Skip to content

Conversation

@codeunia-dev
Copy link
Owner

@codeunia-dev codeunia-dev commented Nov 18, 2025

Description

This PR improves how company dashboards handle real event and hackathon statistics by integrating accurate metrics and adding missing metadata.

Key Changes

  • Company Dashboard

    • Added calculation of actual views and clicks per event.
  • Analytics

    • Fetched real event + hackathon stats directly from the API.
    • Synced analytics with events and hackathons tables.
    • Distributed actual stats proportionally across historical analytics for better accuracy.
  • Hackathons

    • Added required metadata fields to hackathon registrations.
    • Included a cleanup script to maintain data integrity.

Why This Matters

  • Ensures the company dashboard displays true performance numbers instead of approximations.
  • Improves reliability of analytics insights for both events and hackathons.
  • Enhances data quality across multiple dashboard modules.

Future Considerations

  • Add caching for heavy analytics endpoints.
  • Introduce validation rules for hackathon metadata.
  • Expand cleanup script to include orphaned analytics entries.

Authored by: @akshay0611

Summary by CodeRabbit

Release Notes

  • New Features

    • Analytics dashboard now displays real-time statistics for views, clicks, and registrations
  • Bug Fixes

    • Corrected event and hackathon performance metrics calculations to use actual data aggregation instead of proportional scaling
  • Improvements

    • Enhanced registration records with additional hackathon metadata for better tracking

…type

- Replace proportional view/click calculation with actual aggregated metrics from events and hackathons data
- Calculate eventViews by summing views from all approved events
- Calculate eventClicks by summing clicks from all approved events
- Calculate hackathonViews by summing views from all approved hackathons
- Calculate hackathonClicks by summing clicks from all approved hackathons
- Update eventMetrics and hackathonMetrics to use actual calculated values instead of proportional estimates
- Remove proportional ratio calculation logic that was previously used as a workaround
- Improves accuracy of dashboard metrics by using real data instead of estimates based on item counts
- Add React state and useEffect hook to EventPerformanceComparison component to fetch real event data from API
- Add React state and useEffect hook to HackathonPerformanceComparison component to fetch real hackathon data from API
- Extract company slug from URL pathname to construct API endpoints dynamically
- Filter approved events and hackathons before calculating performance metrics
- Calculate total views, clicks, and registrations from actual event/hackathon records instead of analytics aggregates
- Implement fallback to analytics data when API fetch fails or returns no data
- Replace hardcoded metric calculations with dynamic API-driven data for more accurate dashboard reporting
- Add useEffect hook to fetch real-time event and hackathon statistics from API
- Calculate actual views, clicks, and registrations from approved events and hackathons
- Implement fallback to analytics data when actual stats are unavailable
- Update AnalyticsCharts to use actual stats instead of analytics summary data
- Update CompanyDashboard to calculate totalViews and totalClicks from events/hackathons
- Rename analytics totals to analyticsTotals for clarity and distinction
- Improve accuracy of dashboard metrics by using source-of-truth data from events and hackathons tables
…ical data

- Calculate scaling factors to adjust historical analytics data to match current actual stats
- Implement two-pass distribution algorithm to proportionally scale views and clicks
- Floor proportional values in first pass to maintain data integrity
- Distribute remaining views and clicks to days with highest fractional remainders
- Remove remainder fields from final chart data for clean output
- Ensures historical trends are preserved while reflecting current reality in analytics charts
- Add hackathon metadata (id, slug, title) to master_registrations table during registration
- Include note clarifying integer to string conversion for activity_id
- Create delete-test-company.js script for cleaning up test data
- Script handles cascading deletion of events, hackathons, registrations, and analytics
- Improves data tracking and provides utility for development/testing cleanup
@vercel
Copy link

vercel bot commented Nov 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
codeunia Building Building Preview Comment Nov 18, 2025 10:59am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 18, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This PR enriches hackathon registrations with metadata containing hackathon details, refactors dashboard analytics to directly aggregate views and clicks from events and hackathons APIs instead of proportional calculations, and adds a cascading deletion utility for test company data.

Changes

Cohort / File(s) Summary
Registration Metadata
app/api/hackathons/[id]/register/route.ts
Adds metadata field to master_registrations containing hackathon_id, hackathon_slug, and hackathon_title on successful registration POST
Dashboard Analytics Refactor
components/dashboard/AnalyticsCharts.tsx, components/dashboard/CompanyDashboard.tsx
Replaces proportional views/clicks distribution with direct aggregation from events and hackathons API data; introduces actualStats state and useEffect for live fetching; adds two-pass remainder distribution logic to match current totals; updates comparison components to fetch actual per-category totals
Test Utility
delete-test-company.js
New cascading deletion script for test companies; locates company by slug, reports related record counts, and deletes in dependency order with progress logging and error handling

Sequence Diagram(s)

sequenceDiagram
    participant UI as Dashboard Component
    participant API as Events/Hackathons API
    participant State as actualStats State
    
    UI->>+API: Fetch events & hackathons
    API-->>-UI: Return data with views/clicks
    UI->>State: Update actualStats
    
    Note over UI: First pass: Compute proportional<br/>distribution from historical data
    Note over UI: Second pass: Distribute remainders<br/>to largest remainder days
    
    UI->>UI: Generate chartData with<br/>remainder-adjusted values
    UI->>UI: Render with actual totals
Loading
sequenceDiagram
    participant Client as Registration Request
    participant Route as /hackathons/[id]/register
    participant DB as Database
    
    Client->>+Route: POST registration
    Route->>Route: Validate & check capacity
    Route->>Route: Check duplicate registration
    Route->>DB: Insert master_registrations<br/>with metadata
    Note over Route: metadata = {<br/>hackathon_id,<br/>hackathon_slug,<br/>hackathon_title<br/>}
    DB-->>Route: Record inserted
    Route-->>-Client: Success response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • components/dashboard/AnalyticsCharts.tsx: Requires careful review of two-pass remainder distribution logic and API integration; ensure aggregation is accurate
  • components/dashboard/CompanyDashboard.tsx: Verify direct aggregation logic produces correct view/click totals compared to previous proportional calculations; check edge cases with zero data
  • delete-test-company.js: Review cascade deletion order and error handling; ensure no data orphaning occurs

Possibly related PRs

Poem

🐰 Our dashboards now see with clear eyes,
No more proportions, just honest replies,
Direct from the source, the numbers ring true,
Registrations enriched with context for you!
While test companies bid their goodbye. 🗑️

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/companyhackathons

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between beab5aa and 9a0c590.

📒 Files selected for processing (4)
  • app/api/hackathons/[id]/register/route.ts (2 hunks)
  • components/dashboard/AnalyticsCharts.tsx (4 hunks)
  • components/dashboard/CompanyDashboard.tsx (2 hunks)
  • delete-test-company.js (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codeunia-dev codeunia-dev merged commit 7545be8 into main Nov 18, 2025
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants