From 5990a938a46d118c5b6ca950bb4ffcc2b2637136 Mon Sep 17 00:00:00 2001 From: Andrej Karpathy Date: Sat, 27 Nov 2021 14:47:28 -0800 Subject: [PATCH] add few more stats --- serve.py | 12 ++++++++++-- templates/stats.html | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/serve.py b/serve.py index 62cc74c..df1d6ff 100644 --- a/serve.py +++ b/serve.py @@ -302,14 +302,22 @@ def stats(): context = default_context() mdb = get_metas() kv = {k:v for k,v in mdb.items()} # read all of metas to memory at once, for efficiency + times = [v['_time'] for v in kv.values()] tstr = lambda t: time.strftime('%b %d %Y', time.localtime(t)) + context['num_papers'] = len(kv) if len(kv) > 0: - context['earliest_paper'] = tstr(min(kv.values(), key=lambda x: x['_time'])['_time']) - context['latest_paper'] = tstr(max(kv.values(), key=lambda x: x['_time'])['_time']) + context['earliest_paper'] = tstr(min(times)) + context['latest_paper'] = tstr(max(times)) else: context['earliest_paper'] = 'N/A' context['latest_paper'] = 'N/A' + + # count number of papers from various time deltas to now + tnow = time.time() + for thr in [1, 6, 12, 24, 48, 72, 96]: + context['thr_%d' % thr] = len([t for t in times if t > tnow - thr*60*60]) + return render_template('stats.html', **context) @app.route('/about') diff --git a/templates/stats.html b/templates/stats.html index f588332..5d6dfc5 100644 --- a/templates/stats.html +++ b/templates/stats.html @@ -5,10 +5,24 @@ {% block content %}
-
Current database index:
-
Number of papers: {{ num_papers }}
+ +
Current index:
+
Number of papers total: {{ num_papers }}
Earliest paper: {{ earliest_paper }}
Latest paper: {{ latest_paper }}
+ +
+ + +
New paper counts flow:
+
Number of new papers in the last 1 hour : {{ thr_1 }}
+
Number of new papers in the last 6 hours: {{ thr_6 }}
+
Number of new papers in the last 12 hours: {{ thr_12 }}
+
Number of new papers in the last 24 hours: {{ thr_24 }}
+
Number of new papers in the last 48 hours: {{ thr_48 }}
+
Number of new papers in the last 72 hours: {{ thr_72 }}
+
Number of new papers in the last 96 hours: {{ thr_96 }}
+
{% endblock %}