2017-06-02 13:02:28 +00:00
|
|
|
{% extends "core/base.jinja" %}
|
|
|
|
|
|
|
|
{% block title %}
|
2024-07-23 22:16:31 +00:00
|
|
|
{% trans %}Subscription stats{% endtrans %}
|
2017-06-02 13:02:28 +00:00
|
|
|
{% endblock %}
|
|
|
|
|
2017-06-07 12:08:48 +00:00
|
|
|
{% block head %}
|
2024-07-23 22:16:31 +00:00
|
|
|
{{ super() }}
|
2024-08-14 11:25:33 +00:00
|
|
|
<script type="text/javascript" src="{{ static('vendored/chart/Chart.bundle.min.js') }}"></script>
|
2017-06-07 12:08:48 +00:00
|
|
|
{% endblock %}
|
|
|
|
|
2017-06-02 13:02:28 +00:00
|
|
|
{% block content %}
|
|
|
|
|
2024-07-23 22:16:31 +00:00
|
|
|
<p>
|
2017-06-06 21:27:57 +00:00
|
|
|
{{ form.start_date.label }}<br>
|
|
|
|
{{ form.start_date }}<br><br>
|
|
|
|
{{ form.end_date.label }}<br>
|
|
|
|
{{ form.end_date }}<br>
|
|
|
|
<p><input type="submit" value="{% trans %}Go{% endtrans %}" /></p>
|
2024-07-23 22:16:31 +00:00
|
|
|
</p>
|
2017-06-06 21:27:57 +00:00
|
|
|
|
2024-07-23 22:16:31 +00:00
|
|
|
<canvas id="statsChart" width="400" height="200"></canvas>
|
2017-06-07 12:08:48 +00:00
|
|
|
|
2024-07-23 22:16:31 +00:00
|
|
|
<p>
|
2017-06-06 21:27:57 +00:00
|
|
|
{% trans %}Total subscriptions{% endtrans %} : {{ subscriptions_total.count() }}<br><br>
|
|
|
|
{% trans %}Subscriptions by type{% endtrans %}<br><br>
|
|
|
|
{% for location in locations %}
|
2024-07-23 22:16:31 +00:00
|
|
|
{{ location[1] }} : <i class="nb">{{ subscriptions_total.filter(location=location[0]).count() }}</i><br>
|
2017-06-06 21:27:57 +00:00
|
|
|
{% endfor %}
|
2024-07-23 22:16:31 +00:00
|
|
|
<p>
|
2017-06-02 13:02:28 +00:00
|
|
|
|
2024-07-23 22:16:31 +00:00
|
|
|
<br>
|
2017-06-02 13:02:28 +00:00
|
|
|
|
2024-07-23 22:16:31 +00:00
|
|
|
<table>
|
2017-06-02 13:02:28 +00:00
|
|
|
<tr>
|
2024-07-23 22:16:31 +00:00
|
|
|
<th>{% trans %}Subscription type{% endtrans %}</th>
|
|
|
|
{% for location in locations %}
|
|
|
|
<th>{{ location[1] }}</th>
|
|
|
|
{% endfor %}
|
|
|
|
<th id="graphLabel">{% trans %}Total{% endtrans %}</th>
|
|
|
|
{% for type in subscriptions_types %}
|
|
|
|
<tr>
|
|
|
|
<td><i class="types" >{{ subscriptions_types[type]['name'] }}</i></td>
|
|
|
|
{% set subscriptions_total_type = subscriptions_total.filter(subscription_type=type) %}
|
|
|
|
{% for location in locations %}
|
2017-06-02 13:02:28 +00:00
|
|
|
<td>
|
2024-07-23 22:16:31 +00:00
|
|
|
{% set subscriptions_total_type_location = subscriptions_total_type.filter(location=location[0]) %}
|
|
|
|
{% trans %}Total{% endtrans %} : {{ subscriptions_total_type_location.count()}}<br>
|
|
|
|
{% for p_type in payment_types %}
|
|
|
|
{{ p_type[1] }} : <i class="nb">{{ subscriptions_total_type_location.filter(payment_method=p_type[0]).count()}}</i><br>
|
|
|
|
{% endfor %}
|
2017-06-02 13:02:28 +00:00
|
|
|
</td>
|
2024-07-23 22:16:31 +00:00
|
|
|
{% endfor %}
|
|
|
|
<td class="total"><i class="nb">{{subscriptions_total_type.count()}}</i>
|
|
|
|
</tr>
|
|
|
|
{% endfor %}
|
|
|
|
</table>
|
2017-06-02 13:02:28 +00:00
|
|
|
|
|
|
|
{% endblock %}
|
2017-06-07 12:08:48 +00:00
|
|
|
|
|
|
|
{% block script %}
|
2024-07-23 22:16:31 +00:00
|
|
|
{{ super() }}
|
|
|
|
<script>
|
|
|
|
function getRandomColor() {
|
|
|
|
var letters = '0123456789ABCDEF';
|
|
|
|
var color = '#';
|
|
|
|
for (var i = 0; i < 6; i++ ) {
|
2017-06-07 13:23:32 +00:00
|
|
|
color += letters[Math.floor(Math.random() * 16)];
|
2024-07-23 22:16:31 +00:00
|
|
|
}
|
|
|
|
return color;
|
2017-06-07 13:23:32 +00:00
|
|
|
}
|
2024-07-23 22:16:31 +00:00
|
|
|
function getRandomColorUniq(list) {
|
|
|
|
var color = getRandomColor();
|
|
|
|
while (list.includes(color)){
|
2017-06-07 13:23:32 +00:00
|
|
|
color = getRandomColor();
|
2024-07-23 22:16:31 +00:00
|
|
|
}
|
|
|
|
return color;
|
2017-06-07 13:23:32 +00:00
|
|
|
}
|
2024-07-23 22:16:31 +00:00
|
|
|
function hexToRgb(hex) {
|
2017-06-07 13:23:32 +00:00
|
|
|
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
|
2024-07-23 22:16:31 +00:00
|
|
|
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
|
|
hex = hex.replace(shorthandRegex, function(m, r, g, b) {
|
2017-06-07 13:23:32 +00:00
|
|
|
return r + r + g + g + b + b;
|
2024-07-23 22:16:31 +00:00
|
|
|
});
|
2017-06-07 13:23:32 +00:00
|
|
|
|
2024-07-23 22:16:31 +00:00
|
|
|
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
|
|
return result ? {
|
2017-06-07 13:23:32 +00:00
|
|
|
r: parseInt(result[1], 16),
|
|
|
|
g: parseInt(result[2], 16),
|
|
|
|
b: parseInt(result[3], 16)
|
2024-07-23 22:16:31 +00:00
|
|
|
} : null;
|
|
|
|
}
|
2017-06-07 13:23:32 +00:00
|
|
|
|
2024-07-23 22:16:31 +00:00
|
|
|
var ctx = document.getElementById("statsChart").getContext('2d');
|
|
|
|
var labels = [];
|
|
|
|
var total = [];
|
|
|
|
var colors = [];
|
|
|
|
var colors_dimmed = [];
|
|
|
|
Array.from(document.getElementsByClassName("types")).forEach(function(element){
|
|
|
|
labels.push(element.childNodes[0].data);
|
|
|
|
});
|
|
|
|
Array.from(document.getElementsByClassName("total")).forEach(function(element){
|
|
|
|
total.push(element.childNodes[0].childNodes[0].data);
|
|
|
|
});
|
|
|
|
labels.forEach(function(element){
|
|
|
|
colors.push(getRandomColorUniq(colors));
|
|
|
|
});
|
|
|
|
colors.forEach(function(element){
|
|
|
|
var rgb_color = hexToRgb(element);
|
|
|
|
colors_dimmed.push('rgba(' + rgb_color.r + ', ' + rgb_color.g + ', ' + rgb_color.b + ', 0.2)');
|
|
|
|
});
|
|
|
|
console.log(colors);console.log(colors_dimmed);
|
|
|
|
var myChart = new Chart(ctx, {
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
2017-06-07 12:08:48 +00:00
|
|
|
labels: labels,
|
|
|
|
datasets: [{
|
2024-07-23 22:16:31 +00:00
|
|
|
label: document.getElementById("graphLabel").childNodes[0].data,
|
|
|
|
data: total,
|
|
|
|
backgroundColor: colors_dimmed,
|
|
|
|
borderColor: colors,
|
|
|
|
borderWidth: 1
|
2017-06-07 12:08:48 +00:00
|
|
|
}]
|
2024-07-23 22:16:31 +00:00
|
|
|
},
|
|
|
|
options: {
|
2017-06-07 12:08:48 +00:00
|
|
|
scales: {
|
2024-07-23 22:16:31 +00:00
|
|
|
yAxes: [{
|
|
|
|
ticks: {
|
|
|
|
beginAtZero:true
|
|
|
|
}
|
|
|
|
}]
|
2017-06-07 12:08:48 +00:00
|
|
|
}
|
2024-07-23 22:16:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
2017-06-07 12:08:48 +00:00
|
|
|
{% endblock %}
|