forked from d101tm/tmstats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathearlyachievers.py
More file actions
executable file
·87 lines (64 loc) · 2.74 KB
/
earlyachievers.py
File metadata and controls
executable file
·87 lines (64 loc) · 2.74 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
#!/usr/bin/env python3
import os
import tmglobals
import tmparms
from tmutil import showclubswithvalues, getClubBlock
class myclub:
""" Just enough club info to sort the list nicely """
def __init__(self, clubnumber, clubname, asof, goalsmet, division, area):
self.area = '%s%s' % (division, area)
self.clubnumber = clubnumber
self.clubname = clubname
self.asof = asof
self.goalsmet = goalsmet
def tablepart(self):
return (' <td>%s</td><td>%s</td><td>%d</td>' % (self.area, self.clubname, self.goalsmet))
def key(self):
return (self.area, self.clubnumber)
# Establish parameters
parms = tmparms.tmparms()
parms.parser.add_argument("--toend", dest='toend', type=int, default=10)
parms.parser.add_argument("--outfileprefix", dest='outfileprefix', type=str, default='earlyachievers')
# Set up global environment
myglobals = tmglobals.tmglobals(parms)
conn = myglobals.conn
curs = myglobals.curs
today = myglobals.today
endmonth = '%d-%0.2d-01' % (myglobals.tmyear, parms.toend)
# If there's monthly data for the end date, use it; otherwise, use
# today's data.
curs.execute("SELECT clubnumber, clubname, asof, goalsmet, division, area FROM clubperf WHERE monthstart=%s AND entrytype = 'M'", (endmonth,))
if curs.rowcount:
final = True
else:
# No data returned; use today's data instead
curs.execute("SELECT clubnumber, clubname, asof, goalsmet, division, area FROM clubperf WHERE entrytype = 'L' AND district = %s", (parms.district,))
final = False
status = "final" if final else "updated daily"
clubs = []
for c in curs.fetchall():
clubs.append(myclub(*c))
winners = [c for c in clubs if c.goalsmet >= 5]
almost = [c for c in clubs if c.goalsmet == 4]
# Write the HTML version
outfile = open(os.path.join(parms.workdir, parms.outfileprefix + '.html'), 'w')
outfile.write("""<h3 id="early">Early Achievers</h3>
<p>
Clubs achieving 5 or more Distinguished Club Program (DCP) goals by October 31 earn $100 in District Credit. This report is %s.</p>
""" % status)
if len(winners) > 0:
outfile.write("<h4>Early Achievers</h4>\n")
showclubswithvalues(winners, "Goals", outfile)
if len(almost) > 0 and not final:
outfile.write("<p> </p>")
outfile.write("<p>These clubs have achieved 4 of the 5 DCP goals needed to join the Early Achievers.</p>")
showclubswithvalues(almost, "Goals", outfile)
outfile.close()
# Write the text block version
outfile = open(os.path.join(parms.workdir, parms.outfileprefix + '.text'), 'w')
if len(winners) > 0:
outfile.write("<b>Congratulations to our first Early Achiever Club%s</b>: " % ('s' if len(winners) > 1 else ''))
outfile.write(getClubBlock(winners))
outfile.write('.')
outfile.write('\n')
outfile.close()