mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 22:12:24 +01:00
Statistics: Add weekly and monthly total/average
This commit is contained in:
parent
977fc1ce96
commit
5fc603682d
@ -25,6 +25,11 @@ function hexToRgb(hex) {
|
||||
}
|
||||
|
||||
|
||||
function sum(list) {
|
||||
return list.reduce((acc, x) => acc + x, 0);
|
||||
}
|
||||
|
||||
|
||||
const chartColorsBg = chartColors.map(color => `rgba(${hexToRgb(color.slice(1))}, 0.2)`);
|
||||
|
||||
|
||||
@ -41,6 +46,18 @@ async function load_data() {
|
||||
return;
|
||||
}
|
||||
|
||||
const total7 = sum(json.platform_minetest.slice(-7)) + sum(json.platform_other.slice(-7));
|
||||
document.getElementById("downloads_total7d").textContent = total7;
|
||||
document.getElementById("downloads_avg7d").textContent = (total7 / 7).toFixed(0);
|
||||
|
||||
if (json.platform_minetest.length >= 30) {
|
||||
const total30 = sum(json.platform_minetest.slice(-30)) + sum(json.platform_other.slice(-30));
|
||||
document.getElementById("downloads_total30d").textContent = total30;
|
||||
document.getElementById("downloads_avg30d").textContent = (total30 / 30).toFixed(0);
|
||||
} else {
|
||||
document.getElementById("downloads30").style.display = "none";
|
||||
}
|
||||
|
||||
const jsonOther = json.platform_minetest.map((value, i) =>
|
||||
value + json.platform_other[i]
|
||||
- json.reason_new[i] - json.reason_dependency[i]
|
||||
@ -52,10 +69,6 @@ async function load_data() {
|
||||
return list.map((value, i) => ({ x: json.dates[i], y: value }));
|
||||
}
|
||||
|
||||
function sum(list) {
|
||||
return list.reduce((acc, x) => acc + x, 0);
|
||||
}
|
||||
|
||||
{
|
||||
const ctx = document.getElementById("chart-platform").getContext("2d");
|
||||
const data = {
|
||||
|
@ -7,38 +7,74 @@
|
||||
{% block scriptextra %}
|
||||
<script src="/static/libs/chart.min.js"></script>
|
||||
<script src="/static/libs/chartjs-adapter-date-fns.bundle.min.js"></script>
|
||||
<script src="/static/package_charts.js?v=3"></script>
|
||||
<script src="/static/package_charts.js?v=4"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2 class="mt-0">{{ _("Statistics") }}</h2>
|
||||
<noscript>
|
||||
<p class="alert alert-danger">
|
||||
{{ _("JavaScript is needed for graphs") }}
|
||||
{{ _("JavaScript is required to display charts and statistics") }}
|
||||
</p>
|
||||
</noscript>
|
||||
<div class="row mb-5">
|
||||
<div class="col-md-4">
|
||||
<div class="card h-100">
|
||||
<div class="card-body media align-items-center">
|
||||
<i class="fas fa-download ml-2 mr-4 text-size" style="font-size: 45px; color: #999;"></i>
|
||||
<div class="media-body">
|
||||
<div class="mt-0 h4">
|
||||
{{ package.downloads }}
|
||||
</div>
|
||||
<div class="my-0">
|
||||
{{ _("Lifetime downloads") }}
|
||||
</div>
|
||||
<div class="card-body align-items-center text-center">
|
||||
<div class="mt-0 mb-3">
|
||||
<i class="fas fa-download mr-1"></i>
|
||||
{{ _("Lifetime unique downloads") }}
|
||||
</div>
|
||||
<div class="my-0 h4">
|
||||
{{ package.downloads }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<div class="card h-100">
|
||||
<div class="card-body align-items-center text-center">
|
||||
<div class="mt-0 mb-3">
|
||||
<i class="fas fa-download mr-1"></i>
|
||||
{{ _("Downloads, past 7 days") }}
|
||||
</div>
|
||||
<div class="my-0 h4">
|
||||
<span id='downloads_total7d'></span>
|
||||
<small class="text-muted ml-2">
|
||||
({{ _("%(downloads)s per day", downloads=("<span id='downloads_avg7d'></span>" | safe)) }})
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4" id="downloads30">
|
||||
<div class="card h-100">
|
||||
<div class="card-body align-items-center text-center">
|
||||
<div class="mt-0 mb-3">
|
||||
<i class="fas fa-download mr-1"></i>
|
||||
{{ _("Downloads, past 30 days") }}
|
||||
</div>
|
||||
<div class="my-0 h4">
|
||||
<span id='downloads_total30d'></span>
|
||||
<small class="text-muted ml-2">
|
||||
({{ _("%(downloads)s per day", downloads=("<span id='downloads_avg30d'></span>" | safe)) }})
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="loading">{{ _("Loading...") }}</div>
|
||||
|
||||
<div id="empty-view" style="display: none;">
|
||||
{{ _("No data") }}
|
||||
</div>
|
||||
|
||||
<div id="stats-root" data-source="{{ package.getURL('api.package_stats') }}" style="display: none;">
|
||||
|
||||
<h3>{{ _("Downloads by Client") }}</h3>
|
||||
<p class="text-muted">
|
||||
{{ _("This is a stacked area graph. For total downloads, look at the combined height.") }}
|
||||
|
Loading…
Reference in New Issue
Block a user