Skip to content

Commit 0b9ca49

Browse files
committed
finish logic for score selecting and sorting
1 parent 8849df9 commit 0b9ca49

File tree

5 files changed

+75
-81
lines changed

5 files changed

+75
-81
lines changed

src/main/views.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -165,23 +165,6 @@ def get(self, request, model_id: int):
165165
context = {
166166
"model": model,
167167
"implementation_languages": languages,
168-
"diseases": [
169-
("dengue", "Dengue"),
170-
("zika", "Zika"),
171-
("chikungunya", "Chikungunya"),
172-
],
173-
"adm_levels": [
174-
(0, _("National")),
175-
(1, _("State")),
176-
(2, _("Municipality")),
177-
(3, _("Sub Municipality")),
178-
],
179-
"time_resolutions": [
180-
("day", _("Day")),
181-
("week", _("Week")),
182-
("month", _("Month")),
183-
("year", _("Year")),
184-
],
185168
}
186169
return render(request, self.template_name, context)
187170

@@ -219,11 +202,6 @@ def post(self, request, model_id: int):
219202
),
220203
"spatial": form.data.get("model_spatial") == "True",
221204
"temporal": form.data.get("model_temporal") == "True",
222-
"ADM_level": form.cleaned_data["model_adm_level"],
223-
"disease": form.cleaned_data["model_disease"],
224-
"time_resolution": form.cleaned_data[
225-
"model_time_resolution"
226-
],
227205
}
228206

229207
status_code, model = update_model(

src/static/js/vis/dashboard/predictions.js

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ document.addEventListener('DOMContentLoaded', function() {
8888
});
8989
}
9090
});
91+
9192
});
9293

9394

@@ -214,6 +215,7 @@ class Storage {
214215
end_window_date: null,
215216
adm_1: null,
216217
adm_2: null,
218+
score: null,
217219
}
218220
}
219221
data[this.dashboard].prediction_ids = data[this.dashboard].prediction_ids || [];
@@ -231,6 +233,7 @@ class Storage {
231233
}
232234
data[this.dashboard].adm_1 = data[this.dashboard].adm_1 || null;
233235
data[this.dashboard].adm_2 = data[this.dashboard].adm_2 || null;
236+
data[this.dashboard].score = data[this.dashboard].score || null;
234237
localStorage.setItem("dashboards", JSON.stringify(data));
235238
}
236239

@@ -301,7 +304,7 @@ class ModelList {
301304
<td class="truncate-name"><a href="/${model.author.username}/">${model.author.name}</a></td>
302305
<td class="truncate-name">${model.updated}</td>
303306
</tr>
304-
<tr class="expandable-body d-none"><td colspan="2"><p>${model.description}</p></td></tr>
307+
<tr class="expandable-body d-none"><td colspan="5"><p>${model.description}</p></td></tr>
305308
`;
306309
}
307310

@@ -457,6 +460,7 @@ class PredictionList {
457460
constructor(dashboard) {
458461
this.dashboard = dashboard;
459462
this.predictions_map = {};
463+
this.current_predictions = [];
460464
this.get_data();
461465
}
462466

@@ -491,27 +495,25 @@ class PredictionList {
491495
const selected = storage.get("prediction_ids").includes(prediction.id);
492496

493497
return `
494-
<tr data-widget="expandable-table" aria-expanded="false" class="prediction-row">
498+
<tr data-widget="expandable-table" aria-expanded="false" class="prediction-row" data-id="${prediction.id}">
495499
<td style="width: 40px;" class="${selected ? 'selected' : ''}" id="td-${prediction.id}">
496500
<input type="checkbox" value="${prediction.id}" id="checkbox-${prediction.id}" class="checkbox-prediction">
497501
</td>
498-
<td>${prediction.id}</td>
499-
<td>${prediction.start_date}</td>
500-
<td>${prediction.end_date}</td>
502+
<td style="width: 40px;">${prediction.id}</td>
503+
<td style="width: 40px;"><a href="/registry/model/${prediction.model}/">${prediction.model}</a></td>
504+
<td style="width: 110px;">${prediction.start_date}</td>
505+
<td style="width: 110px;">${prediction.end_date}</td>
506+
<td style="width: 150px;">${prediction.scores[storage.get("score")] || "-"}</td>
501507
</tr>
502-
<tr class="expandable-body d-none"><td colspan="2"><p>${prediction.description}</p></td></tr>
508+
<tr class="expandable-body d-none"><td colspan="6"><p>${prediction.description}</p></td></tr>
503509
`;
504510
}
505511

506-
507-
508512
list(predictions) {
509-
predictions.sort((a, b) => {
510-
const aChecked = storage.get("prediction_ids").includes(a.id);
511-
const bChecked = storage.get("prediction_ids").includes(b.id);
512-
if (aChecked && !bChecked) return -1;
513-
if (!aChecked && bChecked) return 1;
514-
return 0;
513+
predictions = [...predictions].sort((a, b) => {
514+
const aScore = a.scores[storage.get("score")] ?? Infinity;
515+
const bScore = b.scores[storage.get("score")] ?? Infinity;
516+
return aScore - bScore;
515517
});
516518

517519
const self = this;
@@ -562,6 +564,10 @@ class PredictionList {
562564
chart.clearPredictions();
563565
self.paginate(self.filter(predictions, admLevel, $(this).val()));
564566
});
567+
568+
$("#predictions-clear-all").on("click", function() {
569+
self.clear()
570+
});
565571
}
566572

567573
filter(predictions, adm_level, adm) {
@@ -586,34 +592,46 @@ class PredictionList {
586592

587593
paginate(predictions) {
588594
const self = this;
595+
this.current_predictions = predictions;
589596
$('#predictions-pagination').pagination({
590597
dataSource: predictions,
591598
pageSize: 5,
592599
callback: function(data, pagination) {
593600
const body = data.map((item) => self.li(item)).join("");
601+
const score = storage.get("score");
594602
$(`#predictions-list`).html(`
595603
<thead>
596604
<tr>
597605
<th style="width: 40px;">
598606
<input type="checkbox" id="select-all-checkbox">
599607
</th>
600-
<th>ID</th>
601-
<th>Start Date</th>
602-
<th>End Date</th>
603-
<th style="width: 100px;">
604-
<select id="scores" title="Score" class="form-select form-select-sm w-auto" style="width: 80px !important;">
605-
<option value="mae">MAE</option>
606-
<option value="mse">MSE</option>
607-
<option value="crps">CRPS</option>
608-
<option value="log_score">Log Score</option>
609-
<option value="interval_score">Interval Score</option>
610-
</select>
608+
<th style="width: 65px;">ID</th>
609+
<th style="width: 85px;">Model</th>
610+
<th style="width: 110px;">Start Date</th>
611+
<th style="width: 110px;">End Date</th>
612+
<th style="width: 150px;">
613+
<div class="row">
614+
<div class="col">Score</div>
615+
<div class="col">
616+
<select id="scores" title="Score" class="form-select form-select-sm w-auto" style="width: 80px !important;">
617+
<option value="mae" ${score === "mae" ? "selected" : ""}>MAE</option>
618+
<option value="mse" ${score === "mse" ? "selected" : ""}>MSE</option>
619+
<option value="crps" ${score === "crps" ? "selected" : ""}>CRPS</option>
620+
<option value="log_score" ${score === "log_score" ? "selected" : ""}>Log Score</option>
621+
<option value="interval_score" ${score === "interval_score" ? "selected" : ""}>Interval Score</option>
622+
</select>
623+
</div>
624+
</div>
611625
</th>
612626
</tr>
613627
</thead>
614628
<tbody>${body}</tbody>
615629
`);
616630

631+
$("#scores").on("change", function() {
632+
self.set_score($(this).val());
633+
});
634+
617635
$(".checkbox-prediction").each(function() {
618636
const prediction_id = parseInt($(this).val(), 10);
619637
const td = $(`#td-${prediction_id}`);
@@ -647,10 +665,22 @@ class PredictionList {
647665
self.unselect(prediction_id)
648666
}
649667
});
668+
669+
$("#select-all-checkbox").prop("checked", $(".checkbox-prediction").length === $(".checkbox-prediction:checked").length);
650670
},
651671
});
652672
}
653673

674+
set_score(score) {
675+
storage.set("score", score);
676+
const predictions = [...this.current_predictions].sort((a, b) => {
677+
const aScore = a.scores[score] ?? Infinity;
678+
const bScore = b.scores[score] ?? Infinity;
679+
return aScore - bScore;
680+
});
681+
this.list(predictions);
682+
}
683+
654684
select(prediction) {
655685
let prediction_ids = new Set(storage.get("prediction_ids"));
656686

@@ -679,6 +709,12 @@ class PredictionList {
679709
const td = $(`#td-${prediction_id}`);
680710
td.removeClass('selected');
681711
td.css("background-color", '');
712+
$(`.checkbox-prediction[value="${prediction_id}"]`).prop("checked", false);
713+
$("#select-all-checkbox").prop("checked", false);
714+
}
715+
716+
clear() {
717+
storage.get("prediction_ids").forEach(id => this.unselect(id));
682718
}
683719
}
684720

src/templates/main/edit-model.html

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,6 @@
3030
</textarea>
3131
</div>
3232
</div>
33-
<div class="row mb-3">
34-
<div class="col">
35-
<label for="model_time_resolution"><b>{% translate "Time resolution" %}:</b></label>
36-
<select id="edit-time-resolution" name="model_time_resolution" class="form-control" required>
37-
{% for value, label in time_resolutions %}
38-
<option value="{{ value }}" {% if value == model.time_resolution %}selected{% endif %}>
39-
{{ label }}
40-
</option>
41-
{% endfor %}
42-
</select>
43-
</div>
44-
<div class="col">
45-
<label for="model_adm_level"><b>{% translate "ADM Level" %}:</b></label>
46-
<select id="edit-adm-level" name="model_adm_level" class="form-control" required>
47-
{% for level, label in adm_levels %}
48-
<option value="{{ level }}" {% if level == model.ADM_level %}selected{% endif %}>
49-
{{ level }} - {{ label }}
50-
</option>
51-
{% endfor %}
52-
</select>
53-
</div>
54-
<div class="col">
55-
<label for="model_disease"><b>{% translate "Disease" %}:</b></label>
56-
<select id="edit-disease" name="model_disease" class="form-control" required>
57-
{% for disease, label in diseases %}
58-
<option value="{{ disease }}" {% if disease == model.disease %}selected{% endif %}>
59-
{{ label }}
60-
</option>
61-
{% endfor %}
62-
</select>
63-
</div>
64-
</div>
6533
<div class="row mb-3">
6634
<div class="col">
6735
<label for="model_repository"><b>{% translate "Github repository" %}:</b></label>

src/templates/vis/dashboard/predictions.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ <h3 class="card-title">Predictions</h3>
5353
</table>
5454
</div>
5555
<div class="card-footer clearfix">
56-
<ul id="predictions-pagination" class="pagination pagination-sm m-0 float-right"></ul>
56+
<div class="row">
57+
<div class="col">
58+
<button id="predictions-clear-all" type="button" class="btn btn-tool">Clear</button>
59+
</div>
60+
<div class="col">
61+
<ul id="predictions-pagination" class="pagination pagination-sm m-0 float-right"></ul>
62+
</div>
63+
</div>
5764
</div>
5865
</div>
5966
</div>
@@ -98,7 +105,6 @@ <h3 class="card-title">Tags</h3>
98105
gap: 20px;
99106
justify-content: space-between;
100107
align-items: flex-start;
101-
background-color: wheat;
102108
}
103109

104110
.tag-group {
@@ -178,6 +184,11 @@ <h3 class="card-title">Tags</h3>
178184
margin-bottom: 0;
179185
}
180186

187+
#scores {
188+
height: 25px;
189+
font-size: 0.75rem;
190+
}
191+
181192
#adm-filter {
182193
height: calc(1.8125rem + 2px);
183194
width: 200px !important;

src/vis/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def get_predictions(request) -> JsonResponse:
182182

183183
p_res = {}
184184
p_res["id"] = p.id
185+
p_res["model"] = p.model.id
185186
p_res["description"] = p.description
186187
p_res["adm_1"] = p.adm_1_geocode
187188
p_res["adm_2"] = p.adm_2_geocode

0 commit comments

Comments
 (0)