-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.py
More file actions
217 lines (158 loc) · 8.54 KB
/
student.py
File metadata and controls
217 lines (158 loc) · 8.54 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/env python3
import csv
import sys
class Student:
roster = [] #list of not matched student
tandems = []
languages = set()
def __init__(self, row):
self.name = row[1].strip()
self.surname = row[2].strip()
self.email = row[3].strip()
self.nationality = row[4].strip()
self.known_lang = row[5]
self.wanted_lang = row[6]
self.age = row[7].strip()
self.gender = row[8].strip()
self.university = row[9].strip()
self.avail = row[10]
self.partner = None
self._roster_uptodate = False
self._viable_tandems = None
# remove duplicate
exist = False
for other in Student.roster:
if not exist and (self.name.lower() == other.name.lower() and self.surname.lower() == other.surname.lower()) or self.email.lower() == other.email.lower():
print(other)
print(self)
ans = input('Est-ce que ce sont les mêmes personnes ? [O/n] ')
if ans.lower() == 'n':
print('Réponse prise en compte. Ce sont deux participants différents.\n')
else:
print('Copie effacé !\n')
exist = True
if not exist: other._roster_uptodate = False
if not exist:
Student.roster.append(self)
for lang in self.list_known + self.list_wanted:
Student.languages.add(lang)
@property
def list_known(self):
return [lang.strip() for lang in self.known_lang.split(',')]
@property
def list_wanted(self):
return [lang.strip() for lang in self.wanted_lang.split(',')]
@property
def viable_tandems(self):
if self._roster_uptodate:
return self._viable_tandems
self._roster_uptodate = True
self._viable_tandems = []
for other in Student.roster:
if id(other) != id(self) and\
set(other.list_known).intersection(self.list_wanted) and\
set(other.list_wanted).intersection(self.list_known):
self._viable_tandems.append(other)
return self._viable_tandems
@property
def gen_email(self):
if self.partner:
return '''************************************************************************************************
************************************************************************************************
mail à envoyer à {0.surname} {0.name} : {0.email}
Bonjour {0.surname},
L'association IntEGre te contacte suite à ton inscription à notre programme Tandem.
Nous avons le plaisir de t'annoncer qu'un tandem t'a été attribué : {1.surname} {1.name}
Ses langues parlées couramment sont : {1.known_lang}.
Voici son adresse mail, tu peux dès à présent le contacter : {1.email}
Néanmoins si tu rencontres le moindre problème n'hésite pas à nous recontacter.
Vous pouvez vous donner rendez-vous de façon hebdomadaire et dès le Lundi 29 janvier 2018 à partir de 18h00 à EVE au cours de nos Cafés-Tandem !
Tu peux retrouver toutes les informations sur l'événement en cliquant sur le lien suivant : http://bit.ly/LAssociationIntEGre
Merci d'accuser réception de ce message.
Cordialement,
-------------------------------------------------------------------------------------------------------------------------
Hi {0.surname}
IntEGre is contacting you about your subscription to our Tandem program.
We are pleased to inform you that a tandem is now assigned to you : {1.surname} {1.name} , whose languages fluently spoken are : {1.known_lang}
Here is his email: {1.email}
However if you have any problem you can contact us.
You can meet your tandem every week on Mondays, starting January 29, 2018, from 6pm at EVE during our Cafes-Tandem events !
You can find all the information about the event clicking on the following link : http://bit.ly/LAssociationIntEGre
Kind regards
L'Association IntEGre.
'''.format(self, self.partner)
else:
return '''************************************************************************************************
************************************************************************************************
mail à envoyer à {0.surname} {0.name} : {0.email}
Bonjour {0.surname},
L'association IntEGre te contacte suite à ton inscription à notre programme de tandem.
Nous sommes désolés de t'annoncer que nous n’avons pas pu t’attribuer de tandem pour le moment.
Cependant, nous vous gardons dans le programme dans l'espoir qu'un profil compatible s'inscrive prochainement.
D'ici là, nous te donnons rendez vous dès le Lundi 29 janvier 2018 à partir de 18h00 à EVE pour nos Cafés-Tandem hebdomadaires ! Tu auras l’occasion de rencontrer d’autres personnes dans ton cas et pourquoi pas un futur tandem !
Tu peux retrouver toutes les informations sur l'événement en cliquant sur le lien suivant : http://bit.ly/LAssociationIntEGre
En espérant que tu trouves un tandem bientôt,
Cordialement,
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hi {0.surname},
IntEGre is contacting you about your subscription to our Tandem program.
We are sorry to inform you that we haven’t been able to assign a tandem to you yet.
However, we keep you in our Tandem program until we find a matching profile, hopefully very soon.
Meanwhile, we invite you to join us on Mondays, starting January 29, 2018, from 6.00pm at EVE for our weekly Cafes-Tandem events, where you will meet other students in your situation, and maybe find a tandem there !
You can find all the information about the event clicking on the following link : http://bit.ly/LAssociationIntEGre
Kind regards
L'Association IntEGre
'''.format(self)
def __str__(self):
"""define str(student), e.g. print(student)"""
return 'Nom: {name} Prenom: {surname} Addresse Mail: {email} Nation: {nationality} Langues connues: {known_lang} Langues cherchées: {wanted_lang} Age: {age} Sexe: {gender} Universite: {university} Date de première disponibilité: {avail}'.format_map(self.__dict__)
def pair_with(self, other):
for student in Student.roster:
student._roster_uptodate = False
if not self.partner and other in Student.roster:
Student.tandems.append((self, other))
self.partner = other
other.partner = self
Student.roster.remove(self)
Student.roster.remove(other)
@classmethod
def load(cls, filename, legacy=False):
"""load a csv into a list of students"""
with open(filename) as f:
reader = csv.reader(f)
if not legacy: # discard the first line
next(reader)
for row in reader:
cls(row)
@classmethod
def to_str(cls):
strs = []
for student in sorted(cls.roster, key=lambda x: x.name.lower()):
strs.append(str(student))
return '\r\n\r\n'.join(strs)
if __name__ == '__main__':
legacy = False
if len(sys.argv) > 1:
if sys.argv[1].lower() == '-l' or sys.argv[1].lower() == '--legacy':
legacy = True
with open('log.txt', 'w') as log:
Student.load(input('Quel est le nom du fichier à charger ? '), legacy)
print(Student.to_str(), file=log)
print('Il y a {} langues en total.'.format(len(Student.languages)))
print('', file=log)
for lang in Student.languages:
print(lang, file=log)
nb_stud = len(Student.roster)
for s in sorted(Student.roster, key=lambda x: len(x.viable_tandems)):
if not s.partner and s.viable_tandems:
s.pair_with(s.viable_tandems[0])
print('{} tandems et {} étudiants seuls (sur {}).'.format(len(Student.tandems), len(Student.roster), nb_stud))
print("\n{} éudiants n'ont pas de tandem :".format(len(Student.roster)), file=log)
with open('email.txt', 'w') as email:
for alone in Student.roster:
print(alone.gen_email, file=email)
print(alone.surname, alone.name, file=log)
for tandem in Student.tandems:
print(tandem[0].gen_email, file=email)
print(tandem[1].gen_email, file=email)
input()