Last active
April 25, 2023 17:17
-
-
Save Fimeo/502d50191ff51271a924ec65eb69baf4 to your computer and use it in GitHub Desktop.
ETNA Leader board - Marks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from requests.exceptions import HTTPError | |
import json | |
import logging | |
import numpy as np | |
logging.basicConfig(level=logging.INFO) | |
cookies = { | |
'authenticator': 'jwtToken', | |
} | |
headers = { | |
'Accept': 'application/json, text/plain, */*', | |
'Accept-Language': 'fr', | |
'Origin': 'https://intra.etna-alternance.net', | |
} | |
logging.info("Retrieving current promo") | |
promo = 0 | |
try: | |
response = requests.get('https://intra-api.etna-alternance.net/promo', cookies=cookies, headers=headers) | |
jsonResponse = response.json() | |
promo = jsonResponse[0]["id"] | |
except HTTPError as http_err: | |
print(f'HTTP error occurred: {http_err}') | |
exit(1) | |
except Exception as err: | |
print(f'Other error occurred: {err}') | |
exit(1) | |
logging.info("Retrieving current promo OK") | |
logging.info("Retrieving promo logins") | |
try: | |
response = requests.get('https://intra-api.etna-alternance.net/trombi/' + str(promo), cookies=cookies, headers=headers) | |
jsonResponse = response.json() | |
except HTTPError as http_err: | |
print(f'HTTP error occurred: {http_err}') | |
exit(1) | |
except Exception as err: | |
print(f'Other error occurred: {err}') | |
exit(1) | |
logins = [] | |
for student in jsonResponse["students"]: | |
logins.append(student["login"]) | |
logging.info("Retrieving promo logins OK") | |
logging.info("Retrieving promo marks") | |
marks = {} | |
for login in logins: | |
try: | |
logging.info("Retrieving promo marks for student " + login) | |
response = requests.get('https://intra-api.etna-alternance.net/terms/721/students/'+login+'/marks', | |
cookies=cookies, headers=headers) | |
jsonResponse = response.json() | |
marks[login] = jsonResponse | |
except HTTPError as http_err: | |
print(f'HTTP error occurred: {http_err}') | |
exit(1) | |
except Exception as err: | |
print(f'Other error occurred: {err}') | |
exit(1) | |
logging.info("Retrieving promo marks OK") | |
f = open("marks.json", "w") | |
f.write(json.dumps(marks, indent=4)) | |
f.close() | |
logging.info("Marks available in marks.json") | |
logging.info("Parsing marks") | |
f = open("marks.json", "r") | |
content = f.read() | |
f.close() | |
marksByUV = {} | |
jsonContent = json.loads(content) | |
for login, v in jsonContent.items(): | |
logging.info("Parsing marks of user " + login) | |
for activity in v: | |
uv = activity["uv_name"] | |
mark = activity["student_mark"] | |
if mark is None: | |
continue | |
if login not in marksByUV: | |
marksByUV[login] = {} | |
if uv not in marksByUV[login]: | |
marksByUV[login][uv] = [] | |
if mark < 0: | |
mark = 0 | |
elif mark > 20: | |
mark = 20 | |
marksByUV[login][uv].append({"mark": mark, "coefficient": activity["activity_coefficient"]}) | |
logging.info("Parsing marks OK") | |
logging.info("Generating report") | |
means = {} | |
for user, uv in marksByUV.items(): | |
means[user] = {} | |
for uv_name, marks in uv.items(): | |
notes = [data['mark'] for data in marks] | |
poids = [data['coefficient'] for data in marks] | |
means[user][uv_name] = np.average(notes, weights=poids) | |
means[user]["mean"] = np.average(list(means[user].values())) | |
f = open("means.json", "w") | |
f.write(json.dumps(means, indent=4)) | |
f.close() | |
logging.info("Generating report OK") | |
logging.info("Means available in means.json") | |
logging.warning("Leader board") | |
best = [] | |
for user, mean in means.items(): | |
best.append({"login": user, "mean": mean["mean"]}) | |
print(json.dumps(sorted(best, key=lambda d: d['mean'], reverse=True), indent=4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Current promo marks and leaderboard
Mean of each UE
Each UE has ponderated activities
How to use: login and retrieve the cookie, paste the value in
authenticator
variable and runpython3 mark.py