-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
210 lines (156 loc) · 6.12 KB
/
main.py
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
import argparse
import pdb
import input
import output
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--file", help="""name of file can be 'a' or 'b' or 'c' or 'd' or 'e'""")
return parser.parse_args()
class Colaborateur:#N collaborators(Contributors)
def __init__(self, name, skills):
self.name = name
#skills: {skill_name:level}
self.skills = skills
#self.projects
self.assigned = False
# if the assigned is true maybe add the project name
# to see in which proj he's working
self.project_name = ""
class Projet:#M projects
def __init__(self, name, days, score, best_before, roles, level_roles):
self.name = name
#days aka duration
self.days = days
self.score = score
self.best_before = best_before
# {role:min_level}
# role c'est la techno!!
self.roles = roles
# assigned_to {role:, role2{}}
self.asigned_to = {}
self.level_roles = level_roles
self.list_skills_requirement = []
def can_fill_role(self, colaborator):
pass
# check si collab a minimumu skills
def exist_mentor(self, colaborator, role):
"""check if a mentor exists for a collaborator."""
pass
# parcourir list des gens faisant partie du projet
# check si parmi eux il y'a quelqu'un qui
# a le role demandé au niveau minimum
# dans ce cas le colaborateur peut etre assigne avec
# mentor
def main():
args = parse_arguments()
if args.file not in ('a','b','c','d','e','f'):
raise ValueError("argument file (-f) must be equal to 'a' or 'b' or 'c' or 'd' or 'e'")
# rest of the code
# read file
content = input.read_file(input.path_files[args.file])
# separate the first line
first_line, content = input.separate_first_line(content)
# get the content from the first line
C, P = input.split_first_line(first_line)
lines = content.split("\n")
# get contribs
contributors = []
i = 0
for _ in range(C):
name, nb_skils = lines[i].split(' ')
nb_skils = int(nb_skils)
i+=1
skills = {}
for _ in range(nb_skils):
skill, level = lines[i].split(' ')
skills[skill] = int(level)
i+=1
contributors.append(Colaborateur(name, skills))
projects = []
# get projects
for _ in range(P):
name, D, S, B, R = lines[i].split(' ')
# R,D,S,B = map(lambda x:int(x),[R,D,S,B])
R = int(R)
D = int(D)
S = int(S)
B = int(B)
i+=1
roles = []
roles_level = {}
for _ in range(R):
role, level = lines[i].split(' ')
i+=1
roles.append(role)
roles_level[role] = int(level)
projects.append(Projet(name, D, S, B, roles, roles_level ))
# represent data
# solution
to_do_projects = solution1(projects, contributors)
# output
output.write_file(args.file, to_do_projects)
# i do prefer using a bunch of other functions and call them from here,
# that way we will manage the "cas par cas" thing that you talked about
def solution1(projects, collaborateurs):
"""Solution for the input 1."""
# nous voullons parcourir chaque projet
# et check si on a les candidats nécessaire
# pour qu'on puisse demarrer le truc
to_do_projects = []
for project in projects:
project_roles = {}
project_doable = True
for role in project.roles:
found = False
for collaborateur in collaborateurs:
# collaborateur can't work on more then 1 (role)tech on a project
if not collaborateur.assigned and role in collaborateur.skills:
if collaborateur.skills[role] >= project.level_roles[role]:
found = True
collaborateur.assigned = True
break
if found:
project_roles[role] = collaborateur
else:
# this means that the project can't be asigned
project_doable = False
# ignore project
for asigned_role in project_roles:
project_roles[asigned_role].assigned = False
break
if project_doable:
#ajouterasigned_toe des doua
project.asigned_to = project_roles
to_do_projects.append(project)
return to_do_projects
def solution2():
"""autre solution."""
def project_fulfillable(project_candidats):
"""
project_candidats : dic
{role: [list,candidat], role: [list, candidats] }
"""
for role in project_candidats:
if len(role)==0:
return False
return True
# list candidats pour chaque projet
# PS: plusieurs candidat pour le meme role, osef on met tout!
# {project_name : {role: [list,candidat], role: [list, candidats] },
# project_name2: {role: [list,candidat], role: [list, candidats] }
# }
projet_candidats = {}
# NO NEED to_do_projects = []
for project in projects:
projet_candidats[project.name] = {}
for role in project.roles:
projet_candidats[project.name][role] = []
for collaborateur in collaborateurs:
if role in collaborateur.skills:
# on prend pas en compte le mentorship
if collaborateur.skills[role] >= project.level_roles[role]:
# ajouter a la liste des collabo
projet_candidats[project.name][role].append(collaborateur)
# TODO: ajouter une fonction pour check si le projet peut etre fulfill
if __name__ == '__main__':
main()