Skip to content

Commit c783f34

Browse files
committed
update-sites/stats: tweak daily rolling average UI
1 parent 5a2163c commit c783f34

File tree

1 file changed

+17
-33
lines changed

1 file changed

+17
-33
lines changed

_pages/update-sites/stats.md

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ section: Extend:Update Sites
7171

7272
<label class="heading">Time Window:</label>
7373
<div class="widgets">
74-
<label><input type="radio" id="time-daily" name="timeWindow" value="daily" checked onchange="updateChart()"> Daily</label>
74+
<label><input type="radio" id="time-daily" name="timeWindow" value="daily" onchange="updateChart()"> Daily</label>
75+
<label><input type="radio" id="time-daily-avg" name="timeWindow" value="daily-avg" checked onchange="updateChart()"> Daily (7-day avg)</label>
7576
<label><input type="radio" id="time-monthly" name="timeWindow" value="monthly" onchange="updateChart()"> Monthly</label>
7677
<label><input type="radio" id="time-yearly" name="timeWindow" value="yearly" onchange="updateChart()"> Yearly</label>
7778
<label><input type="radio" id="time-ever" name="timeWindow" value="ever" onchange="updateChart()"> Ever/Cumulative</label>
@@ -82,11 +83,6 @@ section: Extend:Update Sites
8283
<label><input type="radio" id="count-unique" name="countType" value="unique" checked onchange="updateChart()"> Unique IPs</label>
8384
<label><input type="radio" id="count-total" name="countType" value="total" onchange="updateChart()"> Total Checks</label>
8485
</div>
85-
86-
<label class="heading">Options:</label>
87-
<div class="widgets">
88-
<label for="rolling-average"><input type="checkbox" id="rolling-average" checked onchange="updateChart()"> 7-day rolling average</label>
89-
</div>
9086
</div>
9187

9288
<div id="loading">Loading data...</div>
@@ -108,9 +104,8 @@ section: Extend:Update Sites
108104
const site2 = document.getElementById('site2').value;
109105
const timeWindow = document.querySelector('input[name="timeWindow"]:checked').value;
110106
const countType = document.querySelector('input[name="countType"]:checked').value;
111-
const rollingAverage = document.getElementById('rolling-average').checked;
112107

113-
return { site, op, site2, timeWindow, countType, rollingAverage };
108+
return { site, op, site2, timeWindow, countType };
114109
}
115110

116111
function updateSiteList() {
@@ -201,23 +196,10 @@ section: Extend:Update Sites
201196
}
202197
}
203198

204-
function updateRollingAverageState() {
205-
const { timeWindow } = getSelectedValues();
206-
const checkbox = document.getElementById('rolling-average');
207-
const label = document.querySelector('label[for="rolling-average"]');
208-
209-
if (timeWindow === 'daily') {
210-
checkbox.disabled = false;
211-
label.style.color = '';
212-
} else {
213-
checkbox.disabled = true;
214-
checkbox.checked = false;
215-
label.style.color = '#999';
216-
}
217-
}
218-
219199
function buildStatsUrl(site, timeWindow, countType) {
220-
const filename = `stats-${countType}-${timeWindow}.txt.gz`;
200+
// Map daily-avg to daily for URL
201+
const urlTimeWindow = timeWindow === 'daily-avg' ? 'daily' : timeWindow;
202+
const filename = `stats-${countType}-${urlTimeWindow}.txt.gz`;
221203
return `https://sites.imagej.net/${site}/${filename}`;
222204
}
223205

@@ -226,7 +208,7 @@ section: Extend:Update Sites
226208
}
227209

228210
function parseDate(dateStr, timeWindow) {
229-
if (timeWindow === 'daily' || timeWindow === 'ever') {
211+
if (timeWindow === 'daily' || timeWindow === 'daily-avg' || timeWindow === 'ever') {
230212
// YYYYMMDD format
231213
const year = parseInt(dateStr.substring(0, 4));
232214
const month = parseInt(dateStr.substring(4, 6)) - 1; // JS months are 0-based
@@ -284,7 +266,7 @@ section: Extend:Update Sites
284266
}
285267

286268
// Increment current date based on time window
287-
if (timeWindow === 'daily' || timeWindow === 'ever') {
269+
if (timeWindow === 'daily' || timeWindow === 'daily-avg' || timeWindow === 'ever') {
288270
current.setDate(current.getDate() + 1);
289271
} else if (timeWindow === 'monthly') {
290272
current.setMonth(current.getMonth() + 1);
@@ -401,13 +383,10 @@ section: Extend:Update Sites
401383
}
402384

403385
async function updateChart() {
404-
const { site, op, site2, timeWindow, countType, rollingAverage } = getSelectedValues();
386+
const { site, op, site2, timeWindow, countType } = getSelectedValues();
405387

406388
if (!site) return;
407389

408-
// Update rolling average state
409-
updateRollingAverageState();
410-
411390
// Show loading indicator
412391
document.getElementById('loading').style.display = 'block';
413392

@@ -418,12 +397,17 @@ section: Extend:Update Sites
418397
let chartTitle = site;
419398
let yLabel = `${countType === 'unique' ? 'Unique IP Addresses' : 'Total Update Checks'}`;
420399

400+
// Determine display time window for title
401+
const displayTimeWindow = timeWindow === 'daily-avg' ?
402+
'Daily (7-day avg)' :
403+
timeWindow.charAt(0).toUpperCase() + timeWindow.slice(1);
404+
421405
// Configuration for chart
422406
let chartConfig = {
423-
rollPeriod: rollingAverage && timeWindow === 'daily' ? 7 : 1,
407+
rollPeriod: timeWindow === 'daily-avg' ? 7 : 1,
424408
labels: ['Date', `${countType === 'unique' ? 'Unique IPs' : 'Total Checks'}`],
425409
ylabel: yLabel,
426-
title: `${chartTitle} - ${timeWindow.charAt(0).toUpperCase() + timeWindow.slice(1)} ${countType === 'unique' ? 'Unique' : 'Total'} Statistics`
410+
title: `${chartTitle} - ${displayTimeWindow} ${countType === 'unique' ? 'Unique' : 'Total'} Statistics`
427411
};
428412

429413
// Set X-axis formatting based on time window
@@ -483,7 +467,7 @@ section: Extend:Update Sites
483467
}
484468
}
485469

486-
chartConfig.title = `${chartTitle} - ${timeWindow.charAt(0).toUpperCase() + timeWindow.slice(1)} ${countType === 'unique' ? 'Unique' : 'Total'} Statistics`;
470+
chartConfig.title = `${chartTitle} - ${displayTimeWindow} ${countType === 'unique' ? 'Unique' : 'Total'} Statistics`;
487471
chartConfig.ylabel = yLabel;
488472
}
489473

0 commit comments

Comments
 (0)