WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit b554291

Browse files
authored
Merge pull request #286 from Seshat-Global-History-Databank/instability_data
improved the performance of the analytics page for instability events
2 parents 2fd5ca9 + 9b6bddb commit b554291

File tree

3 files changed

+142
-173
lines changed

3 files changed

+142
-173
lines changed

seshat/apps/crisisdb/templates/crisisdb/instability_analytics.html

Lines changed: 66 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -408,25 +408,11 @@
408408

409409

410410
<div class="col--md-12 align-self-end pb-0 mb-0">
411-
{% if request.GET.year_from_min or request.GET.year_to_max or request.GET.created_before or request.GET.polity or request.GET.selected_batch or request.GET.inst_type or request.GET.ra_check or request.GET.inst_extent or request.GET.inst_intensity or request.GET.has_comment or request.GET.has_private_comment or request.GET.researcher or request.GET.expert or request.GET.real_event_check %}
411+
{% if request.GET.polity or request.GET.selected_batch or request.GET.inst_type or request.GET.ra_check or request.GET.inst_extent or request.GET.inst_intensity or request.GET.has_comment or request.GET.has_private_comment or request.GET.researcher or request.GET.expert or request.GET.real_event_check %}
412412

413413
<div class="py-1 px-0 d-inline-block" >
414414
<strong>Filters applied:</strong>
415415
<ul class="list-inline mb-1">
416-
{% if request.GET.year_from_min %}
417-
<li class="list-inline-item px-2 mb-1 rounded bg-orange-light text-dark">
418-
<span class="fw-light">Year ≥ </span> <span class="fw-bold"> {{ request.GET.year_from_min }}</span>
419-
420-
<a href="?{% query_transform request year_from_min=None %}" class="text-dark ms-1" style="vertical-align:center;">&nbsp;&nbsp;&nbsp;<i class="fa-solid fa-square-xmark"></i></a>
421-
</li>
422-
{% endif %}
423-
{% if request.GET.year_to_max %}
424-
<li class="list-inline-item px-2 mb-1 rounded bg-orange-light text-dark">
425-
<span class="fw-light">Year ≤ </span> <span class="fw-bold"> {{ request.GET.year_to_max }}</span>
426-
427-
<a href="?{% query_transform request year_to_max=None %}" class="text-dark ms-1" style="text-decoration: none;">&nbsp;<i class="fa-solid fa-square-xmark"></i></a>
428-
</li>
429-
{% endif %}
430416
{% for type in instability_types %}
431417
{% if type.id|stringformat:"s" in selected_inst_type_ids %}
432418
<li class="list-inline-item px-2 mb-1 rounded bg-info-light text-dark">
@@ -493,8 +479,6 @@
493479
{% else %}
494480
Not Available
495481
{% endif %}
496-
497-
498482
</span>
499483
<a href="?{% query_transform request has_private_comment=None %}" class="text-dark ms-1">&nbsp;&nbsp;&nbsp;<i class="fa-solid fa-square-xmark"></i></a>
500484
</li>
@@ -510,8 +494,6 @@
510494
{% else %}
511495
Not Available
512496
{% endif %}
513-
514-
515497
</span>
516498
<a href="?{% query_transform request has_private_comment=None %}" class="text-dark ms-1">&nbsp;&nbsp;&nbsp;<i class="fa-solid fa-square-xmark"></i></a>
517499
</li>
@@ -590,8 +572,8 @@ <h5> <span class="fw-light"> Total Selected Events: </span> {{events|length}} /
590572
</div>
591573
<div class="row">
592574
<div class="col-md-8 p-3 border border-1">
593-
<canvas id="centuryChart" height="5" width="10"></canvas>
594-
<hr>
575+
<canvas id="centuryChart" height="5" width="10"></canvas>
576+
<hr>
595577
<div class="row">
596578
<div class="col-md-6">
597579
<canvas id="extentChart" height="10" width="10"></canvas>
@@ -674,10 +656,73 @@ <h5> <span class="fw-light"> Total Selected Events: </span> {{events|length}} /
674656
const expertData = {{ expert_chart_data|safe }};
675657
const centuryData = {{ century_chart_data|safe }};
676658

659+
677660
const batchData = {{ batch_data|safe }};
678661

679662
const realCheckData = {{ real_check_data|safe }};
680663

664+
665+
new Chart(document.getElementById('centuryChart'), {
666+
type: 'bar',
667+
data: {
668+
labels: centuryData.map(c => c.century),
669+
datasets: [{
670+
label: ' Count',
671+
data: centuryData.map(c => c.count),
672+
backgroundColor: 'teal'
673+
}]
674+
},
675+
options: {
676+
responsive: true,
677+
plugins: {
678+
title: {
679+
display: true,
680+
text: 'Events by Century',
681+
font: {
682+
size: 18,
683+
weight: 'bold'
684+
},
685+
padding: {
686+
top: 10,
687+
bottom: 30
688+
}
689+
},
690+
legend: {
691+
display: false
692+
}
693+
},
694+
scales: {
695+
y: {
696+
ticks: {
697+
// This ensures only integer labels appear
698+
callback: function(value) {
699+
if (Number.isInteger(value)) {
700+
return value;
701+
}
702+
return null;
703+
},
704+
},
705+
beginAtZero: true,
706+
title: {
707+
display: true,
708+
text: 'Event Count'
709+
}
710+
},
711+
x: {
712+
grid: {
713+
display: false // 👈 removes vertical grid lines
714+
},
715+
title: {
716+
display: true,
717+
text: 'Century'
718+
}
719+
}
720+
}
721+
}
722+
});
723+
724+
725+
681726
new Chart(document.getElementById('realCheckChart'), {
682727
type: 'pie',
683728
data: {
@@ -853,66 +898,6 @@ <h5> <span class="fw-light"> Total Selected Events: </span> {{events|length}} /
853898
}
854899
});
855900

856-
new Chart(document.getElementById('centuryChart'), {
857-
type: 'line',
858-
data: {
859-
labels: centuryData.map(c => c.century),
860-
datasets: [{
861-
label: 'Count',
862-
data: centuryData.map(c => c.count),
863-
backgroundColor: 'teal'
864-
}]
865-
},
866-
options: {
867-
responsive: true,
868-
plugins: {
869-
title: {
870-
display: true,
871-
text: 'Events by Century',
872-
font: {
873-
size: 18,
874-
weight: 'bold'
875-
},
876-
padding: {
877-
top: 10,
878-
bottom: 30
879-
}
880-
},
881-
legend: {
882-
display: false
883-
}
884-
},
885-
scales: {
886-
y: {
887-
ticks: {
888-
// This ensures only integer labels appear
889-
callback: function(value) {
890-
if (Number.isInteger(value)) {
891-
return value;
892-
}
893-
return null;
894-
},
895-
},
896-
beginAtZero: true,
897-
title: {
898-
display: true,
899-
text: 'Event Count'
900-
}
901-
},
902-
x: {
903-
grid: {
904-
display: false // 👈 removes vertical grid lines
905-
},
906-
title: {
907-
display: true,
908-
text: 'Century'
909-
}
910-
}
911-
}
912-
}
913-
});
914-
915-
916901

917902
new Chart(document.getElementById('extentChart'), {
918903
type: 'bar',

0 commit comments

Comments
 (0)