commit 9a9d48e1dfc458be1c2730dba1ec6f15ceeb8817
parent 261d06460c3c667696aa13935b39dc3400777baf
Author: Natalie Pendragon <natpen@natpen.net>
Date: Sun, 5 Jul 2020 08:02:54 -0400
[serve] Add historical statistics page
Diffstat:
5 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/gus/lib/index_statistics.py b/gus/lib/index_statistics.py
@@ -104,6 +104,15 @@ def load_last_statistics_from_file(filename):
statistics = deserialize_statistics_line(lastline)
return statistics
+def load_all_statistics_from_file(filename):
+ with open(filename) as f:
+ data = f.readlines()
+ return [{
+ "date": datetime.strptime(line.split(",")[0], "%Y-%m-%d"),
+ "page_count": line.split(",")[2],
+ "domain_count": line.split(",")[3],
+ } for line in data[1:]]
+
def deserialize_statistics_line(line):
line_parts = line.split(",")
diff --git a/serve/models.py b/serve/models.py
@@ -8,21 +8,10 @@ from whoosh.index import open_dir
from . import constants
from gus.crawl import Page, Link
from gus.lib.gemini import GeminiResource
-from gus.lib.index_statistics import compute_index_statistics, load_last_statistics_from_file
+from gus.lib.index_statistics import compute_index_statistics, load_all_statistics_from_file
from gus.lib.misc import bytes2human
from gus.lib.whoosh_extensions import GeminiFormatter, GeminiScorer
-def init_db(filename = ":memory:"):
- """
- Bind an SQLite database to the Peewee ORM models.
- """
- models = [Page, Link]
- db = SqliteDatabase(filename)
- db.bind(models)
- db.create_tables(models)
- return db
-
-
class GUS():
def __init__(self):
self.ix = open_dir(constants.INDEX_DIR)
@@ -35,8 +24,20 @@ class GUS():
order=highlight.SCORE,
)
- self.db = init_db(f"{constants.INDEX_DIR}/{constants.DB_FILENAME}")
+ self.db = GUS.init_db(f"{constants.INDEX_DIR}/{constants.DB_FILENAME}")
self.statistics = compute_index_statistics(self.db)
+ self.statistics_historical_overall = load_all_statistics_from_file(constants.STATISTICS_FILE)
+
+
+ def init_db(filename = ":memory:"):
+ """
+ Bind an SQLite database to the Peewee ORM models.
+ """
+ models = [Page, Link]
+ db = SqliteDatabase(filename)
+ db.bind(models)
+ db.create_tables(models)
+ return db
def init_query_parser(ix):
diff --git a/serve/templates/news.gmi b/serve/templates/news.gmi
@@ -3,6 +3,9 @@
## News
+### 2020-07-05
+Added historical statistics page, viewable at gemini://gus.guru/statistics/historical/overall
+
### 2020-07-03
Added support for viewing backlinks to pages. You can find this functionality on search result pages when in verbose mode. If GUS knows of pages linking to a given result (a.k.a., a "backlink"), it will add an option to view those backlinks. This comes on the heels of some interesting discussion regarding tracking replies in Geminispace, and could open the door to some novel functionality built on top of this feature - e.g. the ability to "subscribe" to updates to your own posts, and if a new backlink is discovered, it could notify you somehow. Alternatively, since the URL structure to reach a given page's backlinks page is predictable, one could also simply place a link on content pages to their corresponding GUS backlinks page, which readers could navigate to after reading, to find related content to read. As always, documentation for this new feature can be found on the about page. A number of small changes to verbose mode also went out with this release - in particular, there is now a button on search result pages to toggle verbose mode, so you don't need to muck around with the URL manually to toggle it, and verbose mode is now sticky between search result pages when using the previous/first/next page links at the bottom.
diff --git a/serve/templates/statistics.gmi b/serve/templates/statistics.gmi
@@ -12,6 +12,8 @@ Page Count : {{ "{:>5}".format(statistics.page_count) }}
Domain Count : {{ "{:>5}".format(statistics.domain_count) }}
```
+=> /statistics/historical/overall historical data
+
### By Content Type
These figures are representative of the number of pages seen per content type at the time the current index was last updated on {{ index_modification_time }}.
diff --git a/serve/views.py b/serve/views.py
@@ -49,6 +49,14 @@ def statistics(request):
return Response(Status.SUCCESS, "text/gemini", body)
+@app.route("/statistics/historical/overall", strict_trailing_slash=False)
+def statistics(request):
+ body = render_template("statistics_historical_overall.gmi",
+ statistics_historical_overall=gus.statistics_historical_overall,
+ index_modification_time=gus.statistics["index_modification_time"])
+ return Response(Status.SUCCESS, "text/gemini", body)
+
+
@app.route("/known-hosts", strict_trailing_slash=False)
def known_hosts(request):
body = render_template("known_hosts.gmi",