-
Notifications
You must be signed in to change notification settings - Fork 0
/
processEntries.py
204 lines (165 loc) · 9.49 KB
/
processEntries.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import csv
import itertools
import os
import subprocess
import calendar
import style20409, style13620
def readCSV():
# Read in each CSV file and create a list of dictionaries
with open("data/business.csv") as afile:
businessFile = csv.DictReader(afile)
businessData = list(businessFile)
with open("data/building.csv") as bfile:
buildFile = csv.DictReader(bfile)
buildData = list(buildFile)
with open("data/coding.csv") as cfile:
codingFile = csv.DictReader(cfile)
codingData = list(codingFile)
with open("data/wholeTeam.csv") as wfile:
wholeFile = csv.DictReader(wfile)
wholeData = list(wholeFile)
return (businessData, buildData, codingData, wholeData)
def computeDateList(businessData, buildData, codingData, wholeData):
# Gather up a master list of all of dates of meetings by reading through every entry
aDates = [businessData[i]['Date'].split(" ")[0] for i in xrange(len(businessData))]
bDates = [buildData[i]['Date'].split(" ")[0] for i in xrange(len(buildData))]
cDates = [codingData[i]['Date'].split(" ")[0] for i in xrange(len(codingData))]
wDates = [wholeData[i]['Date'].split(" ")[0] for i in xrange(len(wholeData))]
# Taking the set removes duplicates. Then return an unsorted list
allDates = list(set(aDates + bDates + cDates + wDates))
return allDates
def findIndicesForDateAndTeam(allData, date, teamNumber):
# For a given date, find all of the entries in allData that correspond to that date.
# For a given team, find all of the entries in allData that correspond to that team
matching = []
for i in xrange(len(allData)):
rawDay = allData[i]['Date'].split(" ")[0]
rawTeam = allData[i]['Team'].split(" ")[0]
if rawDay == date and ((str(teamNumber) in rawTeam) or ('Both' in rawTeam) or ('Fill' in rawTeam)):
matching.append(i)
return matching
def displayDate(date):
# Convert the date format. i.e. "12/7/2020" -> December 7, 2020
[m, d, y] = date.split("/")
return calendar.month_name[int(m)] + ' ' + d + ', ' + y
def generateLatex20409(style, businessData, buildData, codingData, wholeData, meeting_date):
# For a particular meeting_data, generate the corresponding LaTeX page and write to meeting_date.tex
# There is a lot of list comprehension because each subteam may have multiple entries per date
# Find the list indices for all the entries corresponding to this date
aidx = findIndicesForDateAndTeam(businessData, meeting_date, style.teamNumber)
bidx = findIndicesForDateAndTeam(buildData, meeting_date, style.teamNumber)
cidx = findIndicesForDateAndTeam(codingData, meeting_date, style.teamNumber)
widx = findIndicesForDateAndTeam(wholeData, meeting_date, style.teamNumber)
# Crate a nicely formatted date
date_pretty = displayDate(meeting_date)
# Generate the header block with the date and members list
date = style.formatDate(date_pretty)
###################################
# For each of our three headers, write the header (including the dotted line)
# Then, within each header, if that subteam has entries, generate the color box for each entry
focus = style.focusHeader
summary = style.summaryHeader
challenges = style.challengesHeader
nextSteps = style.nextStepsHeader
# If exists entries for each date, generate blocks
if (len(widx) > 0):
focus += " ".join([style.wholeBlock(wholeData[widx[f]]['Focus'], f) for f in xrange(len(widx))])
summary += " ".join([style.wholeBlock(wholeData[widx[s]]['Summary'], s) for s in xrange(len(widx))])
challenges += " ".join([style.wholeBlock(wholeData[widx[c]]['Challenges/Problems'], c) for c in xrange(len(widx))])
nextSteps += " ".join([style.wholeBlock(wholeData[widx[n]]['Next Steps'], n) for n in xrange(len(widx))])
if (len(bidx) > 0):
focus += " ".join([style.buildBlock(buildData[bidx[f]]['Focus'], f) for f in xrange(len(bidx))])
summary += " ".join([style.buildBlock(buildData[bidx[s]]['Summary'], s) for s in xrange(len(bidx))])
challenges += " ".join([style.buildBlock(buildData[bidx[c]]['Challenges/Problems'], c) for c in xrange(len(bidx))])
nextSteps += " ".join([style.buildBlock(buildData[bidx[n]]['Next Steps'], n) for n in xrange(len(bidx))])
if (len(cidx) > 0):
focus += " ".join([style.codingBlock(codingData[cidx[f]]['Focus'], f) for f in xrange(len(cidx))])
summary += " ".join([style.codingBlock(codingData[cidx[s]]['Summary'], s) for s in xrange(len(cidx))])
challenges += " ".join([style.codingBlock(codingData[cidx[c]]['Challenges/Problems'], c) for c in xrange(len(cidx))])
nextSteps += " ".join([style.codingBlock(codingData[cidx[n]]['Next Steps'], n) for n in xrange(len(cidx))])
if (len(aidx) > 0):
focus += " ".join([style.businessBlock(businessData[aidx[f]]['Focus'], f) for f in xrange(len(aidx))])
summary += " ".join([style.businessBlock(businessData[aidx[s]]['Summary'], s) for s in xrange(len(aidx))])
challenges += " ".join([style.businessBlock(businessData[aidx[c]]['Challenges/Problems'], c) for c in xrange(len(aidx))])
nextSteps += " ".join([style.businessBlock(businessData[aidx[n]]['Next Steps'], n) for n in xrange(len(aidx))])
# Gather all of the material in order. "material" is a string file that contains the entire LaTeX document
material = style.header + date + focus + summary + challenges + nextSteps + style.footer
###################################
# Need to reformat date to not use backslashes in the filename
save_date = meeting_date.replace('/', '_')
fileName = 'pages/{}/{}.tex'.format(style.teamNumber, save_date)
# Write LaTex
f = open(fileName, 'a')
f.write(material)
f.close()
return save_date
def generateLatex13620(style, businessData, buildData, codingData, wholeData, meeting_date):
# For a particular meeting_data, generate the corresponding LaTeX page and write to meeting_date.tex
# There is a lot of list comprehension because each subteam may have multiple entries per date
# Find the list indices for all the entries corresponding to this date
aidx = findIndicesForDateAndTeam(businessData, meeting_date, style.teamNumber)
bidx = findIndicesForDateAndTeam(buildData, meeting_date, style.teamNumber)
cidx = findIndicesForDateAndTeam(codingData, meeting_date, style.teamNumber)
widx = findIndicesForDateAndTeam(wholeData, meeting_date, style.teamNumber)
# Crate a nicely formatted date
date_pretty = displayDate(meeting_date)
# Generate the header block with the date
date = style.formatDate(date_pretty, int(meeting_date.split("/")[0]))
###################################
# For each of our three headers, write the header (including the dotted line)
# Then, within each header, if that subteam has entries, generate the color box for each entry
building = ''
coding = ''
business = ''
whole = ''
# Check if no entries for the team
if (len(bidx) + len(cidx) + len(aidx) + len(widx)) == 0:
return None
if (len(widx) > 0):
whole += style.wholeHeader
whole += " ".join([style.wholeBlock(wholeData[widx[f]], f) for f in xrange(len(widx))])
if (len(bidx) > 0):
building += style.buildingHeader
if len(widx) > 0:
building += style.buildingHeaderOffset
building += "".join([style.buildBlock(buildData[bidx[f]], f) for f in xrange(len(bidx))])
if (len(cidx) > 0):
coding += style.codingHeader
coding += " ".join([style.codingBlock(codingData[cidx[f]], f) for f in xrange(len(cidx))])
if (len(aidx) > 0):
business += style.businessHeader
business += " ".join([style.businessBlock(businessData[aidx[f]], f) for f in xrange(len(aidx))])
# Gather all of the material in order. "material" is a string file that contains the entire LaTeX document
material = style.header + date + whole + building + coding + business + style.footer
###################################
# Need to reformat date to not use backslashes in the filename
save_date = meeting_date.replace('/', '_')
fileName = 'pages/{}/{}.tex'.format(style.teamNumber, save_date)
# Write LaTex
f = open(fileName, 'w')
f.write(material)
f.close()
return save_date
def generatePDF(fileName, teamNumber):
if fileName is None: return
# Generate PDF
# Use subprocess instead of os.system so that we can operate in different directory
p = subprocess.Popen(['pdflatex', '{}.tex'.format(fileName)], cwd='pages/{}'.format(teamNumber))
p.wait()
# Command to convert to pngs: pdftoppm 9_26_2020.pdf 9_26_2020 -png
p = subprocess.Popen(['pdftoppm', '{}.pdf'.format(fileName), fileName, '-png'], cwd='pages/{}'.format(teamNumber))
if __name__ == '__main__':
# Read in the data
aData, bData, cData, wData = readCSV()
# Create the master date list
dateList = computeDateList(aData, bData, cData, wData)
spec20409 = style20409.Team20409()
spec13620 = style13620.Team13620()
# For each date, create the file
for i in xrange(len(dateList)):
print('DATE {}'.format(dateList[i]))
# Generate LaTeX file. Then PDF, then PNG
fileName13620 = generateLatex13620(spec13620, aData, bData, cData, wData, dateList[i])
generatePDF(fileName13620, spec13620.teamNumber)
fileName20409 = generateLatex20409(spec20409, aData, bData, cData, wData, dateList[i])
generatePDF(fileName20409, spec20409.teamNumber)