Skip to content

Commit

Permalink
Show amount of time in last 365 days for shows
Browse files Browse the repository at this point in the history
  • Loading branch information
jhong93 committed Jan 5, 2022
1 parent fbea745 commit 2d6faf2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
19 changes: 14 additions & 5 deletions app/route_data_json.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from datetime import datetime
from datetime import datetime, timedelta
from collections import namedtuple, defaultdict
from flask import Flask, Response, jsonify

Expand Down Expand Up @@ -43,12 +43,21 @@ def get_data_tags_json() -> Response:

@app.route('/data/shows.json')
def get_data_shows_json() -> Response:
tmp = defaultdict(float)
time_all = defaultdict(float)
time_1yr = defaultdict(float)
max_date_minus_1yr = max(
v.date for v in video_data_context.video_dict.values()
) - timedelta(days=365)
for v in video_data_context.video_dict.values():
tmp[(v.channel, v.show)] += v.num_frames / v.fps
s = v.num_frames / v.fps
k = (v.channel, v.show)
time_all[k] += s
if v.date >= max_date_minus_1yr:
time_1yr[k] += s

channel_and_show = [
(channel, show, round(seconds / 3600, 1))
for (channel, show), seconds in tmp.items()]
(*k, round(s / 3600, 1), round(time_1yr[k] / 3600, 1))
for k, s in time_all.items()]
channel_and_show.sort()
return jsonify({'data': channel_and_show})

Expand Down
5 changes: 4 additions & 1 deletion templates/data/shows.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ <h1>
<th>Channel</th>
<th>Show</th>
<th>Total screen time (in hours)</th>
<th>Last 365 days (in hours)</th>
</tr>
</thead>
</table>
Expand All @@ -39,7 +40,9 @@ <h1>
null,
{render: x => x.length > 0 ? x : '&lt;unnamed&gt;' },
{render: x => formatNumber(x, 1),
width: '25%', className: 'text-right'},
width: '20%', className: 'text-right'},
{render: x => formatNumber(x, 1),
width: '20%', className: 'text-right'},
],
order: [[2, 'desc']],
language: {
Expand Down

0 comments on commit 2d6faf2

Please sign in to comment.