import pandas as pd
import pprint
import sys 
sys.path.append('../learnlytics/')
from dbmodel import *

df = pd.read_csv("Student_list.csv")
df = df.dropna()
courses = {
        'Tutorial 1': 31,
        'Tutorial 2': 15,
        'Extended Applications': 18,
        'Numpy & MatPlotLib': 35,
        'SciPy': 20,
        'Monte Carlo': 20,
        'Pandas & Seaborn': 22,
        'Folium': 27,
        'Statistical Test Methods': 24,
        'Data Analysis': 30
    }

groups = {
    "NoGroup": "No Project",
    "MeWi1": "Covid-19",
    "MeWi2": "Covid-19",
    "MeWi3": "Discovery of Handwashing",
    "MeWi4": "Uber Trips",
    "MeWi5": "Extramarital Affairs",
    "MeWi6": "Hochschulstatistik",
    "DiKum": "Facebook Data"
}

print(df)
init_db('WiSe_24_25.db')


# Create Class
clas = Class.create(name='WiSe 24/25')
#print(clas.id)

# Create Courses
for k, v in courses.items():
    Lecture.create(title=k, points=v, class_id=clas.id)
    #print(l.title, l.points, l.class_id, l.id)

for k, v in groups.items():
    Group.create(name=k, project=v, has_passed=True, class_id=clas.id)

for index, row in df.iterrows():
    s = Student.create(
        prename=row["First Name"],
        surname=row["Last Name"],
        sex=row["Sex"],
        class_id=clas.id,
        group_id=Group.select().where(Group.name == row["Group"]),
        grader=row["Grader"],
    )
    
    for title, points in list(row.to_dict().items())[5:]:
        Submission.create(
            student_id=s.id,
            lecture_id=Lecture.select().where(Lecture.title == title),
            class_id=clas.id,
            points=points
        )
 

