mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-23 06:22: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)`);
|
const chartColorsBg = chartColors.map(color => `rgba(${hexToRgb(color.slice(1))}, 0.2)`);
|
||||||
|
|
||||||
|
|
||||||
@ -41,6 +46,18 @@ async function load_data() {
|
|||||||
return;
|
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) =>
|
const jsonOther = json.platform_minetest.map((value, i) =>
|
||||||
value + json.platform_other[i]
|
value + json.platform_other[i]
|
||||||
- json.reason_new[i] - json.reason_dependency[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 }));
|
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 ctx = document.getElementById("chart-platform").getContext("2d");
|
||||||
const data = {
|
const data = {
|
||||||
|
@ -7,38 +7,74 @@
|
|||||||
{% block scriptextra %}
|
{% block scriptextra %}
|
||||||
<script src="/static/libs/chart.min.js"></script>
|
<script src="/static/libs/chart.min.js"></script>
|
||||||
<script src="/static/libs/chartjs-adapter-date-fns.bundle.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 %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2 class="mt-0">{{ _("Statistics") }}</h2>
|
<h2 class="mt-0">{{ _("Statistics") }}</h2>
|
||||||
<noscript>
|
<noscript>
|
||||||
<p class="alert alert-danger">
|
<p class="alert alert-danger">
|
||||||
{{ _("JavaScript is needed for graphs") }}
|
{{ _("JavaScript is required to display charts and statistics") }}
|
||||||
</p>
|
</p>
|
||||||
</noscript>
|
</noscript>
|
||||||
<div class="row mb-5">
|
<div class="row mb-5">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<div class="card h-100">
|
<div class="card h-100">
|
||||||
<div class="card-body media align-items-center">
|
<div class="card-body align-items-center text-center">
|
||||||
<i class="fas fa-download ml-2 mr-4 text-size" style="font-size: 45px; color: #999;"></i>
|
<div class="mt-0 mb-3">
|
||||||
<div class="media-body">
|
<i class="fas fa-download mr-1"></i>
|
||||||
<div class="mt-0 h4">
|
{{ _("Lifetime unique downloads") }}
|
||||||
{{ package.downloads }}
|
</div>
|
||||||
</div>
|
<div class="my-0 h4">
|
||||||
<div class="my-0">
|
{{ package.downloads }}
|
||||||
{{ _("Lifetime downloads") }}
|
</div>
|
||||||
</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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="loading">{{ _("Loading...") }}</div>
|
<div id="loading">{{ _("Loading...") }}</div>
|
||||||
|
|
||||||
<div id="empty-view" style="display: none;">
|
<div id="empty-view" style="display: none;">
|
||||||
{{ _("No data") }}
|
{{ _("No data") }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="stats-root" data-source="{{ package.getURL('api.package_stats') }}" style="display: none;">
|
<div id="stats-root" data-source="{{ package.getURL('api.package_stats') }}" style="display: none;">
|
||||||
|
|
||||||
<h3>{{ _("Downloads by Client") }}</h3>
|
<h3>{{ _("Downloads by Client") }}</h3>
|
||||||
<p class="text-muted">
|
<p class="text-muted">
|
||||||
{{ _("This is a stacked area graph. For total downloads, look at the combined height.") }}
|
{{ _("This is a stacked area graph. For total downloads, look at the combined height.") }}
|
||||||
|
Loading…
Reference in New Issue
Block a user