Skip to content

Commit

Permalink
Fixes (#237)
Browse files Browse the repository at this point in the history
* Fix translation table SPCH-13 -> Swiss7

Closes #219

* Show last day first in chart by hour

Closes #231

* Show value on mouse hover on category chart

Closes #232

* Add trash category column in reports

Closes #233

* Add alias to installation

Includes migration

Closes #230
  • Loading branch information
marioba authored Jan 14, 2022
1 parent 2240016 commit c712eb3
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion comptages/chart/chart_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def get_div(self):
name="Nouveau"),
1, num_of_charts)

fig.update_traces(hoverinfo="label+percent+name")
fig.update_traces(hoverinfo="label+percent+name+value")
fig.update_layout(title_text="Véhicules groupés par catégorie")

return plotly.offline.plot(fig, output_type='div')
Expand Down
6 changes: 3 additions & 3 deletions comptages/core/importer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytz
import os
from datetime import datetime, timedelta
from django.db.models import Q

from comptages.core import definitions
from comptages.datamodel import models
Expand Down Expand Up @@ -404,7 +405,8 @@ def guess_count(file_path):
header = _parse_file_header(file_path)

result = models.Count.objects.filter(
id_installation__name=header['SITE'],
Q(id_installation__name=header['SITE']) | Q(id_installation__alias=header['SITE']))
result = result.filter(
id_installation__active=True,
id_class__name=header['CLASS'],
start_service_date__lte=header['STARTREC'],
Expand All @@ -415,5 +417,3 @@ def guess_count(file_path):
return result[0]
else:
return None

# TODO: what to do if multiple results?
22 changes: 7 additions & 15 deletions comptages/core/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,6 @@ def _data_category(count, section, monday, workbook):
row_offset = 5
col_offset = 2
for category in categories:
if category.code == 0:
continue # We don't put TRASH category in report
res = statistics.get_category_data_by_hour(
count,
section,
Expand All @@ -785,7 +783,7 @@ def _data_category(count, section, monday, workbook):

for row in res:
row_num = row_offset + row[0]
col_num = col_offset + _t_cat(count, category.code) - 1
col_num = col_offset + _t_cat(count, category.code)
value = ws.cell(row_num, col_num).value + row[1] # Add to previous value because with class convertions multiple categories can converge into a single one

ws.cell(
Expand All @@ -798,8 +796,6 @@ def _data_category(count, section, monday, workbook):
row_offset = 33
col_offset = 2
for category in categories:
if category.code == 0:
continue # We don't put TRASH category in report
res = statistics.get_category_data_by_hour(
count,
section,
Expand All @@ -811,7 +807,7 @@ def _data_category(count, section, monday, workbook):

for row in res:
row_num = row_offset + row[0]
col_num = col_offset + _t_cat(count, category.code) - 1
col_num = col_offset + _t_cat(count, category.code)
value = ws.cell(row_num, col_num).value + row[1] # Add to previous value because with class convertions multiple categories can converge into a single one

ws.cell(
Expand All @@ -832,8 +828,6 @@ def _data_category_yearly(count, section, year, workbook):
row_offset = 5
col_offset = 2
for category in categories:
if category.code == 0:
continue # We don't put TRASH category in report
res = statistics.get_category_data_by_hour(
None,
section,
Expand All @@ -845,7 +839,7 @@ def _data_category_yearly(count, section, year, workbook):

for row in res:
row_num = row_offset + row[0]
col_num = col_offset + _t_cat(count, category.code) - 1
col_num = col_offset + _t_cat(count, category.code)
value = ws.cell(row_num, col_num).value + row[1] # Add to previous value because with class convertions multiple categories can converge into a single one

ws.cell(
Expand All @@ -858,8 +852,6 @@ def _data_category_yearly(count, section, year, workbook):
row_offset = 33
col_offset = 2
for category in categories:
if category.code == 0:
continue # We don't put TRASH category in report
res = statistics.get_category_data_by_hour(
None,
section,
Expand All @@ -871,7 +863,7 @@ def _data_category_yearly(count, section, year, workbook):

for row in res:
row_num = row_offset + row[0]
col_num = col_offset + _t_cat(count, category.code) - 1
col_num = col_offset + _t_cat(count, category.code)
value = ws.cell(row_num, col_num).value + row[1] # Add to previous value because with class convertions multiple categories can converge into a single one

ws.cell(
Expand Down Expand Up @@ -965,10 +957,10 @@ def _t_cat(count, cat_id):
6: 4,
7: 1,
8: 5,
9: 7,
10: 6,
9: 6,
10: 7,
11: 7,
12: 7,
12: 6,
13: 7,
}
return conv[cat_id]
Expand Down
2 changes: 1 addition & 1 deletion comptages/core/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_time_data(count, section, lane=None, direction=None, start=None, end=Non
qs = qs.annotate(date=Trunc('timestamp', 'day'), hour=ExtractHour('timestamp')) \
.order_by('hour') \
.values('date', 'hour', 'times') \
.order_by('date', 'hour') \
.order_by('-date', 'hour') \
.annotate(thm=Sum('times')) \
.values('import_status', 'date', 'hour', 'thm')

Expand Down
18 changes: 18 additions & 0 deletions comptages/datamodel/migrations/0023_installation_alias.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.5 on 2022-01-14 05:28

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('comptages', '0022_auto_20211217_0624'),
]

operations = [
migrations.AddField(
model_name='installation',
name='alias',
field=models.CharField(blank=True, max_length=200, null=True),
),
]
1 change: 1 addition & 0 deletions comptages/datamodel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class Installation(models.Model):
qdmtk_addlayer = True

id = models.BigAutoField(primary_key=True)
alias = models.CharField(blank=True, null=True, max_length=200)
permanent = models.BooleanField()
name = models.TextField()
picture = models.TextField(blank=True, null=True)
Expand Down
Binary file modified comptages/report/template.xlsx
Binary file not shown.
Binary file modified comptages/report/template_yearly.xlsx
Binary file not shown.

0 comments on commit c712eb3

Please sign in to comment.