-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgne.py
85 lines (69 loc) · 3.84 KB
/
gne.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
#!/usr/bin/env python3
# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory
import os
# MODE_KAGGLE => specific basedir / filein = *.in / fileout = submission.csv
# ELSE => filein = *.txt / fileout = submission_samefilein
def main():
contributors = create_df_contrib_sample()
contributors['dispo'] = True
contributors['skill_assigned_to'] = ""
data_projects = [{'name': 'Logging', 'duration': 5, 'award':10, 'best_time':5, 'skills_nbr':1},
{'name': 'WebServer', 'duration': 7, 'award':10, 'best_time':7, 'skills_nbr':2},
{'name': 'WebChat', 'duration': 10, 'award':20, 'best_time':20, 'skills_nbr':2}
]
projects = pd.DataFrame(data_projects)
projects = projects.sort_values(by=['award'], ascending=False)
data_project_skills = [{'name': 'Logging', 'skill_name': 'C++', 'skill_lvl':3, 'skill_pos':0},
{'name': 'WebServer', 'skill_name': 'HTML', 'skill_lvl':3, 'skill_pos':0},
{'name': 'WebServer', 'skill_name': 'C++', 'skill_lvl':2, 'skill_pos':1},
{'name': 'WebChat', 'skill_name': 'Python', 'skill_lvl':3, 'skill_pos':0},
{'name': 'WebChat', 'skill_name': 'HTML', 'skill_lvl':3, 'skill_pos':1}
]
project_skills = pd.DataFrame(data_project_skills)
# project_skill = {'name': 'Logging', 'skill_name': 'C++', 'skill_lvl':5, 'skill_pos':0}
for inc in range(projects.index.size):
proj_name = projects.loc[inc]['name']
if is_faisable(proj_name):
project_skills_list = project_skills[(project_skills['name'] == proj_name)]
assign_worker_to_role(contributors, project_skills_list, organization, proj_name)
def create_df_contrib_sample():
data = [{'name': 'Anna', 'skill_name': 'C++', 'skill_lvl':2},
{'name': 'Bob', 'skill_name': 'HTML', 'skill_lvl':5},
{'name': 'Bob', 'skill_name': 'CSS', 'skill_lvl':5},
{'name': 'Maria', 'skill_name': 'Python', 'skill_lvl':3},
{'name': 'Jean', 'skill_name': 'C++', 'skill_lvl':8},
]
df = pd.DataFrame(data)
return(df)
def is_faisable(ff):
return True
def add_to_organization(organization, contributor, project_name):
row = organization.loc(organization['name'] == project_name)
# if row:
# else:
last_pos = organization['project_pos'].max()
new_row = {'name': project_name, 'contributors': contributor['name'], 'project_pos': last_pos + 1}
print(new_row)
organization.append(new_row)
return organization
def assign_worker_to_role(contributors, project_skills, organization, project_name):
like_df = contributors['name'].str.split(expand=True).stack().value_counts().reset_index()
like_df.columns = ['name', 'id']
nb_worker = like_df['name'].drop_duplicates().size
for n in project_skills.index:
project_skill = project_skills.loc[n]
good_contributor = contributors[(contributors['skill_name'] == project_skill['skill_name']) &
(contributors['skill_lvl'] >= project_skill['skill_lvl']) &
(contributors['dispo'] == True)].head(1)
if good_contributor.index.size >= 1:
good_contributor.loc[good_contributor.index, ['dispo']] = False
good_contributor.loc[good_contributor.index, ['skill_assigned_to']] = project_skill['skill_name']
add_to_organization(organization, good_contributor, project_name)
if __name__ == "__main__":
main()