-
-
Notifications
You must be signed in to change notification settings - Fork 259
Fix: Stats_Dashboard is fixed now #3978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe changes update the statistics dashboard by overhauling the HTML template and backend view function. The UI is restructured with new blocks for external JavaScript libraries, improved layout with KPI cards, responsive design, and additional charts. On the backend, the function calculating statistics has been enhanced to include percentage metrics for various data points, ensuring more detailed analytics are provided to the dashboard. Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant B as Browser
participant V as Django View
participant T as Template Engine
participant JS as JavaScript Libraries
U->>B: Request Dashboard Page
B->>V: GET /stats_dashboard
V->>V: Calculate statistics with percentages
V->>T: Render updated dashboard template with stats
T->>B: Send rendered HTML
B->>JS: Load ApexCharts and CountUp.js
JS->>B: Initialize charts and animated counters
Assessment against linked issues
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (5)
website/views/core.py (1)
1494-1494: Consider adding error handling for potential division by zero.While the code checks if
users["total"] > 0before division, I'd recommend extracting the percentage calculation logic into a helper function for better maintainability and consistency across all metrics.+ def calculate_percentage(numerator, denominator): + """Calculate percentage with zero division protection""" + return round((numerator / denominator * 100) if denominator > 0 else 0) + # Then in the stats dictionary: - "active_percentage": round((users["active"] / users["total"] * 100) if users["total"] > 0 else 0), + "active_percentage": calculate_percentage(users["active"], users["total"]),website/templates/stats_dashboard.html (4)
251-256: Consider adding feedback mechanism for sync operation.The sync button should provide visual feedback after the operation completes, indicating success or failure.
<button id="syncProjectsBtn" type="button" class="mt-1 inline-flex items-center px-2 py-1 bg-[#e74c3c] hover:bg-red-600 text-white text-xs rounded"> <i class="fas fa-sync-alt mr-1"></i> Sync Now </button> + {% if messages %} + {% for message in messages %} + <div class="text-xs mt-1 {% if message.tags == 'success' %}text-green-600{% else %}text-red-600{% endif %}"> + {{ message }} + </div> + {% endfor %} + {% endif %}
423-424: Use dynamic date ranges for the activity chart.The x-axis categories are hard-coded to months instead of being dynamically generated based on the selected time period.
Pass date labels from the backend and use them in the chart configuration:
xaxis: { - categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], + categories: {{ date_labels|safe }}, labels: { style: { colors: '#9ca3af' } },
496-496: Consider using a more diverse color palette for better accessibility.Using variations of red for all chart elements may make it difficult for users with color vision deficiencies to distinguish between different data points.
Use a more diverse and accessible color palette:
- colors: ['#e74c3c', '#e76c3c', '#e74c6c', '#e7463c'], + colors: ['#e74c3c', '#3498db', '#2ecc71', '#f39c12'],
287-349: Add error handling for JavaScript libraries.There's no error handling for cases where the external libraries (ApexCharts or CountUp.js) fail to load.
Add error handling to gracefully degrade functionality when libraries are unavailable:
document.addEventListener('DOMContentLoaded', function() { + // Check if required libraries are available + if (typeof CountUp === 'undefined' || typeof ApexCharts === 'undefined') { + console.error('Required libraries not loaded. Some dashboard features will be disabled.'); + document.querySelectorAll('.requires-js').forEach(el => { + el.innerHTML = 'Chart unavailable (JavaScript library not loaded)'; + el.classList.add('bg-gray-100', 'text-gray-500', 'p-4', 'text-center'); + }); + return; + } // Rest of the initialization code...
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
website/templates/stats_dashboard.html(1 hunks)website/views/core.py(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Run Tests
- GitHub Check: docker-test
🔇 Additional comments (4)
website/views/core.py (1)
1490-1531: Improved stats structure with new percentage metrics!The updated stats dictionary structure now includes percentage calculations for active users, open issues, active domains, and more. This enhances the data visualization capabilities on the dashboard.
website/templates/stats_dashboard.html (3)
7-12: Good addition of external libraries in the head block!Adding ApexCharts and CountUp.js will enhance the data visualization capabilities of the dashboard. This is a great improvement.
44-182: Great implementation of KPI summary cards!The new KPI card design with animated counters, percentage indicators, and progress bars greatly improves the user experience and data readability.
278-283: Good implementation of hidden form for sync action.Using a hidden form for the sync operation is a clean approach for handling the POST request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
website/templates/stats_dashboard.html (3)
362-366: Ensure time series data aligns with selected time period.The chart uses a static 12-month display regardless of the selected time period. Consider dynamically adjusting the chart's x-axis labels based on the selected period for improved accuracy.
series: [{ name: 'Issues', data: {{ issues_time_series|safe|default:'[0,0,0,0,0,0,0,0,0,0,0,0]' }} }, { name: 'Users', data: {{ users_time_series|safe|default:'[0,0,0,0,0,0,0,0,0,0,0,0]' }} }],Additionally, pass the actual time period labels from the backend:
xaxis: { - categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], + categories: {{ time_period_labels|safe|default:"['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']" }},
352-356: Add error handling for the sync projects operation.The button is correctly disabled during the sync operation, but there's no mechanism to re-enable it or show an error message if the operation fails.
document.getElementById('syncProjectsBtn').addEventListener('click', function() { + const button = this; document.getElementById('syncProjectsForm').submit(); this.disabled = true; this.innerHTML = '<i class="fas fa-spinner fa-spin mr-1"></i> Syncing...'; + + // Add listener for form submission result + window.addEventListener('load', function() { + button.disabled = false; + button.innerHTML = '<i class="fas fa-sync-alt mr-1"></i> Sync Now'; + + // Check for Django messages to display success/error + const messages = document.querySelectorAll('.django-messages .alert'); + if (messages.length > 0) { + // Handle messages accordingly + } + }, { once: true }); });
498-499: Improve color differentiation in the issue status pie chart.The current colors are all similar shades of red, which might make it difficult to distinguish between different statuses.
-colors: ['#e74c3c', '#e76c3c', '#e74c6c', '#e7463c'], +colors: ['#e74c3c', '#3498db', '#2ecc71', '#f39c12'],
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
website/templates/stats_dashboard.html(1 hunks)website/views/core.py(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Run Tests
- GitHub Check: docker-test
🔇 Additional comments (7)
website/views/core.py (3)
1490-1534: Well-structured enhancement of the stats dictionary with percentage metrics!The addition of percentage metrics for active users, open issues, active domains, etc. provides more meaningful insights in the dashboard. The code correctly handles potential division by zero cases.
1542-1573: Good implementation of time series data for visualization.The time series data generation for issues and users is well implemented. It appropriately handles various time period selections and fills in missing months with zeros.
1589-1591: Properly exposing time series data to the template for chart consumption.The addition of context variables for JSON-encoded time series data ensures the frontend can easily consume this data for visualization.
website/templates/stats_dashboard.html (4)
44-182: Excellent implementation of KPI cards with animated counters!The KPI cards follow a consistent design pattern with good use of Tailwind CSS for styling. The data binding to the backend statistics is well implemented, and the progress bars visually represent the percentage metrics.
201-207: Well-structured chart containers.The chart containers are properly sized and structured for optimal data visualization. The use of responsive design principles ensures good display across different screen sizes.
210-274: Good implementation of secondary metric cards.The implementation of additional metrics (domains, bug hunts, projects, activities) with consistent styling and counter animations enhances the dashboard's completeness. The sync projects button is a useful feature for data refresh.
278-283: Properly implemented form for GitHub projects synchronization.The hidden form with CSRF token for project synchronization follows best practices for Django form submissions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (5)
website/templates/stats_dashboard.html (5)
188-213: Charts & Secondary Metrics SectionThe integration of the "Activity Over Time" area chart and the "Issue Status Breakdown" pie chart enhances data visualization. One suggestion: for the activity chart, both data series currently use the same color (
#e74c3c) which may reduce clarity. Consider assigning distinct colors to differentiate between “Issues” and “Users” data.
281-287: Sync Projects Form IntegrationThe hidden sync projects form and the associated button are correctly implemented. For increased robustness, consider adding error handling (and perhaps re-enabling the button) if the form submission fails.
330-350: Animated Counters InitializationThe function
initializeCounters()efficiently iterates over the counter elements—retrieving the starting values from data attributes and initializing the CountUp animations. For future maintainability, you might consider encapsulating this logic into a module if similar functionality is needed elsewhere.
355-360: Sync Projects Button Event HandlingThe event listener for the “Sync Projects” button disables the button and updates its inner HTML to indicate a loading state. It works as intended, though adding error handling for failed submissions could further improve user feedback.
362-394: Activity Over Time Chart ConfigurationThe configuration for the Activity Over Time chart correctly sets up dynamic series data and responsive styling. However, both the “Issues” and “Users” series are assigned the same color (
#e74c3c), which might lead to visual confusion. Consider using a distinct color (for example, a blue tone for one series) to enhance clarity.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
website/templates/stats_dashboard.html(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Run Tests
- GitHub Check: docker-test
🔇 Additional comments (6)
website/templates/stats_dashboard.html (6)
7-16: External Scripts with SRI AttributesThe newly added
{% block head %}correctly includes ApexCharts and CountUp.js with explicit integrity and crossorigin attributes, which enhances security by ensuring resource integrity.
17-30: Dashboard Header & Container StructureThe dashboard header now dynamically displays the title, description, and current period. The use of a dedicated container (
#dashboardContainer) and responsive spacing is well executed.
31-42: Time Period Selector ImplementationThe redesigned time period selector makes use of a loop over
period_optionsand applies conditional styling based on the selected period. This approach improves usability.
47-83: KPI Summary Cards for Core MetricsThe KPI cards for Users, Issues, Organizations, and Points are effectively structured. They dynamically render key stats using Django template variables with appropriate fallback defaults.
214-278: Additional Metrics GridThe grid displaying Domains, Bug Hunts, Projects, and Activities is well designed and consistently styled. Dynamic values and layout classes are used effectively.
476-483: Issue Status Pie Chart SetupThe Issue Status Pie Chart is configured well by combining dynamic values from the template with a clear set of labels and differentiated colors for each issue status. Verify that the order of series data (Open, Fixed, In Review, Invalid) aligns with backend computations.
Fixes: #3977

Summary by CodeRabbit
New Features
Refactor