diff --git a/App.py b/App.py
index 76c4afb..9137c76 100644
--- a/App.py
+++ b/App.py
@@ -821,6 +821,30 @@ class RobustMiddleware:
start_response("500 Internal Server Error", [("Content-Type", "text/html")])
return [b"
Internal Server Error
"]
+@app.route("/api/reset-chart-data", methods=["POST"])
+def reset_chart_data():
+ """API endpoint to reset chart data history."""
+ try:
+ global arrow_history, state_manager
+
+ # Clear hashrate data from in-memory dictionary
+ hashrate_keys = ["hashrate_60sec", "hashrate_3hr", "hashrate_10min", "hashrate_24hr"]
+ for key in hashrate_keys:
+ if key in arrow_history:
+ arrow_history[key] = []
+
+ # Force an immediate save to Redis if available
+ if state_manager and hasattr(state_manager, 'redis_client') and state_manager.redis_client:
+ # Force save by overriding the time check
+ state_manager.last_save_time = 0
+ state_manager.save_graph_state()
+ logging.info("Chart data reset saved to Redis immediately")
+
+ return jsonify({"status": "success", "message": "Chart data reset successfully"})
+ except Exception as e:
+ logging.error(f"Error resetting chart data: {e}")
+ return jsonify({"status": "error", "message": str(e)}), 500
+
# Add the middleware
app.wsgi_app = RobustMiddleware(app.wsgi_app)
diff --git a/static/js/main.js b/static/js/main.js
index 4ec7d18..482786b 100644
--- a/static/js/main.js
+++ b/static/js/main.js
@@ -1412,43 +1412,34 @@ function initNotificationBadge() {
setInterval(updateNotificationBadge, 60000);
}
-// Function to reset dashboard chart data
+// Modify the resetDashboardChart function
function resetDashboardChart() {
console.log("Resetting dashboard chart data");
if (trendChart) {
- // Reset chart data arrays
+ // Reset chart data arrays first (always succeeds)
trendChart.data.labels = [];
trendChart.data.datasets[0].data = [];
-
- // Update the chart with empty data
trendChart.update('none');
- // Show feedback to the user
- showConnectionIssue("Chart data reset");
- setTimeout(hideConnectionIssue, 2000);
+ // Show immediate feedback
+ showConnectionIssue("Resetting chart data...");
- // If we have latest metrics, add the current point back
- if (latestMetrics && latestMetrics.hashrate_60sec) {
- // Get current time
- const now = new Date();
- let currentTime = now.toLocaleTimeString('en-US', {
- timeZone: dashboardTimezone,
- hour: '2-digit',
- minute: '2-digit',
- hour12: true
- }).replace(/\s[AP]M$/i, '');
-
- // Get current hashrate
- const currentUnit = latestMetrics.hashrate_60sec_unit ?
- latestMetrics.hashrate_60sec_unit.toLowerCase() : 'th/s';
- const normalizedValue = normalizeHashrate(parseFloat(latestMetrics.hashrate_60sec) || 0, currentUnit);
-
- // Add single point
- trendChart.data.labels = [currentTime];
- trendChart.data.datasets[0].data = [normalizedValue];
- trendChart.update('none');
- }
+ // Then call the API to clear underlying data
+ $.ajax({
+ url: '/api/reset-chart-data',
+ method: 'POST',
+ success: function (response) {
+ console.log("Server data reset:", response);
+ showConnectionIssue("Chart data reset successfully");
+ setTimeout(hideConnectionIssue, 3000);
+ },
+ error: function (xhr, status, error) {
+ console.error("Error resetting chart data:", error);
+ showConnectionIssue("Chart display reset (backend error: " + error + ")");
+ setTimeout(hideConnectionIssue, 5000);
+ }
+ });
}
}