This commit is contained in:
parent
f780447eb1
commit
518b9534ba
@ -1,9 +1,9 @@
|
||||
from PIL import Image
|
||||
from pathlib import Path
|
||||
import functools
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import functools
|
||||
import sys
|
||||
|
||||
printr = functools.partial(print,file=sys.stderr)
|
||||
printr = functools.partial(print, file=sys.stderr)
|
||||
|
||||
per_image_width = 480
|
||||
per_image_height = 320
|
||||
@ -11,19 +11,23 @@ cols = 2
|
||||
|
||||
images = list(Path("./export/").glob("*.png"))
|
||||
image_count = len(images)
|
||||
total_image_height = (image_count / cols * per_image_height)
|
||||
if(image_count / cols * per_image_height > total_image_height):
|
||||
total_image_height = image_count / cols * per_image_height
|
||||
if image_count / cols * per_image_height > total_image_height:
|
||||
total_image_height += per_image_height
|
||||
total_image_width = image_count / cols * per_image_width
|
||||
total_image_width = image_count / cols * per_image_width
|
||||
|
||||
resized_images = []
|
||||
|
||||
for path in images:
|
||||
image = Image.open(path)
|
||||
image = image.resize((per_image_width, per_image_height))
|
||||
resized_images.append((path,image))
|
||||
resized_images.append((path, image))
|
||||
|
||||
new_image = Image.new("RGB",(per_image_width * cols, int(per_image_height * image_count / cols)), (250,250,250))
|
||||
new_image = Image.new(
|
||||
"RGB",
|
||||
(per_image_width * cols, int(per_image_height * image_count / cols)),
|
||||
(250, 250, 250),
|
||||
)
|
||||
|
||||
current_col = 0
|
||||
current_row = 0
|
||||
@ -32,8 +36,8 @@ for path, image in resized_images:
|
||||
printr("Merging image {}".format(path))
|
||||
current_row = int(current_image_number / cols)
|
||||
left = int((current_col) * per_image_width)
|
||||
top = int(per_image_height * current_row )
|
||||
new_image.paste(image,(left,top))
|
||||
top = int(per_image_height * current_row)
|
||||
new_image.paste(image, (left, top))
|
||||
new_image.save("export/1_graphs_compliation.png")
|
||||
|
||||
current_col += 1
|
||||
@ -41,4 +45,4 @@ for path, image in resized_images:
|
||||
if current_col == cols:
|
||||
current_col = 0
|
||||
|
||||
new_image.show()
|
||||
new_image.show()
|
||||
|
@ -1,8 +1,9 @@
|
||||
from drstats import db
|
||||
import functools
|
||||
import sys
|
||||
import functools
|
||||
import sys
|
||||
|
||||
printr = functools.partial(print, file=sys.stderr)
|
||||
|
||||
printr = functools.partial(print,file=sys.stderr)
|
||||
|
||||
def dump():
|
||||
statistics_text = [
|
||||
@ -13,23 +14,33 @@ def dump():
|
||||
printr(statistics_text)
|
||||
for contribution in db.get_contributions():
|
||||
statistics_text.append(
|
||||
f"Statistics: User(ranter) {contribution['username']} made {contribution['contributions']} contributions to devRant(developer community) what means {contribution['username']} owns {contribution['ownership']} percent of contributions on devRant(developer community). The avarage post length of {contribution['username']} is {contribution['post_length_average']} and total post length is {contribution['post_length_total']}. {contribution['username']} owns {contribution['ownership_content']} percent of content on devRant(developer community)."
|
||||
f"Statistics: User(ranter) {contribution['username']} made {contribution['contributions']} contributions to devRant(developer community) what means {contribution['username']} owns {contribution['ownership']} percent of contributions on devRant(developer community). The avarage post length of {contribution['username']} is {contribution['post_length_average']} and total post length is {contribution['post_length_total']}. {contribution['username']} owns {contribution['ownership_content']} percent of content on devRant(developer community)."
|
||||
)
|
||||
printr(statistics_text[-1])
|
||||
print("\n".join(statistics_text))
|
||||
all_content = ''
|
||||
all_content = ""
|
||||
for user in db.get_users():
|
||||
text = db.get_all_rants_of_user(user).replace("\n"," ").replace(" "," ").strip()
|
||||
text = (
|
||||
db.get_all_rants_of_user(user).replace("\n", " ").replace(" ", " ").strip()
|
||||
)
|
||||
total_text = ""
|
||||
if text:
|
||||
total_text += text
|
||||
print("```",f"All rants written by user(ranter) `{user}` on devRant(developer community)```.")
|
||||
print(text,"```")
|
||||
text = db.get_all_posts_of_user(user).replace("\n", " ").replace(" "," ").strip()
|
||||
print(
|
||||
"```",
|
||||
f"All rants written by user(ranter) `{user}` on devRant(developer community)```.",
|
||||
)
|
||||
print(text, "```")
|
||||
text = (
|
||||
db.get_all_posts_of_user(user).replace("\n", " ").replace(" ", " ").strip()
|
||||
)
|
||||
if text:
|
||||
total_text += text
|
||||
print("```",f"All posts written by user(ranter) `{user}` on devRant(developer community): ```.")
|
||||
print(text,"```")
|
||||
total_text += text
|
||||
print(
|
||||
"```",
|
||||
f"All posts written by user(ranter) `{user}` on devRant(developer community): ```.",
|
||||
)
|
||||
print(text, "```")
|
||||
all_content += total_text
|
||||
|
||||
for user in db.get_users():
|
||||
@ -37,6 +48,3 @@ def dump():
|
||||
line = f"{user} is {all_content.count(mention_text)} times mentioned on devRant(developer comminity)."
|
||||
printr(line)
|
||||
print(line)
|
||||
|
||||
|
||||
|
||||
|
@ -33,7 +33,7 @@ class Devrant:
|
||||
url = self.API + "devrant/search"
|
||||
params = {"app": 3, "term": term}
|
||||
|
||||
r = requests.get(url, params,timeout=5)
|
||||
r = requests.get(url, params, timeout=5)
|
||||
obj = json.loads(r.text)
|
||||
return obj
|
||||
|
||||
@ -52,7 +52,7 @@ class Devrant:
|
||||
params = {
|
||||
"app": 3,
|
||||
}
|
||||
r = requests.get(url, params,timeout=5)
|
||||
r = requests.get(url, params, timeout=5)
|
||||
obj = json.loads(r.text)
|
||||
return obj
|
||||
|
||||
@ -65,7 +65,7 @@ class Devrant:
|
||||
url = self.API + "devrant/rants"
|
||||
params = {"app": 3, "sort": sort, "limit": limit, "skip": skip}
|
||||
|
||||
r = requests.get(url, params,timeout=5)
|
||||
r = requests.get(url, params, timeout=5)
|
||||
obj = json.loads(r.text)
|
||||
return obj
|
||||
|
||||
@ -80,4 +80,4 @@ class Devrant:
|
||||
|
||||
r = requests.get(url, params)
|
||||
obj = json.loads(r.text)
|
||||
return obj
|
||||
return obj
|
||||
|
@ -1,17 +1,18 @@
|
||||
import time
|
||||
import sys
|
||||
import time
|
||||
import sys
|
||||
|
||||
|
||||
class Duration:
|
||||
|
||||
def __init__(self, description):
|
||||
self.description = description
|
||||
self.description = description
|
||||
|
||||
def __enter__(self):
|
||||
self.start = time.time()
|
||||
return self
|
||||
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.end = time.time()
|
||||
self.duration = self.end - self.start
|
||||
print(self.description,end=" ",file=sys.stderr)
|
||||
print("took {} seconds.".format(self.duration),file=sys.stderr)
|
||||
print(self.description, end=" ", file=sys.stderr)
|
||||
print("took {} seconds.".format(self.duration), file=sys.stderr)
|
||||
|
@ -1,7 +1,7 @@
|
||||
from drstats.db import get_db, Db,get_users
|
||||
from drstats.db import get_db, Db, get_users
|
||||
from drstats import sync
|
||||
import asyncio
|
||||
from drstats.duration import Duration
|
||||
from drstats.duration import Duration
|
||||
|
||||
from time import sleep
|
||||
import importlib
|
||||
@ -67,8 +67,8 @@ async def rant_stats_per_day():
|
||||
|
||||
|
||||
async def comment_stats_per_day():
|
||||
with Duration("Comment stats per day"):
|
||||
|
||||
with Duration("Comment stats per day"):
|
||||
|
||||
plt = figure_inc()
|
||||
async with Db() as db:
|
||||
x = []
|
||||
@ -188,7 +188,9 @@ async def score_most_ignored_last_7_days():
|
||||
x = []
|
||||
y = []
|
||||
|
||||
for record in db.query("SELECT * FROM score_ignored_most_last_7_days LIMIT 15"):
|
||||
for record in db.query(
|
||||
"SELECT * FROM score_ignored_most_last_7_days LIMIT 15"
|
||||
):
|
||||
x.append(record["username"])
|
||||
y.append(record["userscore"])
|
||||
|
||||
@ -199,7 +201,9 @@ async def score_most_ignored_last_7_days():
|
||||
plt.ylabel("Times ignored")
|
||||
plt.title("Most ignored based on score regarding last 7 days")
|
||||
plt.legend()
|
||||
plt.savefig(f"export/score_ignored_most_last_7_days_{get_date_range_str()}.png")
|
||||
plt.savefig(
|
||||
f"export/score_ignored_most_last_7_days_{get_date_range_str()}.png"
|
||||
)
|
||||
plt_reset()
|
||||
# plt.show()
|
||||
|
||||
@ -226,43 +230,52 @@ async def score_last_7_days():
|
||||
plt_reset()
|
||||
# plt.show()
|
||||
|
||||
|
||||
async def user_score_per_day(username):
|
||||
with Duration("User {} score per day".format(username)):
|
||||
plt = figure_inc()
|
||||
plt = figure_inc()
|
||||
async with Db() as db:
|
||||
|
||||
plt.xticks(rotation=45)
|
||||
plt.title(f"{username}'s score per day")
|
||||
plt.xlabel("Date")
|
||||
plt.ylabel("Score")
|
||||
|
||||
|
||||
x = []
|
||||
y = []
|
||||
|
||||
for record in db.query("SELECT * FROM user_stats WHERE username = '{}'".format(username)):
|
||||
for record in db.query(
|
||||
"SELECT * FROM user_stats WHERE username = '{}'".format(username)
|
||||
):
|
||||
x.append(record["date"])
|
||||
y.append(record["post_count"])
|
||||
y.append(record["post_count"])
|
||||
plt.plot(x, y, label="Posts")
|
||||
|
||||
x = []
|
||||
y = []
|
||||
for record in db.query("SELECT * FROM user_stats WHERE username = '{}'".format(username)):
|
||||
for record in db.query(
|
||||
"SELECT * FROM user_stats WHERE username = '{}'".format(username)
|
||||
):
|
||||
x.append(record["date"])
|
||||
y.append(record["ignore_count"])
|
||||
y.append(record["ignore_count"])
|
||||
plt.plot(x, y, label="Times ignored")
|
||||
|
||||
x = []
|
||||
y = []
|
||||
for record in db.query("SELECT * FROM user_stats WHERE username = '{}'".format(username)):
|
||||
for record in db.query(
|
||||
"SELECT * FROM user_stats WHERE username = '{}'".format(username)
|
||||
):
|
||||
x.append(record["date"])
|
||||
y.append(record["upvote_times"])
|
||||
y.append(record["upvote_times"])
|
||||
plt.plot(x, y, label="Times upvoted")
|
||||
|
||||
x = []
|
||||
y = []
|
||||
for record in db.query("SELECT * FROM user_stats WHERE username = '{}'".format(username)):
|
||||
for record in db.query(
|
||||
"SELECT * FROM user_stats WHERE username = '{}'".format(username)
|
||||
):
|
||||
x.append(record["date"])
|
||||
y.append(record["upvote_total"])
|
||||
y.append(record["upvote_total"])
|
||||
plt.plot(x, y, label="Sum upvotes")
|
||||
|
||||
plt.legend()
|
||||
@ -284,7 +297,3 @@ def rant_stats_all():
|
||||
asyncio.run(score_last_7_days())
|
||||
for user in get_users():
|
||||
asyncio.run(user_score_per_day(user))
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -4,6 +4,7 @@ import json
|
||||
import asyncio
|
||||
from pprint import pprint as pp
|
||||
import requests
|
||||
|
||||
dr = Devrant()
|
||||
db = get_db()
|
||||
|
||||
@ -37,10 +38,11 @@ async def get_recent_rants(start_from=1, page_size=10):
|
||||
|
||||
yield rant
|
||||
start_from += page_size
|
||||
|
||||
|
||||
|
||||
async def sync_rants():
|
||||
count = 0
|
||||
start_from = 0
|
||||
start_from = 0
|
||||
|
||||
page_size = 20
|
||||
|
||||
@ -52,7 +54,8 @@ async def sync_rants():
|
||||
db["rants"].upsert(rant, ["id"])
|
||||
print(f"Upserted {count} rant(s).")
|
||||
except:
|
||||
print("Rate limit of server exceeded. That's normal.s")
|
||||
print("Rate limit of server exceeded. That's normal.s")
|
||||
|
||||
|
||||
async def sync_comments():
|
||||
comments_synced = 0
|
||||
|
Loading…
Reference in New Issue
Block a user