-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
124 lines (105 loc) · 4.17 KB
/
Copy pathutils.py
File metadata and controls
124 lines (105 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import csv
def lire_csv(fichier):
"""Read a CSV file and return its content as a list of lists."""
tableau = []
try:
with open(fichier, "r", encoding="utf-8") as f:
lecteur = csv.reader(f, delimiter=",")
for ligne in lecteur:
tableau.append(ligne)
return tableau
except FileNotFoundError:
print(f"Erreur : le fichier {fichier} n'existe pas.")
return []
def ecrire_csv(fichier, data):
"""Write data (list of lists) to a CSV file."""
try:
with open(fichier, "w", newline='', encoding="utf-8") as f:
ecrivain = csv.writer(f, delimiter=",")
for ligne in data:
ecrivain.writerow(ligne)
except Exception as e:
print(f"Erreur lors de l'écriture dans le fichier {fichier} : {e}")
def is_numeric_column(tableau, col_index):
"""Check if a column in the table is numeric."""
if col_index == 0:
return False # Ignorer la première colonne
numeric_count = 0
for row in tableau[1:]:
if col_index < len(row) and row[col_index].strip(): # ignorer les cellules vides
try:
float(row[col_index])
numeric_count += 1
except ValueError:
return False # Si une valeur n'est pas numérique, la colonne ne l'est pas
return numeric_count > 0 # Au moins une valeur numérique trouvée
def find_index(header, subject_name):
"""Find the index of a subject in the header row."""
for subject_index in range(6, len(header)):
if header[subject_index] == subject_name:
return subject_index
return -1
def get_course_name(index):
"""Get the course name based on its index."""
course_names = [
"Arithmancy", "Astronomy", "Herbology", "Defense Against the Dark Arts",
"Divination", "Muggle Studies", "Ancient Runes", "History of Magic",
"Transfiguration", "Potions", "Care of Magical Creatures", "Charms",
"Flying"
]
if 0 <= index < len(course_names):
return course_names[index]
return "Unknown Course"
def get_houses(all_students, index_course):
"""Get the grades for each house in a specific course."""
# Recuperer les notes
gryffindor_origin = []
slytherin_origin = []
hufflepuff_origin = []
ravenclaw_origin = []
for student in all_students:
house = student[1]
note = student[index_course + 6]
if note:
try:
if house == "Gryffindor":
gryffindor_origin.append(float(note))
elif house == "Slytherin":
slytherin_origin.append(float(note))
elif house == "Hufflepuff":
hufflepuff_origin.append(float(note))
elif house == "Ravenclaw":
ravenclaw_origin.append(float(note))
except ValueError:
pass
return gryffindor_origin, slytherin_origin, hufflepuff_origin, ravenclaw_origin
def get_house_xy(all_students, index1, index2):
"""Get the grades for each house in two specific courses."""
# Recuperer les notes des matieres pour le scatter plot par maison
x_gryff, y_gryff = [], []
x_huff, y_huff = [], []
x_raven, y_raven = [], []
x_slyth, y_slyth = [], []
for student in all_students[1:]:
note1 = student[index1]
note2 = student[index2]
house = student[1]
if note1 and note2:
try:
score1 = float(note1)
score2 = float(note2)
if house == 'Gryffindor':
x_gryff.append(score1)
y_gryff.append(score2)
elif house == 'Hufflepuff':
x_huff.append(score1)
y_huff.append(score2)
elif house == 'Ravenclaw':
x_raven.append(score1)
y_raven.append(score2)
elif house == 'Slytherin':
x_slyth.append(score1)
y_slyth.append(score2)
except ValueError:
pass
return x_gryff, y_gryff, x_huff, y_huff, x_raven, y_raven, x_slyth, y_slyth