Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. import csv
  2. from collections import namedtuple
  3.  
  4. with open('data.csv', encoding='utf8') as data:
  5.     table = csv.DictReader(data, delimiter=';')
  6.     print(table.fieldnames)
  7.     users = {}
  8.     name_by_id = {}
  9.     for info in table:
  10.         name_by_id[info['User_Id']] = info['User_Name']
  11.         if info['User_Inv'] == 'I' or info['Stat_Short'] == 'CE':
  12.             continue
  13.         if info['User_Id'] not in users:
  14.             users[info['User_Id']] = dict()
  15.         if info['Prob'] not in users[info['User_Id']]:
  16.             users[info['User_Id']][info['Prob']] = {'st': '_', 'penalty': 0}
  17.         if users[info['User_Id']][info['Prob']]['st'] == 'OK':
  18.             continue
  19.         else:
  20.             if info['Stat_Short'] == 'OK':
  21.                 users[info['User_Id']][info['Prob']]['st'] = 'OK'
  22.                 users[info['User_Id']][info['Prob']]['penalty'] += int(info['Dur'])
  23.                 continue
  24.             users[info['User_Id']][info['Prob']]['penalty'] += 20 * 60
  25.     ans = []
  26.     user = namedtuple(['name', 'cnt', 'penalty'])
  27.     for name in users:
  28.         cnt, penalty = 0, 0
  29.         for prob in name.values():
  30.             if prob['st'] == 'OK':
  31.                 cnt += 1
  32.                 penalty += prob['penalty']
  33.         ans.append(user(name_by_id[name], cnt, penalty))
  34.     ans.sort(key=lambda x: ())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement