From a6697fab58d827ed353fd7b63ff6882fb62c2070 Mon Sep 17 00:00:00 2001 From: retoor Date: Tue, 26 Nov 2024 09:21:46 +0100 Subject: [PATCH] Cleanup --- README.md | 4 +-- setup.cfg | 5 +-- src/drstats/statistics.py | 76 ++++++++++++++------------------------- 3 files changed, 29 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index b57a508..12fc49f 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ Also this data will be used for retoor9b, the newest AI hype! You're still using ## Statistics by last build -Click here for latest [dataset](https://retoor.molodetz.nl/retoor/drstats/src/branch/main/export/0_dataset.txt). +Click here for latest [dataset](https://retoor.molodetz.nl/retoor/drstats/src/branch/main/export/0_dataset.txt) optimized for training LLM's like retoor9b. -Click here for latest [graphs compilaiton](https://retoor.molodetz.nl/retoor/drstats/src/branch/main/export/1_graphs_compliation.png). +Click here for latest [graphs compilation](https://retoor.molodetz.nl/retoor/drstats/src/branch/main/export/1_graphs_compliation.png). Click here for all generated [data](https://retoor.molodetz.nl/retoor/drstats/src/branch/main/export). It's a big dataset containing data for LLM's to train on, graphs per user or overal statistics and json files with all made observations. diff --git a/setup.cfg b/setup.cfg index 9ed26ce..b0b140c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,8 +25,5 @@ where = src [options.entry_points] console_scripts = dr.sync = drstats.sync:sync - dr.rant_stats_per_day = drstats.statistics:rant_stats_per_day - dr.rant_stats_per_weekday = drstats.statistics:rant_stats_per_weekday - dr.rant_stats_per_hour = drstats.statistics:rant_stats_per_hour - dr.stats_all = drstats.statistics:rant_stats_all + dr.stats = drstats.statistics:rant_stats_all dr.dataset = drstats.dataset:dump \ No newline at end of file diff --git a/src/drstats/statistics.py b/src/drstats/statistics.py index 513858f..78e4e77 100644 --- a/src/drstats/statistics.py +++ b/src/drstats/statistics.py @@ -1,38 +1,26 @@ from drstats.db import get_db, Db, get_users -from drstats import sync import asyncio from drstats.duration import Duration -from time import sleep -import importlib -def plt_reset(): - pass - -_figure_count = 0 - - -def figure_inc(): +def new_plot(): import matplotlib.pyplot as plt - plt.clf() plt.cla() plt.close(0) plt.figure(figsize=(8, 8)) return plt - # return pyplot.figure(_figure_count) def get_date_range(): - db = get_db() - for record in db.query( - "SELECT min(date(created)) as start_date, max(date(created)) as end_date FROM rants" - ): - db.close() + with Db() as db: + record = list(db.query( + "SELECT min(date(created)) as start_date, max(date(created)) as end_date FROM rants" + ))[0] return record["start_date"], record["end_date"] - db.close() + def get_date_range_str(): @@ -42,7 +30,7 @@ def get_date_range_str(): async def rant_stats_per_day(): with Duration("Rant stats per day"): - plt = figure_inc() + plt = new_plot() async with Db() as db: x = [] y = [] @@ -62,14 +50,13 @@ async def rant_stats_per_day(): plt.title("Rants per day") plt.legend() plt.savefig(f"export/rants_per_day_{get_date_range_str()}.png") - plt_reset() - # plt.show() + async def comment_stats_per_day(): with Duration("Comment stats per day"): - plt = figure_inc() + plt = new_plot() async with Db() as db: x = [] y = [] @@ -89,13 +76,12 @@ async def comment_stats_per_day(): plt.title("Comments per day") plt.legend() plt.savefig(f"export/comments_per_day_{get_date_range_str()}.png") - plt_reset() - # plt.show() + async def rant_stats_per_weekday(): with Duration("Rant stats per weekday"): - plt = figure_inc() + plt = new_plot() async with Db() as db: x = [] y = [] @@ -111,13 +97,12 @@ async def rant_stats_per_weekday(): plt.title("Rants per weekday") plt.legend() plt.savefig(f"export/rants_per_weekday_{get_date_range_str()}.png") - plt_reset() - # plt.show() + async def comment_stats_per_weekday(): with Duration("Comment stats per weekday"): - plt = figure_inc() + plt = new_plot() async with Db() as db: x = [] y = [] @@ -133,13 +118,12 @@ async def comment_stats_per_weekday(): plt.title("Comments per weekday") plt.legend() plt.savefig(f"export/comments_per_weekday_{get_date_range_str()}.png") - plt_reset() - # plt.show() + async def rant_stats_per_hour(): with Duration("Rant stats per hour"): - plt = figure_inc() + plt = new_plot() async with Db() as db: x = [] y = [] @@ -155,13 +139,12 @@ async def rant_stats_per_hour(): plt.title("Rants per hour") plt.legend() plt.savefig(f"export/rants_per_hour_{get_date_range_str()}.png") - plt_reset() - # plt.show() + async def comment_stats_per_hour(): with Duration("Comment stats per hour"): - plt = figure_inc() + plt = new_plot() async with Db() as db: x = [] y = [] @@ -177,13 +160,12 @@ async def comment_stats_per_hour(): plt.title("Comments per hour") plt.legend() plt.savefig(f"export/comments_per_hour_{get_date_range_str()}.png") - plt_reset() - # plt.show() + async def score_most_ignored_last_7_days(): with Duration("Score most ignored last 7 days"): - plt = figure_inc() + plt = new_plot() async with Db() as db: x = [] y = [] @@ -195,7 +177,6 @@ async def score_most_ignored_last_7_days(): y.append(record["userscore"]) plt.bar(x, y, label="Upvotes") - # plt.plot(x, y, label=get_date_range_str(), color='pink') plt.xticks(rotation=45) plt.xlabel("Ranter") plt.ylabel("Times ignored") @@ -204,13 +185,12 @@ async def score_most_ignored_last_7_days(): plt.savefig( f"export/score_ignored_most_last_7_days_{get_date_range_str()}.png" ) - plt_reset() - # plt.show() - + + async def score_last_7_days(): with Duration("Upvotes (score) last 7 days"): - plt = figure_inc() + plt = new_plot() async with Db() as db: x = [] y = [] @@ -220,20 +200,18 @@ async def score_last_7_days(): y.append(record["userscore"]) plt.bar(x, y, label="Upvotes") - # plt.plot(x, y, label=get_date_range_str(), color='pink') plt.xticks(rotation=45) plt.xlabel("Ranter") plt.ylabel("Upvote count") plt.title("Most ignored based on score regarding last 7 days") plt.legend() plt.savefig(f"export/score_last_7_days_{get_date_range_str()}.png") - plt_reset() - # plt.show() + async def user_score_per_day(username): with Duration("User {} score per day".format(username)): - plt = figure_inc() + plt = new_plot() async with Db() as db: plt.xticks(rotation=45) @@ -280,12 +258,10 @@ async def user_score_per_day(username): plt.legend() plt.savefig(f"export/score_user_{username}_{get_date_range_str()}.png") - plt_reset() + -def rant_stats_all(): - print("Did you sync all rants before running this?") - sleep(3) +def stats(): with Duration("Complete process"): asyncio.run(rant_stats_per_day()) asyncio.run(rant_stats_per_weekday())