Skip to content

Instantly share code, notes, and snippets.

@niflostancu
Created January 15, 2025 13:05
Show Gist options
  • Save niflostancu/efa22505266edf8b712117e88219b250 to your computer and use it in GitHub Desktop.
Save niflostancu/efa22505266edf8b712117e88219b250 to your computer and use it in GitHub Desktop.
import csv
import json
from datetime import date
DEADLINE = date(2023, 12, 10)
class RezultateStudent():
nume = ""
prenume = ""
id_student = ""
punctaj = ""
data_submisie = ""
def __init__(self, student_dict):
self.nume = student_dict["NUME"]
self.prenume = student_dict["Prenume"]
self.id_student = student_dict["ID Student"]
self.punctaj = int(student_dict["Punctaj Tema"])
data = date.fromisoformat(student_dict["Data Submisie"])
self.data_submisie = data
def calc_punctaj(self):
punctaj = self.punctaj
if student.data_submisie > DEADLINE:
punctaj = punctaj * 0.9
return punctaj
def export(self):
return {
"NUME": self.nume,
"Prenume": self.prenume,
"Punctaj": self.punctaj,
"Data Submisie": str(self.data_submisie),
}
student_map = {}
with open("studenti.csv", "r") as csvf:
csv_reader = csv.DictReader(csvf)
for row in csv_reader:
obj = RezultateStudent(row)
student_map[obj.nume] = obj
print(f"Deadline-ul a fost {DEADLINE.__format__("%d.%m.%Y")}")
for nume in student_map:
student = student_map[nume]
print(f"{student.nume} {student.prenume}: {student.calc_punctaj()}")
with open("studenti_salvati.json", "w") as jsonf:
exported_map = {}
for nume, obj in student_map.items():
exported_map[nume] = obj.export()
json.dump(exported_map, jsonf)
stud_cititi = {}
with open("studenti_salvati.json", "r") as jsonf:
stud_cititi = json.load(jsonf)
# print(stud_cititi)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment