Last active
January 26, 2023 10:58
-
-
Save eniehack/f3aff92cff4ee86a7c1ba337073b8869 to your computer and use it in GitHub Desktop.
TWINSで生成されたCSVからGPAを計算するツール。klis用。CC0でライセンスします
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
# SPDX-License-Identifier: CC0-1.0 | |
import csv | |
import math | |
import argparse | |
parser = argparse.ArgumentParser( | |
prog="GPA Calculator", | |
description="calculates GPA from csv which is generated by TWINS.", | |
) | |
parser.add_argument("filename") | |
args = parser.parse_args() | |
units = 0.0 | |
weighted_units = 0.0 | |
content = [] | |
with open(args.filename, encoding="utf-8") as f: | |
reader = csv.reader(f) | |
content = [row for row in reader] | |
content = content[1:] | |
for row in content: | |
if row[2] == "" or row[7] == "履修中" or row[7] == "P" or row[7] == "F": | |
continue | |
units += float(row[4]) | |
if row[7] == "A+": | |
weighted_units += 4.3 * float(row[4]) | |
elif row[7] == "A": | |
weighted_units += 4.0 * float(row[4]) | |
elif row[7] == "B": | |
weighted_units += 3.0 * float(row[4]) | |
elif row[7] == "C": | |
weighted_units += 2.0 * float(row[4]) | |
gpa = weighted_units / units | |
print(math.floor(gpa * 10 ** 2) / (10 ** 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment