feat: prettier grades calculation
This commit is contained in:
@@ -6,8 +6,11 @@ import pandas as pd
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
import asyncio
|
import asyncio
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
CORONANG_VERSION='v1.8.00'
|
CORONANG_VERSION='v1.8.00'
|
||||||
Selection = Enum('Selection', ['TREE_WALK', 'TREE_LEAF', 'ITEM_SELECTED'])
|
Selection = Enum('Selection', ['TREE_WALK', 'TREE_LEAF', 'ITEM_SELECTED'])
|
||||||
|
|
||||||
@@ -32,8 +35,11 @@ async def run_playwright(headless: bool):
|
|||||||
@click.option('--username','-u')
|
@click.option('--username','-u')
|
||||||
@click.option('--password','-p')
|
@click.option('--password','-p')
|
||||||
@click.option('--headful', is_flag=True, help='Show the browser window')
|
@click.option('--headful', is_flag=True, help='Show the browser window')
|
||||||
|
@click.option('--debug', '-d', is_flag=True, help='Set the log level to DEBUG')
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
async def cli(ctx, username, password, headful):
|
async def cli(ctx, username, password, headful, debug):
|
||||||
|
logging.basicConfig(level=logging.ERROR,format='%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
if(debug): logger.setLevel(logging.DEBUG)
|
||||||
ctx.ensure_object(dict)
|
ctx.ensure_object(dict)
|
||||||
if ctx.invoked_subcommand != 'grades':
|
if ctx.invoked_subcommand != 'grades':
|
||||||
ctx.obj['USERNAME'] = username or await questionary.text('Enter your kiz username:').ask_async()
|
ctx.obj['USERNAME'] = username or await questionary.text('Enter your kiz username:').ask_async()
|
||||||
@@ -76,27 +82,27 @@ async def coronang(ctx):
|
|||||||
await page.reload()
|
await page.reload()
|
||||||
click.echo("Finished coronang.")
|
click.echo("Finished coronang.")
|
||||||
|
|
||||||
@cli.command(help='Calculate your weighted grade from a CSV using the best n ECTS')
|
@cli.command(help='''Calculate your weighted grade using the best n credits. Expects a csv with the columns name, grade, credits''')
|
||||||
@click.argument('filename', type=click.Path(exists=True))
|
@click.argument('filename', type=click.Path(exists=True))
|
||||||
@click.option('--target_lp', '-t', type=int, default=74, help='Target number of n ECTS needed')
|
@click.option('--target_lp', '-t', type=int, default=74, help='Target number of n credits needed')
|
||||||
def grades(filename, target_lp:int):
|
def grades(filename, target_lp:int):
|
||||||
data = pd.read_csv(filename)
|
data = pd.read_csv(filename)
|
||||||
data.sort_values(by='note', inplace=True)
|
data.sort_values(by='grade', inplace=True)
|
||||||
|
|
||||||
acc_note: float = 0.0
|
acc_note: float = 0.0
|
||||||
acc_lp = 0
|
acc_lp = 0
|
||||||
# the use of iterrows and all iteration over dataframes is discouraged for performance reasons
|
# the use of iterrows and all iteration over dataframes is discouraged for performance reasons
|
||||||
for _ , row in data.iterrows():
|
for _ , row in data.iterrows():
|
||||||
if acc_lp + row['lp'] < target_lp:
|
if acc_lp + row['credits'] < target_lp:
|
||||||
acc_lp += row['lp']
|
weight = row['credits']
|
||||||
acc_note: float = acc_note + row['lp'] * row['note']
|
|
||||||
else:
|
else:
|
||||||
weight = target_lp - acc_lp
|
weight = target_lp - acc_lp
|
||||||
acc_lp += weight
|
|
||||||
acc_note = acc_note + weight * row['note']
|
|
||||||
break
|
break
|
||||||
|
acc_lp += weight
|
||||||
|
acc_note = acc_note + weight * row['grade']
|
||||||
|
logger.debug('Added "%s" with %d/%d credits and grade %.1f', row['name'], weight, row['credits'], row['grade'])
|
||||||
acc_note: float = acc_note / acc_lp
|
acc_note: float = acc_note / acc_lp
|
||||||
print(acc_note)
|
print(f'Final Grade: {acc_note}')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(cli.main())
|
asyncio.run(cli.main())
|
||||||
Reference in New Issue
Block a user