Created
July 17, 2017 15:56
-
-
Save freddie-freeloader/da7324305864e91c9d59c2096f3dff41 to your computer and use it in GitHub Desktop.
Not at all finished moodle point scraper
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 pandas as pd | |
import argparse | |
# Example: printStuff('blub.html') | |
# Where 'blub.html' is downloaded from Moodle | |
def printStuff(fileName): | |
table = pd.read_html(fileName)[0] | |
res = table[1:-2][['Bereich', 'Prozentsatz']] | |
res['Bereich'] = res['Bereich'].apply(lambda x: int(x[2:])) | |
res['Prozentsatz'] = res['Prozentsatz'].apply(lambda x: float(x.replace(',','.')[:-2])) | |
weights = res['Bereich'] | |
scores = res['Prozentsatz'] | |
print("\nScore in percent with worst assignment:") | |
print(sum(weights*scores)/sum(weights)) | |
minimumId = res['Prozentsatz'].idxmin() | |
bad_df = res.index.isin([minimumId]) | |
res = res[-bad_df] | |
weights = res['Bereich'] | |
scores = res['Prozentsatz'] | |
print("\nScore in percent without worst assignment:") | |
print(sum(weights*scores)/sum(weights)) | |
# Calculate needed points | |
last_weight = int(table['Bereich'][12][2:]) | |
# Im System sind noch die Bonuspunkte eingerechnet | |
last_weight = last_weight - 5 | |
print("\nNeeded points (last assignment): ") | |
print(((90*(sum(weights)+last_weight) - sum(weights*scores))/last_weight) | |
* last_weight / 100) | |
parser = argparse.ArgumentParser() | |
parser.add_argument("fileName", help="Path to html-File") | |
args = parser.parse_args() | |
printStuff(args.fileName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment