Blacked.
This commit is contained in:
parent
a6697fab58
commit
a1b3ad2a92
@ -23,9 +23,7 @@ def dump():
|
||||
print("\n".join(statistics_text))
|
||||
all_content = ""
|
||||
for user in list(db.get_users()):
|
||||
text = (
|
||||
db.get_all_rants_of_user(user)
|
||||
)
|
||||
text = db.get_all_rants_of_user(user)
|
||||
total_text = ""
|
||||
if text:
|
||||
total_text += text
|
||||
@ -42,9 +40,7 @@ def dump():
|
||||
f.write(" said ")
|
||||
f.write(text)
|
||||
f.write("```")
|
||||
text = (
|
||||
db.get_all_posts_of_user(user)
|
||||
)
|
||||
text = db.get_all_posts_of_user(user)
|
||||
if text:
|
||||
total_text += text
|
||||
print(
|
||||
@ -62,7 +58,7 @@ def dump():
|
||||
f.write("```")
|
||||
all_content += total_text
|
||||
print("===Mentions of users:", "```")
|
||||
|
||||
|
||||
users = db.get_users()
|
||||
users.sort()
|
||||
for user in users:
|
||||
@ -76,4 +72,10 @@ def dump():
|
||||
printr(f"export/view-{view['name']}.json")
|
||||
with pathlib.Path(f"export/view-{view['name']}.json").open("w+") as f:
|
||||
with db.Db() as _db:
|
||||
json.dump([dict(record) for record in _db.query("SELECT * FROM {}".format(view['name']))],f)
|
||||
json.dump(
|
||||
[
|
||||
dict(record)
|
||||
for record in _db.query("SELECT * FROM {}".format(view["name"]))
|
||||
],
|
||||
f,
|
||||
)
|
||||
|
@ -206,8 +206,12 @@ def get_db():
|
||||
"CREATE VIEW posts_of_user AS SELECT user_username as username, GROUP_CONCAT(body) as text FROM comments"
|
||||
)
|
||||
db.query("DROP VIEW IF EXISTS contributions_extended_ranked")
|
||||
db.query("CREATE VIEW contributions_extended_ranked AS SELECT ROW_NUMBER() OVER (ORDER BY upvotes_per_post_on_average DESC) as rank_by_appreciation_based_on_upvotes_per_message, * FROM contributions_extended ORDER BY upvotes_per_post_on_average DESC")
|
||||
db.query("CREATE VIEW IF NOT EXISTS views AS SELECT sql, name FROM sqlite_schema WHERE type='view' AND name != 'views';")
|
||||
db.query(
|
||||
"CREATE VIEW contributions_extended_ranked AS SELECT ROW_NUMBER() OVER (ORDER BY upvotes_per_post_on_average DESC) as rank_by_appreciation_based_on_upvotes_per_message, * FROM contributions_extended ORDER BY upvotes_per_post_on_average DESC"
|
||||
)
|
||||
db.query(
|
||||
"CREATE VIEW IF NOT EXISTS views AS SELECT sql, name FROM sqlite_schema WHERE type='view' AND name != 'views';"
|
||||
)
|
||||
|
||||
return db
|
||||
|
||||
@ -246,21 +250,29 @@ def get_views():
|
||||
with Db() as db:
|
||||
return list(db.query("SELECT * FROM views;"))
|
||||
|
||||
|
||||
def get_contributions():
|
||||
with Db() as db:
|
||||
contributions = db.query(
|
||||
"SELECT * FROM contributions_extended_ranked"
|
||||
)
|
||||
contributions = db.query("SELECT * FROM contributions_extended_ranked")
|
||||
return list(contributions)
|
||||
|
||||
|
||||
def get_upvote_average():
|
||||
return avg(contribution["upvotes_per_post_on_average"] for contribution in get_contributions())
|
||||
return avg(
|
||||
contribution["upvotes_per_post_on_average"]
|
||||
for contribution in get_contributions()
|
||||
)
|
||||
|
||||
|
||||
def get_users():
|
||||
with Db() as db:
|
||||
return [user["username"] for user in db.query("SELECT DISTINCT username FROM contributions ORDER BY username")]
|
||||
return [
|
||||
user["username"]
|
||||
for user in db.query(
|
||||
"SELECT DISTINCT username FROM contributions ORDER BY username"
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def get_user_count():
|
||||
return len(get_users())
|
||||
|
@ -3,10 +3,9 @@ import asyncio
|
||||
from drstats.duration import Duration
|
||||
|
||||
|
||||
|
||||
|
||||
def new_plot():
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
plt.clf()
|
||||
plt.cla()
|
||||
plt.close(0)
|
||||
@ -16,11 +15,12 @@ def new_plot():
|
||||
|
||||
def get_date_range():
|
||||
with Db() as db:
|
||||
record = list(db.query(
|
||||
"SELECT min(date(created)) as start_date, max(date(created)) as end_date FROM rants"
|
||||
))[0]
|
||||
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"]
|
||||
|
||||
|
||||
|
||||
def get_date_range_str():
|
||||
@ -50,7 +50,6 @@ 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")
|
||||
|
||||
|
||||
|
||||
async def comment_stats_per_day():
|
||||
@ -76,7 +75,6 @@ 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")
|
||||
|
||||
|
||||
|
||||
async def rant_stats_per_weekday():
|
||||
@ -97,7 +95,6 @@ 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")
|
||||
|
||||
|
||||
|
||||
async def comment_stats_per_weekday():
|
||||
@ -118,7 +115,6 @@ 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")
|
||||
|
||||
|
||||
|
||||
async def rant_stats_per_hour():
|
||||
@ -139,7 +135,6 @@ 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")
|
||||
|
||||
|
||||
|
||||
async def comment_stats_per_hour():
|
||||
@ -160,7 +155,6 @@ 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")
|
||||
|
||||
|
||||
|
||||
async def score_most_ignored_last_7_days():
|
||||
@ -185,8 +179,7 @@ async def score_most_ignored_last_7_days():
|
||||
plt.savefig(
|
||||
f"export/score_ignored_most_last_7_days_{get_date_range_str()}.png"
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
async def score_last_7_days():
|
||||
with Duration("Upvotes (score) last 7 days"):
|
||||
@ -206,7 +199,6 @@ async def score_last_7_days():
|
||||
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")
|
||||
|
||||
|
||||
|
||||
async def user_score_per_day(username):
|
||||
@ -258,7 +250,6 @@ async def user_score_per_day(username):
|
||||
|
||||
plt.legend()
|
||||
plt.savefig(f"export/score_user_{username}_{get_date_range_str()}.png")
|
||||
|
||||
|
||||
|
||||
def stats():
|
||||
|
@ -31,7 +31,7 @@ async def get_recent_rants(start_from=1, page_size=10):
|
||||
|
||||
def get_rants():
|
||||
return dr.get_rants("recent", page_size, start_from)["rants"]
|
||||
|
||||
|
||||
rants = asyncio.wait_for(loop.run_in_executor(get_rants), 5)
|
||||
|
||||
page += 1
|
||||
@ -46,7 +46,7 @@ async def get_recent_rants(start_from=1, page_size=10):
|
||||
start_from += page_size
|
||||
|
||||
|
||||
async def _sync_rants(start_from, page_size,count):
|
||||
async def _sync_rants(start_from, page_size, count):
|
||||
async for rant in get_recent_rants(start_from, page_size):
|
||||
start_from += page_size
|
||||
count += 1
|
||||
@ -55,6 +55,7 @@ async def _sync_rants(start_from, page_size,count):
|
||||
print(f"Upserted {count} rant(s).")
|
||||
return count
|
||||
|
||||
|
||||
async def sync_rants():
|
||||
count = 0
|
||||
start_from = 0
|
||||
@ -63,11 +64,15 @@ async def sync_rants():
|
||||
|
||||
while True:
|
||||
try:
|
||||
count += await asyncio.wait_for(_sync_rants(start_from, page_size,count),5)
|
||||
count += await asyncio.wait_for(
|
||||
_sync_rants(start_from, page_size, count), 5
|
||||
)
|
||||
start_from += page_size
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
print("If exception described above is an timeout related error, it's due ratelimiting and considered OK.")
|
||||
print(
|
||||
"If exception described above is an timeout related error, it's due ratelimiting and considered OK."
|
||||
)
|
||||
break
|
||||
|
||||
|
||||
@ -76,7 +81,7 @@ async def sync_comments():
|
||||
rants_synced = 0
|
||||
for rant in db["rants"].find(order_by="-id"):
|
||||
rants_synced += 1
|
||||
comments = dr.get_rant(rant["id"]).get("comments",[])
|
||||
comments = dr.get_rant(rant["id"]).get("comments", [])
|
||||
for comment in comments:
|
||||
comments_synced += 1
|
||||
comment["created"] = timestamp_to_string(comment["created_time"])
|
||||
|
Loading…
Reference in New Issue
Block a user