first commit
This commit is contained in:
commit
0538cd2797
|
@ -0,0 +1,4 @@
|
|||
*.csv
|
||||
|
||||
# Mac OS
|
||||
.DS_Store
|
|
@ -0,0 +1,71 @@
|
|||
#!/usr/bin/python
|
||||
# Filename : analyse.py
|
||||
|
||||
import csv
|
||||
|
||||
filename = 'WorldC_men_finals.csv'
|
||||
|
||||
skills_dict = dict()
|
||||
combination_dict = dict()
|
||||
|
||||
number_of_skill = 0
|
||||
number_of_routine = 0
|
||||
number_of_unfinished_routine = 0
|
||||
|
||||
with open(filename, 'r') as csvfile:
|
||||
csv_reader = csv.reader(csvfile, delimiter=';', quotechar='\'')
|
||||
for line in csv_reader:
|
||||
number_of_routine += 1
|
||||
previous_skill = None
|
||||
skill_in_routine = 0
|
||||
for skill in line:
|
||||
number_of_skill += 1
|
||||
skill_in_routine += 1
|
||||
skills_dict[skill.replace(" ", "")] = skills_dict.get(skill, 0) + 1
|
||||
|
||||
if skill_in_routine != 10:
|
||||
number_of_unfinished_routine += 1
|
||||
|
||||
# Definition du second dictionnaire pour les combinaises
|
||||
for key, value in skills_dict.items():
|
||||
combination_dict[key] = dict()
|
||||
for k, v in skills_dict.items():
|
||||
combination_dict[key][k] = 0
|
||||
combination_dict[key]['begin'] = 0
|
||||
|
||||
combination_dict['end'] = dict()
|
||||
for k, v in skills_dict.items():
|
||||
combination_dict['end'][k] = 0
|
||||
|
||||
with open(filename, 'r') as csvfile:
|
||||
csv_reader = csv.reader(csvfile, delimiter=';', quotechar='\'')
|
||||
for line in csv_reader:
|
||||
previous_skill = None
|
||||
for skill in line:
|
||||
if previous_skill is None:
|
||||
combination_dict[skill]['begin'] += 1
|
||||
else:
|
||||
combination_dict[skill][previous_skill] += 1
|
||||
previous_skill = skill
|
||||
combination_dict['end'][previous_skill] += 1
|
||||
|
||||
|
||||
with open('result_' + filename, 'w') as result_file:
|
||||
writer = csv.writer(result_file, delimiter=';')
|
||||
writer.writerow(["Skill", "# Apparition", "% Apparition"])
|
||||
for key, value in skills_dict.items():
|
||||
writer.writerow([str(key), str(value), str(value / number_of_routine)])
|
||||
|
||||
print('------------------------------------------------------------------------')
|
||||
print('Number of routine: ' + str(number_of_routine))
|
||||
print('Number of unfinished routine: ' + str(number_of_unfinished_routine))
|
||||
print('Number of skill: ' + str(number_of_skill))
|
||||
print('')
|
||||
for key, value in skills_dict.items():
|
||||
print(str(key) + ' : ' + str(value) + ' / ' + str(number_of_routine))
|
||||
print('')
|
||||
for key, v in combination_dict.items():
|
||||
for k, value in combination_dict[key].items():
|
||||
if value != 0:
|
||||
print(str(k) + ' & ' + str(key) + ' : ' + str(value) + ' / ' + str(number_of_routine))
|
||||
print('------------------------------------------------------------------------')
|
Loading…
Reference in New Issue