User:IngenuityBot/backlogdrive.py: Difference between revisions

Content deleted Content added
update
update
Line 27:
data = data[key]["revisions"][0]["*"]
 
data = re.findall(r"{{user\|(.+?)}}", data, flags=re.IGNORECASE)
return data[1:]
 
Line 44:
def get_time(timestamp, date_format="%Y-%m-%dT%H:%M:%SZ"):
return datetime.strptime(timestamp, date_format).replace(tzinfo=timezone.utc).timestamp()
 
 
def current_time():
return (
datetime.strftime(datetime.now(timezone.utc), format="%Y%m%d%H%M%S"),
datetime.strftime(datetime.now(timezone.utc), format="%H:%M:%S, %d %B")
)
 
 
Line 71 ⟶ 78:
"age": 0
}
 
edit["comment"] = edit["comment"] if "comment" in edit else ""
 
# check each edit to see if it is a review
Line 79 ⟶ 88:
review["type"] = "reject"
review["reasons"] = get_review_reasons(edit["comment"])
elif re.match(r"Cleaning up accepted.+?\(\[\[WP:AFCH\|AFCH\]\] 0\.9\.1\)", edit["comment"]):
review["type"] = "accept"
 
Line 142 ⟶ 151:
def update_leaderboard(users, participants_page, leaderboard_page, wiki):
# for each user, calculate the total score, statistics, etc.
# also subtract failed re-reviews, and add points for completedinvalid re-reviews
user_statistics = {}
 
Line 153 ⟶ 162:
"rejected": 0,
"failed": 0,
"passed": 0,
"invalid": 0,
"rereviews": 0
}
 
Line 182 ⟶ 193:
 
if age >= 30:
score_to_add += 0.5
if age > 90:
score_to_add += 0.5
Line 201 ⟶ 215:
if review == "pass":
user_statistics[user]["passed"] += 1
 
if review == "invalid":
user_statistics[user]["invalid"] += 1
 
review_user = re.findall(r"\[\[User:([^\|\]]+)", line)
 
if len(review_user) == 0:
continue
 
if review_user[-1] in user_statistics:
user_statistics[review_user[-1]]["rereviews"] += 1
except:
pass
 
user_statistics[user]["score"] = sum(scores)
 
for user in user_statistics:
user_statistics[user]["score"] += user_statistics[user]["rereviews"]
 
# create table with statistics
now = current_time()
table = """{| class="wikitable sortable"
time_ago = "{{time ago|" + now[0] + "}} (" + now[1] + ")"
! Rank !! User !! Score !! Total !! Accepted !! Declined !! Rejected"""
table = "Last updated " + time_ago + "\n{| class=\"wikitable sortable\"\n! Rank !! User !! Score !! Total !! Accepted !! Declined !! Rejected !! Re-reviews completed !! Passed !! Failed !! Invalid"
 
# sort users by score
Line 215 ⟶ 244:
 
for user in user_statistics:
failed = user_statistics[user]["failed"]
if failed == 0:
failed = ""
index += 1
score = user_statistics[user]["score"]
score = int(score) if score == int(score) else score
table += f"""
|-
| {index}
| [[User:{user}|{user}]] ([[User talk:{user}|talk]] • [[{participants_page}/{user}|reviews]])
| {user_statistics[user]["score"]}
| {user_statistics[user]["total"]}
| {user_statistics[user]["accepted"]}
| {user_statistics[user]["declined"]}
| {user_statistics[user]["rejected"]}"""
| {user_statistics[user]["rereviews"]}
| {user_statistics[user]["passed"]}
| {user_statistics[user]["failed"]}
| {user_statistics[user]["invalid"]}"""
 
table += "\n|}"
Line 257 ⟶ 295:
 
metadata["users_fetched"][user] = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
open("metadata.json", "w").write(json.dumps(metadata, indent="\t"))
# update the metadata
Line 262 ⟶ 301:
open("metadata.json", "w").write(json.dumps(metadata, indent="\t"))
 
print("Updating leaderboard...")
update_leaderboard(users, metadata["participants_page"], metadata["leaderboard_page"], site)