stats update

This commit is contained in:
Administrator 2023-10-03 20:43:56 +03:00
parent 14918f18a7
commit 4bf77ff3af
2 changed files with 11 additions and 2 deletions

View File

@ -14,19 +14,22 @@ class StatsView(BaseView):
required_login = True required_login = True
def get(self): def get(self):
count = 20 count = 12
snapshots = list(Snapshot.objects.filter(project=self.request.user.selected_project).order_by('-created_at')[:count]) snapshots = list(Snapshot.objects.filter(project=self.request.user.selected_project).order_by('-created_at')[:count])
keys = set() keys = set()
for snapshot in snapshots: for snapshot in snapshots:
for key in snapshot.data: for key in snapshot.data:
keys.add(key) keys.add(key)
keys = list(keys) keys = list(keys)
keys.sort()
rows = [[key] for key in keys] rows = [[key] for key in keys]
times = []
for snapshot in snapshots: for snapshot in snapshots:
times.append(snapshot.created_at)
for index, key in enumerate(keys): for index, key in enumerate(keys):
rows[index].append(snapshot.data.get(key)) rows[index].append(snapshot.data.get(key))
self.context['keys'] = keys
self.context['data'] = rows self.context['data'] = rows
self.context['times'] = times
self.context['err'] = 'err' in self.request.GET self.context['err'] = 'err' in self.request.GET
def post(self): def post(self):

View File

@ -12,6 +12,12 @@
</div> </div>
{% endif %} {% endif %}
<table class="table"> <table class="table">
<thead>
<th>Время</th>
{% for time in times %}
<th>{{ time.date.day }}-{{ time.date.month }}<br>{{ time.hour }}:{% if time.minute < 10 %}0{% endif %}{{ time.minute }}</th>
{% endfor %}
</thead>
<tbody> <tbody>
{% for row in data %} {% for row in data %}
<tr> <tr>