Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- from collections import namedtuple
- with open('data.csv', encoding='utf8') as data:
- table = csv.DictReader(data, delimiter=';')
- print(table.fieldnames)
- users = {}
- name_by_id = {}
- for info in table:
- name_by_id[info['User_Id']] = info['User_Name']
- if info['User_Inv'] == 'I' or info['Stat_Short'] == 'CE':
- continue
- if info['User_Id'] not in users:
- users[info['User_Id']] = dict()
- if info['Prob'] not in users[info['User_Id']]:
- users[info['User_Id']][info['Prob']] = {'st': '_', 'penalty': 0}
- if users[info['User_Id']][info['Prob']]['st'] == 'OK':
- continue
- else:
- if info['Stat_Short'] == 'OK':
- users[info['User_Id']][info['Prob']]['st'] = 'OK'
- users[info['User_Id']][info['Prob']]['penalty'] += int(info['Dur'])
- continue
- users[info['User_Id']][info['Prob']]['penalty'] += 20 * 60
- ans = []
- user = namedtuple(['name', 'cnt', 'penalty'])
- for name in users:
- cnt, penalty = 0, 0
- for prob in name.values():
- if prob['st'] == 'OK':
- cnt += 1
- penalty += prob['penalty']
- ans.append(user(name_by_id[name], cnt, penalty))
- ans.sort(key=lambda x: ())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement