218 lines
7.1 KiB
Python
218 lines
7.1 KiB
Python
#!/usr/bin/python
|
|
# Filename : analyse.py
|
|
|
|
import sys
|
|
import os.path
|
|
from os import path
|
|
from openpyxl import Workbook, load_workbook
|
|
from openpyxl.styles import Font, numbers
|
|
|
|
|
|
def save_skill_statistics(filename, skills_dict, number_of_skill, number_of_routine, number_of_unfinished_routine, number_of_tucked, number_of_picked, number_of_straight) -> None:
|
|
wb = Workbook()
|
|
ws_skill = wb.active
|
|
ws_skill.title = "Skill Statistics"
|
|
|
|
# Headers
|
|
ws_skill['A1'] = "# Routine"
|
|
ws_skill['A1'].font = Font(bold=True)
|
|
ws_skill['B1'] = "# Unfinished R."
|
|
ws_skill['B1'].font = Font(bold=True)
|
|
ws_skill['C1'] = "# skill"
|
|
ws_skill['C1'].font = Font(bold=True)
|
|
ws_skill['D1'] = "# tucked"
|
|
ws_skill['D1'].font = Font(bold=True)
|
|
ws_skill['E1'] = "# picked"
|
|
ws_skill['E1'].font = Font(bold=True)
|
|
ws_skill['F1'] = "# straight"
|
|
ws_skill['F1'].font = Font(bold=True)
|
|
|
|
# Informations
|
|
ws_skill['A2'] = number_of_routine
|
|
ws_skill['B2'] = number_of_unfinished_routine
|
|
ws_skill['C2'] = number_of_skill
|
|
ws_skill['D2'] = number_of_tucked
|
|
ws_skill['E2'] = number_of_picked
|
|
ws_skill['F2'] = number_of_straight
|
|
|
|
ws_skill['B3'] = number_of_unfinished_routine / number_of_routine
|
|
ws_skill['B3'].number_format = numbers.FORMAT_PERCENTAGE_00
|
|
ws_skill['C3'] = number_of_skill / number_of_routine
|
|
ws_skill['D3'] = number_of_tucked / number_of_routine
|
|
ws_skill['E3'] = number_of_picked / number_of_routine
|
|
ws_skill['F3'] = number_of_straight / number_of_routine
|
|
|
|
# Headers
|
|
ws_skill['H1'] = "Skill"
|
|
ws_skill['H1'].font = Font(bold=True)
|
|
ws_skill['I1'] = "# Apparition"
|
|
ws_skill['I1'].font = Font(bold=True)
|
|
ws_skill['J1'] = "% Apparition"
|
|
ws_skill['J1'].font = Font(bold=True)
|
|
|
|
line = 2
|
|
for key, value in skills_dict.items():
|
|
ws_skill['H' + str(line)] = str(key)
|
|
ws_skill['I' + str(line)] = value
|
|
ws_skill['J' + str(line)] = value / number_of_routine
|
|
ws_skill['J' + str(line)].number_format = numbers.FORMAT_PERCENTAGE_00
|
|
line += 1
|
|
|
|
wb.save(filename = filename[:-5] + '_analysed.xlsx')
|
|
|
|
|
|
def save_combinaison_statistics(filename, combination_dict, number_of_skill) -> None:
|
|
wb = load_workbook(filename[:-5] + '_analysed.xlsx')
|
|
ws_combinaison = wb.create_sheet('Combinaison statistics')
|
|
|
|
# Headers
|
|
ws_combinaison['A1'] = "Combinaison"
|
|
ws_combinaison['A1'].font = Font(bold=True)
|
|
ws_combinaison['B1'] = "# Apparition"
|
|
ws_combinaison['B1'].font = Font(bold=True)
|
|
ws_combinaison['C1'] = "% Apparition"
|
|
ws_combinaison['C1'].font = Font(bold=True)
|
|
|
|
# Information
|
|
line = 2
|
|
for following_skill in combination_dict.keys():
|
|
for skill, value in combination_dict[following_skill].items():
|
|
if value != 0:
|
|
ws_combinaison['A' + str(line)] = str(skill) + ' - ' + str(following_skill)
|
|
ws_combinaison['B' + str(line)] = value
|
|
ws_combinaison['C' + str(line)] = value / number_of_routine
|
|
ws_combinaison['C' + str(line)].number_format = numbers.FORMAT_PERCENTAGE_00
|
|
line += 1
|
|
|
|
wb.save(filename = filename[:-5] + '_analysed.xlsx')
|
|
|
|
|
|
def skill_frequency(filename) -> dict:
|
|
"""
|
|
Répertorie toutes les figures contenues dans le fichier et compte le nombre de fois qu'elles
|
|
apparaissent. La fonction compte aussi le nombre de séries, le nombre de séries non finies et
|
|
le nombre de figures et le nombre de figures groupées/carpée/tendues.
|
|
"""
|
|
skills_dict = dict()
|
|
number_of_skill = 0
|
|
number_of_tucked = 0
|
|
number_of_picked = 0
|
|
number_of_routine = 0
|
|
number_of_straight = 0
|
|
number_of_unfinished_routine = 0
|
|
|
|
|
|
wb = load_workbook(filename)
|
|
routine_sheet = wb.active
|
|
max_col = routine_sheet.max_column
|
|
|
|
for column in range(1, max_col + 1):
|
|
number_of_routine += 1
|
|
skill_in_routine = 0
|
|
|
|
for row in range(2, 12):
|
|
current_cell = routine_sheet.cell(row=row, column=column)
|
|
skill = current_cell.value
|
|
|
|
if skill is not None:
|
|
number_of_skill += 1
|
|
skill_in_routine += 1
|
|
skills_dict[skill] = skills_dict.get(skill, 0) + 1
|
|
|
|
position = skill.strip()[-1:]
|
|
if position == 'o':
|
|
number_of_tucked += 1
|
|
elif position == '<':
|
|
number_of_picked += 1
|
|
elif position == '/':
|
|
number_of_straight +=1
|
|
|
|
if skill_in_routine != 10:
|
|
number_of_unfinished_routine += 1
|
|
|
|
save_skill_statistics(
|
|
filename,
|
|
skills_dict,
|
|
number_of_skill,
|
|
number_of_routine,
|
|
number_of_unfinished_routine,
|
|
number_of_tucked,
|
|
number_of_picked,
|
|
number_of_straight
|
|
)
|
|
|
|
return skills_dict, number_of_routine
|
|
|
|
|
|
def setup_combinaison_dictionnary(skills_dict) -> dict:
|
|
"""
|
|
Crée le dictionnaire de combinaison par rapport à toutes les figures contenues dans le
|
|
dictionnaire de figures.
|
|
"""
|
|
combination_dict = dict()
|
|
combination_dict['end'] = dict()
|
|
combination_dict['crash'] = dict()
|
|
|
|
for skill in skills_dict.keys():
|
|
combination_dict[skill] = dict()
|
|
combination_dict['end'][skill] = 0
|
|
combination_dict['crash'][skill] = 0
|
|
for previous_skill in skills_dict.keys():
|
|
combination_dict[skill][previous_skill] = 0
|
|
combination_dict[skill]['begin'] = 0
|
|
|
|
return combination_dict
|
|
|
|
|
|
def combinaison_frequency(filename, skills_dict, number_of_routine) -> dict:
|
|
"""
|
|
Compte la fréquence des occurences des combinaisons de deux figures.
|
|
"""
|
|
|
|
combination_dict = setup_combinaison_dictionnary(skills_dict)
|
|
|
|
wb = load_workbook(filename)
|
|
routine_sheet = wb.active
|
|
max_col = routine_sheet.max_column
|
|
|
|
for column in range(1, max_col + 1):
|
|
skill_in_routine = 0
|
|
previous_skill = None
|
|
for row in range(2, 12):
|
|
current_cell = routine_sheet.cell(row=row, column=column)
|
|
skill = current_cell.value
|
|
|
|
if skill is not None:
|
|
skill_in_routine += 1
|
|
if previous_skill is None:
|
|
combination_dict[skill]['begin'] += 1
|
|
else:
|
|
combination_dict[skill][previous_skill] += 1
|
|
previous_skill = skill
|
|
|
|
if skill_in_routine == 10:
|
|
# on ne compte pas la combinaison de fin s'il y a crash.
|
|
combination_dict['end'][previous_skill] += 1
|
|
else:
|
|
combination_dict['crash'][previous_skill] += 1
|
|
|
|
save_combinaison_statistics(filename, combination_dict, number_of_routine)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) < 2:
|
|
print('Please, give a XLSX file.')
|
|
exit()
|
|
|
|
filename = sys.argv[1]
|
|
if filename[-5:] != '.xlsx':
|
|
print('Must be a XLSX file.')
|
|
exit()
|
|
|
|
if not os.path.isfile(filename):
|
|
print('File does not exist.')
|
|
exit()
|
|
|
|
skills_dict, number_of_routine = skill_frequency(filename)
|
|
combination_dict = combinaison_frequency(filename, skills_dict, number_of_routine)
|