Show total amounts on reports by range

AI-generated summary

In a discussion titled ‘Show total amounts on reports by range’ under the Feature category, alefattorini expresses enthusiasm about exporting report data (e.g., posts, new users) but suggests it would be even more useful if Discourse displayed aggregated totals for selected date ranges. In response, Mittineague offers a custom Firefox browser extension script that calculates and displays total visits and average visits per day for the ‘visits’ admin report, noting that a similar Chrome extension could be built. The script parses table cells, identifies date-formatted entries, computes totals and maximums, and appends summary stats to the page heading. alefattorini acknowledges the suggestion with a brief, appreciative reply. The conversation reflects a user-driven effort to enhance reporting functionality through client-side scripting when native features are lacking.

Now I can export data from reports: posts, new users, etc..
It’s cool! But it might be super-cool if Discourse shows a total amount by range selected since I can simply aggregate such data, for example new users/posts/topics by month
Doing this using excel isn’t really handy

2개의 좋아요

Do you have any experience writing browser extensions?

I threw this together for Firefox but I imagine a Chrome extension would be similar

self.port.on('viewing_admin_reports_visits', function () {
"use strict";
	var visit_cells = document.querySelectorAll("table[class~='report'] tbody tr td");
	var h3_heading = document.querySelector("div#main-outlet h3");
	var visit_cells_len = visit_cells.length;

	var high_visit = 0;
	var high_visit_cell_num = 0;
	var total_count = 0;

	for (var i = 0; i < visit_cells_len; i++) {
		if (/[\d]{4}-[\d]{2}-[\d]{2}/.test(visit_cells[i].textContent)) {
			var ymd_date = new Date(visit_cells[i].textContent);
			if ( (ymd_date.getUTCDay() == 6) || (ymd_date.getUTCDay() == 0) ) {
				visit_cells[i].parentNode.setAttribute('style', "background-color: #efefff");
			}
		}
		if (/\s[\d]+\s/.test(visit_cells[i].textContent)) {
			total_count += parseInt(visit_cells[i].textContent);
			if (parseInt(visit_cells[i].textContent) > high_visit) {
				high_visit = parseInt(visit_cells[i].textContent);
				high_visit_cell_num = i;
			}
		}
	}
	visit_cells[high_visit_cell_num].setAttribute('style', "font-weight: bold; font-size: 1.2em");

	var avg_span = document.createElement('span');
	avg_span.textContent = " - average " + Math.round(total_count / (visit_cells_len / 2) ) + " per day";
	h3_heading.appendChild(avg_span);
});

mmh I could try :slight_smile: thanks..