Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(dashboard): replace Altair by a eCharts.js to render graphs in the frontend #231

Merged
merged 33 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
60e6d18
fix(dashboard): replace API calls by client side logic
luabida Nov 12, 2024
7fba451
initializing localStorage data
luabida Nov 12, 2024
fe84bea
finish menu js with localStorage (cookies)
luabida Nov 15, 2024
4bc9b74
remove unecessary code from menu.html
luabida Nov 15, 2024
aed539b
fix populateAdm1Menu
luabida Nov 20, 2024
0324718
Set start and end window date according to the selected predictions
luabida Nov 21, 2024
4744a12
include predictions data on browser cache for 3h
luabida Nov 22, 2024
4c802ff
render the first five items of the list if none predictions are selected
luabida Nov 22, 2024
5e5913a
include charts rendering in localStorage (browser cache)
luabida Nov 22, 2024
bb35e12
fix cachedChart & add hover to predict-list
luabida Nov 22, 2024
659f63d
include daterangeslider back
luabida Nov 29, 2024
2279e87
chore(dashboard): replace Altair by a Chart.js to render graphs in th…
luabida Jan 14, 2025
be84038
include hex color in Prediction; add dateslider back
luabida Jan 15, 2025
54bb623
remove search by model attr, replace entirely by tag search; add Tag.…
luabida Jan 15, 2025
8a703ab
Include api for tag searching
luabida Jan 16, 2025
da87238
Include search logic on models-list
luabida Jan 17, 2025
1b04d9e
Add tags to template; model selection to localStorage
luabida Jan 17, 2025
46fbfa1
include css for tags; update them to properly use groupping
luabida Jan 20, 2025
d40753f
include tag filtering
luabida Jan 20, 2025
8cd0fc8
logic for predictions
luabida Jan 23, 2025
17af686
Isolate LineChart into its own interface
luabida Jan 24, 2025
d439cd4
replace Chart.js with eCharts
luabida Jan 27, 2025
bac1d3d
include confidence interval into data; try to show it in chart
luabida Jan 27, 2025
5613de3
create interface to localStorage
luabida Jan 28, 2025
b9d9e14
implement interfaces & minor logic improvements
luabida Jan 28, 2025
1acaa06
PredictionList improv
luabida Jan 28, 2025
d3f2f3d
start setting visual & styles
luabida Jan 30, 2025
9412d19
Include scores fields on Prediction & update them weekly
luabida Jan 30, 2025
75e7f1d
Improve caching & clear cache
luabida Jan 30, 2025
56087f3
fix chart tooltip; include watermark; include yaxis name
luabida Feb 3, 2025
299e182
include model info
luabida Feb 3, 2025
8849df9
include scores select dropdown
luabida Feb 3, 2025
0b9ca49
finish logic for score selecting and sorting
luabida Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion containers/mosqlimate/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ COPY --chown=mosqlimate:mosqlimate pyproject.toml /opt/services/mosqlimate
RUN pip install "cython<3.0.0" \
&& pip install --no-build-isolation "pyyaml<6.0" \
&& poetry config virtualenvs.create false \
&& poetry install --without pre-commit,dev,docs
&& poetry install --no-root --without pre-commit,dev,docs

COPY --chown=mosqlimate:mosqlimate containers/entrypoint.sh /opt/entrypoint.sh
ADD --chown=mosqlimate:mosqlimate src/ /opt/services/mosqlimate/
Expand Down
16 changes: 16 additions & 0 deletions src/datastore/migrations/0007_alter_copernicusbrasil_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.18 on 2025-02-03 11:22

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("datastore", "0006_sprint202425_delete_sprint202425schema"),
]

operations = [
migrations.AlterModelTable(
name="copernicusbrasil",
table="copernicus_bra",
),
]
4 changes: 2 additions & 2 deletions src/datastore/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class Meta:

class CopernicusBrasil(models.Model):
date = models.DateField(db_column="date", primary_key=True)
geocodigo = models.BigIntegerField(db_column="geocodigo")
geocodigo = models.BigIntegerField(db_column="geocode")
temp_min = models.FloatField(db_column="temp_min")
temp_med = models.FloatField(db_column="temp_med")
temp_max = models.FloatField(db_column="temp_max")
Expand All @@ -210,7 +210,7 @@ class CopernicusBrasil(models.Model):

class Meta:
managed = False
db_table = "copernicus_brasil"
db_table = "copernicus_bra"
constraints = [
models.UniqueConstraint(
fields=["date", "geocodigo"], name="composite_primary_key"
Expand Down
3 changes: 0 additions & 3 deletions src/main/templatetags/vis_echarts_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ def vis_echarts(context):
}
)

from pprint import pprint

pprint(br_info_data)
context.update(br_info_data)

return context
22 changes: 0 additions & 22 deletions src/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,6 @@ def get(self, request, model_id: int):
context = {
"model": model,
"implementation_languages": languages,
"diseases": [
("dengue", "Dengue"),
("zika", "Zika"),
("chikungunya", "Chikungunya"),
],
"adm_levels": [
(0, _("National")),
(1, _("State")),
(2, _("Municipality")),
(3, _("Sub Municipality")),
],
"time_resolutions": [
("day", _("Day")),
("week", _("Week")),
("month", _("Month")),
("year", _("Year")),
],
}
return render(request, self.template_name, context)

Expand Down Expand Up @@ -219,11 +202,6 @@ def post(self, request, model_id: int):
),
"spatial": form.data.get("model_spatial") == "True",
"temporal": form.data.get("model_temporal") == "True",
"ADM_level": form.cleaned_data["model_adm_level"],
"disease": form.cleaned_data["model_disease"],
"time_resolution": form.cleaned_data[
"model_time_resolution"
],
}

status_code, model = update_model(
Expand Down
3 changes: 3 additions & 0 deletions src/mosqlimate/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS

MIDDLEWARE = [
"django.middleware.cache.UpdateCacheMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.cache.FetchFromCacheMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
Expand Down
28 changes: 28 additions & 0 deletions src/registry/migrations/0041_prediction_color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.17 on 2025-01-15 14:30

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("registry", "0040_alter_predictiondatarow_adm_0"),
]

operations = [
migrations.AddField(
model_name="prediction",
name="color",
field=models.CharField(
help_text="Color in hexadecimal format. E.g: #ffffff",
max_length=7,
null=True,
validators=[
django.core.validators.RegexValidator(
message="Color must be in hexadecimal format, e.g., #ffffff",
regex="^#[0-9A-Fa-f]{6}$",
)
],
),
),
]
22 changes: 22 additions & 0 deletions src/registry/migrations/0042_alter_prediction_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.17 on 2025-01-15 17:54

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
("registry", "0041_prediction_color"),
]

operations = [
migrations.AlterField(
model_name="prediction",
name="model",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="predictions",
to="registry.model",
),
),
]
17 changes: 17 additions & 0 deletions src/registry/migrations/0043_tag_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.17 on 2025-01-15 20:46

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("registry", "0042_alter_prediction_model"),
]

operations = [
migrations.AddField(
model_name="tag",
name="group",
field=models.CharField(null=True, unique=True),
),
]
26 changes: 26 additions & 0 deletions src/registry/migrations/0044_prediction_tags_alter_model_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.17 on 2025-01-16 13:43

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("registry", "0043_tag_group"),
]

operations = [
migrations.AddField(
model_name="prediction",
name="tags",
field=models.ManyToManyField(
default=[], related_name="prediction_tags", to="registry.tag"
),
),
migrations.AlterField(
model_name="model",
name="tags",
field=models.ManyToManyField(
default=[], related_name="model_tags", to="registry.tag"
),
),
]
17 changes: 17 additions & 0 deletions src/registry/migrations/0045_alter_tag_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.18 on 2025-01-20 14:21

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("registry", "0044_prediction_tags_alter_model_tags"),
]

operations = [
migrations.AlterField(
model_name="tag",
name="group",
field=models.CharField(null=True),
),
]
28 changes: 28 additions & 0 deletions src/registry/migrations/0046_alter_prediction_color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.18 on 2025-01-23 14:20

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("registry", "0045_alter_tag_group"),
]

operations = [
migrations.AlterField(
model_name="prediction",
name="color",
field=models.CharField(
default="#000000",
help_text="Color in hexadecimal format. E.g: #ffffff",
max_length=7,
validators=[
django.core.validators.RegexValidator(
message="Color must be in hexadecimal format, e.g., #ffffff",
regex="^#[0-9A-Fa-f]{6}$",
)
],
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 4.2.18 on 2025-01-30 16:11

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("registry", "0046_alter_prediction_color"),
]

operations = [
migrations.AddField(
model_name="prediction",
name="crps",
field=models.FloatField(default=None, null=True),
),
migrations.AddField(
model_name="prediction",
name="interval_score",
field=models.FloatField(default=None, null=True),
),
migrations.AddField(
model_name="prediction",
name="log_score",
field=models.FloatField(default=None, null=True),
),
migrations.AddField(
model_name="prediction",
name="mae",
field=models.FloatField(default=None, null=True),
),
migrations.AddField(
model_name="prediction",
name="mse",
field=models.FloatField(default=None, null=True),
),
]
40 changes: 38 additions & 2 deletions src/registry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def get_plangs_path() -> str:

class Tag(models.Model):
name = models.CharField(max_length=30, unique=True)
group = models.CharField(unique=False, null=True)
color = models.CharField(
max_length=7,
null=True,
Expand Down Expand Up @@ -181,7 +182,7 @@ class ADM_levels(models.IntegerChoices):
)
name = models.CharField(max_length=100, null=False, blank=False)
description = models.TextField(max_length=500, null=True, blank=True)
tags = models.ManyToManyField(Tag, related_name="tags", default=[])
tags = models.ManyToManyField(Tag, related_name="model_tags", default=[])
repository = models.CharField(max_length=100, null=False, blank=False)
implementation_language = models.ForeignKey(
ImplementationLanguage,
Expand Down Expand Up @@ -220,11 +221,30 @@ class Meta:


class Prediction(models.Model):
model = models.ForeignKey(Model, on_delete=models.CASCADE, null=False)
model = models.ForeignKey(
Model, on_delete=models.CASCADE, null=False, related_name="predictions"
)
description = models.TextField(max_length=500, null=True, blank=True)
commit = models.CharField(max_length=100, null=False, blank=False)
predict_date = models.DateField()
tags = models.ManyToManyField(
Tag, related_name="prediction_tags", default=[]
)
# Metadata
color = models.CharField(
max_length=7,
null=False,
default="#000000",
validators=[
RegexValidator(
regex=r"^#[0-9A-Fa-f]{6}$",
message=_(
"Color must be in hexadecimal format, e.g., #ffffff"
),
),
],
help_text=_("Color in hexadecimal format. E.g: #ffffff"),
)
visualizable = models.BooleanField(default=False)
metadata = models.CharField(null=True, default=None)
adm_0_geocode = models.CharField(max_length=3, null=True, default="BRA")
Expand All @@ -233,6 +253,12 @@ class Prediction(models.Model):
adm_3_geocode = models.IntegerField(null=True, default=None) # TODO
date_ini_prediction = models.DateTimeField(null=True, default=None)
date_end_prediction = models.DateTimeField(null=True, default=None)
# scores
mae = models.FloatField(null=True, default=None)
mse = models.FloatField(null=True, default=None)
crps = models.FloatField(null=True, default=None)
log_score = models.FloatField(null=True, default=None)
interval_score = models.FloatField(null=True, default=None)

created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
Expand Down Expand Up @@ -276,6 +302,16 @@ def to_json(self) -> str:

return json.dumps(data)

@property
def scores(self) -> dict:
return {
"mae": self.mae,
"mse": self.mse,
"crps": self.crps,
"log_score": self.log_score,
"interval_score": self.interval_score,
}

def parse_metadata(self):
if not self.to_dataframe().empty:
self._add_adm_geocode()
Expand Down
Loading
Loading