forked from d101tm/tmstats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakebusinessmeetingreport.py
More file actions
executable file
·117 lines (91 loc) · 4.03 KB
/
makebusinessmeetingreport.py
File metadata and controls
executable file
·117 lines (91 loc) · 4.03 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python3
""" Insert description of this program here """
import tmutil, sys
import tmglobals
myglobals = tmglobals.tmglobals()
import csv, xlsxwriter
### Insert classes and functions here. The main program begins in the "if" statement below.
divisions = {}
fontname = 'Myriad Pro'
class myclub(object):
def __init__(self, info, dec):
keepers = ['clubnumber', 'clubname', 'oldarea', 'newarea']
for f in keepers:
self.__dict__[f] = info[f]
if self.clubnumber in dec:
self.decarea = dec[self.clubnumber]
else:
self.decarea = 'New'
self.clubnumber = int(self.clubnumber)
self.division = self.newarea[0]
if self.division not in divisions:
divisions[self.division] = {}
thisdiv = divisions[self.division]
if self.newarea not in thisdiv:
thisdiv[self.newarea] = []
thisarea = thisdiv[self.newarea]
thisarea.append(self)
if __name__ == "__main__":
import tmparms
# Establish parameters
parms = tmparms.tmparms()
# Add other parameters here
parms.add_argument('--infile', default='d101align.csv')
parms.add_argument('--decfile', default='d101decalign.csv')
parms.add_argument('--outtemplate', default='d101bm-div%s.xlsx')
# Do global setup
myglobals.setup(parms)
curs = myglobals.curs
conn = myglobals.conn
# Start by getting alignment from the DEC file
reader = csv.DictReader(open(parms.decfile, 'r'))
dec = {}
for row in reader:
dec[row['clubnumber']] = row['newarea']
# The only information we need is in the alignment file
reader = csv.DictReader(open(parms.infile, 'r'))
for row in reader:
myclub(row, dec)
# Process each division in turn
divnames = sorted(divisions.keys())
for div in divnames:
thisdiv = divisions[div]
book = xlsxwriter.Workbook(parms.outtemplate % div)
# Create formats
divformat = book.add_format({'bold': True, 'font_name': fontname, 'font_size': 18, 'align': 'center'})
areaformat = book.add_format({'bold': True, 'font_name': fontname, 'font_size': 14, 'align': 'center'})
nameformat = book.add_format({'bold': True, 'font_name': fontname})
numformat = book.add_format({'align': 'right', 'font_name': fontname})
bold = book.add_format({'bold':True, 'font_name': fontname})
boldright = book.add_format({'bold': True, 'align':'right', 'font_name': fontname})
changedformat = book.add_format({'italic': True, 'bold': True, 'font_name': fontname, 'bg_color': '#E0E0E0'})
sheet = book.add_worksheet()
sheet.set_column(0, 0, 15)
sheet.set_column(1, 1, 50)
sheet.set_column(2, 2, 20)
sheet.set_column(3, 3, 20)
sheet.merge_range(0, 0, 0, 3, 'Division %s' % div, divformat)
sheet.write(1, 0, 'Club Number', boldright)
sheet.write(1, 1, 'Club Name', bold)
sheet.write(1, 2, 'Current Alignment', bold)
sheet.write(1, 3, 'Proposed Alignment', bold)
rownum = 2
# Process each area in turn
areanames = sorted(thisdiv.keys())
for area in areanames:
thisarea = thisdiv[area]
thisarea.sort(key=lambda c:c.clubnumber)
sheet.merge_range(rownum, 0, rownum, 3, 'Area %s' % area, areaformat)
rownum += 1
for club in thisarea:
sheet.write(rownum, 0, club.clubnumber, numformat)
if club.newarea != club.decarea:
print(club.clubname, 'moved to', club.newarea, '- was', club.decarea)
sheet.write(rownum, 1, club.clubname, changedformat)
else:
sheet.write(rownum, 1, club.clubname, nameformat)
sheet.write(rownum, 2, club.oldarea)
sheet.write(rownum, 3, club.newarea)
rownum += 1
# That's it
book.close()