forked from rjaffe/rdm_metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RDM_metrics_FY2015-Q2.py
68 lines (59 loc) · 2.59 KB
/
RDM_metrics_FY2015-Q2.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
import csv, sys
from collections import Counter
# Let's try analyzing the data without using pandas and data frames
# Column headers (row to be removed):
# [0] Title ("Question asked")
# [1] Date/Time
# [2] Is this question answered?
# [3] Referral In
# [4] Referral Out
# [5] Department
# [6] Organizational partners
# [7] Patron status
from config import *
filename = sys.argv[1]
myrows = []
# Read data into a list of lists, clean as required
with open(filename) as csvfile:
for row in csv.reader(csvfile, delimiter=","):
# Remove rows in which "Is this question answered?" is blank -- i.e., 'FYI only' engagements
if not row[2]: continue
try:
(startdate, enddate) = row[1].split(' to ')
except:
# if there is no 'to', assume startdate == enddate
(startdate, enddate) = (row[1], row[1])
row.extend([startdate, enddate])
# Referrals in, Referrals out, Clean Department, Organizational partner and Patron status "columns":
# replace empty values with appropriate label
for n, label in zip(dictable_cols, labels):
if row[n] == '':
row[n] = label
# make every cell into a list (some cells have comma separated values)
row[n] = row[n].split(', ')
# Replace individual names with the corresponding org name in Referral In and Referral Out fields (positional elements [3] and [4]),
for n in [3, 4]:
ref_x = row[n]
row[n] = [] # Empty cell to ready it for being re-filled
for term in ref_x:
for key in refs.keys():
if term in refs[key][1]:
term = refs[key][0]
row[n].append(term)
myrows.append(row)
# ***** COUNT THE DATA *****
# Each row (list) except first (header) row represents a consulting engagement
print('\nIn FY2015-Q2, RDM Consulting provided %d consultations.' % (len(myrows) - 1))
# Count how many engagements are resolved successfully
myrows = [r for r in myrows if r[2] == 'Yes, we have an answer!']
print('We reached a successful resolution in %d of those engagements.' % len(myrows))
# Gather and count (subtotal) the values for referrals in, referrals out, departments,
# organizational partners and patron status (only those five "columns" for now).
for i, n in enumerate(dictable_cols):
counter = Counter()
for row in myrows:
for z in row[n]:
counter[z] += 1
print('\n' + headings[i] + ':')
for (k, v) in counter.most_common():
print(k + ' (' + str(v) + ')')