statistics can load logs from archives
This commit is contained in:
parent
4cda6d42e4
commit
09d0cab206
|
@ -154,9 +154,14 @@ class Log(models.Model):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def merge_diffusions(cls, logs, diffs, count=None):
|
def merge_diffusions(cls, logs, diffs, count=None):
|
||||||
|
"""
|
||||||
|
Merge logs and diffusions together. `logs` can either be a queryset
|
||||||
|
or a list ordered by `Log.date`.
|
||||||
|
"""
|
||||||
# TODO: limit count
|
# TODO: limit count
|
||||||
# FIXME: log may be iterable (in stats view)
|
# FIXME: log may be iterable (in stats view)
|
||||||
logs = list(logs.order_by('-date'))
|
if isinstance(logs, models.QuerySet):
|
||||||
|
logs = list(logs.order_by('-date'))
|
||||||
diffs = deque(diffs.on_air().before().order_by('-start'))
|
diffs = deque(diffs.on_air().before().order_by('-start'))
|
||||||
object_list = []
|
object_list = []
|
||||||
|
|
||||||
|
@ -171,7 +176,7 @@ class Log(models.Model):
|
||||||
|
|
||||||
diff = diffs.popleft()
|
diff = diffs.popleft()
|
||||||
|
|
||||||
# - takes all logs after diff
|
# - takes all logs after diff start
|
||||||
index = next((i for i, v in enumerate(logs)
|
index = next((i for i, v in enumerate(logs)
|
||||||
if v.date <= diff.end), len(logs))
|
if v.date <= diff.end), len(logs))
|
||||||
if index is not None and index > 0:
|
if index is not None and index > 0:
|
||||||
|
|
|
@ -66,6 +66,7 @@
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<h4 class="title is-4">{% trans "Today" %}</h4>
|
<h4 class="title is-4">{% trans "Today" %}</h4>
|
||||||
|
{% with is_thin=True %}
|
||||||
{% with hide_schedule=True %}
|
{% with hide_schedule=True %}
|
||||||
{% with has_headline=False %}
|
{% with has_headline=False %}
|
||||||
<table class="table is-fullwidth has-background-transparent">
|
<table class="table is-fullwidth has-background-transparent">
|
||||||
|
@ -78,6 +79,7 @@
|
||||||
</table>
|
</table>
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
{% endwith %}
|
||||||
</section>
|
</section>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ Render list of logs (as widget).
|
||||||
|
|
||||||
Context:
|
Context:
|
||||||
- object_list: list of logs to display
|
- object_list: list of logs to display
|
||||||
|
- is_thin: if True, hide some information in order to fit in a thin container
|
||||||
{% endcomment %}
|
{% endcomment %}
|
||||||
{% load aircox %}
|
{% load aircox %}
|
||||||
|
|
||||||
|
@ -13,7 +14,8 @@ Context:
|
||||||
<td>
|
<td>
|
||||||
{% if object|is_diffusion %}
|
{% if object|is_diffusion %}
|
||||||
<time datetime="{{ object.start }}" title="{{ object.start }}">
|
<time datetime="{{ object.start }}" title="{{ object.start }}">
|
||||||
{{ object.start|date:"H:i" }} - {{ object.end|date:"H:i" }}
|
{{ object.start|date:"H:i" }}
|
||||||
|
{% if not is_thin %} - {{ object.end|date:"H:i" }}{% endif %}
|
||||||
</time>
|
</time>
|
||||||
{% else %}
|
{% else %}
|
||||||
<time datetime="{{ object.date }}" title="{{ object.date }}">
|
<time datetime="{{ object.date }}" title="{{ object.date }}">
|
||||||
|
|
|
@ -4,6 +4,7 @@ from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.generic import ListView
|
from django.views.generic import ListView
|
||||||
|
|
||||||
from .log import LogListView
|
from .log import LogListView
|
||||||
|
from ..models.log import LogArchiver
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['BaseAdminView', 'StatisticsView']
|
__all__ = ['BaseAdminView', 'StatisticsView']
|
||||||
|
@ -33,6 +34,8 @@ class StatisticsView(BaseAdminView, LogListView, ListView):
|
||||||
date = None
|
date = None
|
||||||
|
|
||||||
def get_object_list(self, logs, *_):
|
def get_object_list(self, logs, *_):
|
||||||
|
if not logs.exists():
|
||||||
|
logs = LogArchiver().load(self.station, self.date) if self.date else []
|
||||||
return super().get_object_list(logs, True)
|
return super().get_object_list(logs, True)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user