-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.rb
281 lines (226 loc) · 7.19 KB
/
test.rb
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
def setDateYear(datestr, date)
if date.month >= 9
return datestr + " 2011"
else
return datestr + " 2012"
end
end
def createMatchDataHash(match_data)
data_names = match_data.names
data_values = match_data.captures
data_hash = {}
data_names.size.times do |i|
data_hash[data_names[i]] = data_values[i].strip
end
return data_hash
end
def parseUnitData(line)
unit_metadata_regex = /Unit\W(?<unit_num>\d):\W(?<unit_name>[\w\s\(\)-]{1,})\?\s(?<unit_days>\d{1,2})\sdays\s\?\s(?<start_date>\w{1,}\s\d{1,2}) through (?<end_date>\w{1,}\s\d{1,2})/
match_data = line.match(unit_metadata_regex)
unit = createMatchDataHash(match_data)
unit["unit_name"] = unit["unit_name"].split.each{|word| word.capitalize!}.join(" ")
return unit
end
def parseModuleData(line)
moduleRegex = /\* Module (?<module_num>\d) \((?<num_days>\d{1,2}) days\)/
match_data = line.match(moduleRegex)
return createMatchDataHash(match_data)
end
def parseStandard(line)
standardRegex = /\* (?<code>S\d\d\.\w\.(\d\.?){3}) (?<statement>[\w\s\(\)\.\,]{1,})/
match_data = line.match(standardRegex)
return createMatchDataHash(match_data)
end
def parseTextbookRef(line)
txtRefRegex = /(?<textbook>(Holt|Hewitt)) (?<location>.{1,})/
match_data = line.match(txtRefRegex)
return createMatchDataHash(match_data)
end
Dir.foreach('./public/data/curric') do |file|
puts file
if file.match(/physics_unit_\d.txt$/)
file = File.new("./public/data/curric/" + file, "r")
# file = File.new("./public/data/curric/physics_unit_3.txt", "r")
inUnitMeta = true # always true initially b/c always the first line
moduleRegex = /\* Module (?<module_num>\d) \((?<num_days>\d{1,2}) days\)/
inModuleName = false
moduleNotesRegex = /o (Holt|Hewitt) pp \d{1,3}-\d{1,3}/
inModuleNotes =false
unitNotesRegex = /Note:/
inUnitNotes = false
eligibleContentRegex = /^Eligible Content:(\s)?$/
inEligibleContent = false
standardRegex = /\* (?<code>S\d\d\.\w\.(\d\.?){3}) (?<statement>[\w\s\(\)\.\,]{1,})/
keyConceptsRegex = /^Key Concepts:(\s){1,}?$/
inKeyConcepts = false
goalsRegex = /Content Expectations and Performance Expectations/
inGoals = false
moduleTitleRegex = /^(\s)?Module (?<module_num>\d)$/
current_mod = ""
topicRegex = /^(\s{1,})?[A-Z][\w\s\?\(\):]{1,}$/
inTopic = false
olRegex = /^(?<number>\d{1,2}).(\s){1,}(?<statement>[\w\s,\(\)\.\-\/#;\?\+]{1,})$/
pspRegex = /Differentiation for PSP/
inPSPGoals = false
keyTermsRegex = /Key Terms/
inKeyTerms = false
inPSPterms = false
keyTermRegex = /^\* (?<term>[\w\s]{1,})$/
misconceptionRegex = /^Misconceptions:(\s)?$/
inMisconceptions = false
summaryRegex = /Summary of Unit/
inSummary = false
thresholdRegex = /Threshold problems:/
inThresholdProblems = false
inPSPproblems = false
problem_type = ""
thresholdProblemRegex =/\* (Holt|Hewitt) (pp|p\.)[#\d\s,-]{1,}(\w)?/
thresholdModuleRegex = /^Module (?<mod_num>\d)(\s)?$/
whitespaceRegex = /^[\s]{1,}$/
unit = {}
# will have number, name, start date, end date, and days
modules = {}
# each mod will have number and number of days, also an array of notes
current_mod = ""
thresh_mod_num = ""
standards = []
key_concepts = []
key_terms = []
topics = []
current_topic = ""
goals = []
misconceptions = []
threshold_problems = []
file.each_line do |line|
unless whitespaceRegex.match(line)
if inUnitMeta
# parse unit metadata and save to unit hash
unit = parseUnitData(line)
unit["notes"] = []
inUnitMeta = false
elsif moduleRegex.match(line)
inModuleName = true
mod = parseModuleData(line)
mod["unit"] = unit["unit_name"]
mod["notes"] = []
modules[mod["module_num"]] = mod
current_mod = mod["module_num"]
elsif inModuleName && unitNotesRegex.match(line)
current_mod = ""
inModuleName = false
inUnitNotes = true
elsif eligibleContentRegex.match(line)
inUnitNotes = false
inEligibleContent = true
elsif keyConceptsRegex.match(line)
inEligibleContent = false
inKeyConcepts = true
elsif goalsRegex.match(line)
inKeyConcepts = false
inGoals = true
elsif keyTermsRegex.match(line)
inKeyTerms = true
inGoals = false
inTopic = false
elsif misconceptionRegex.match(line)
inKeyTerms = false
inMisconceptions = true
elsif summaryRegex.match(line)
inMisconceptions = false
inSummary = true
elsif thresholdRegex.match(line)
inSummary = false
inThresholdProblems = true
elsif moduleTitleRegex.match(line)
current_mod = moduleTitleRegex.match(line)["module_num"]
elsif inGoals && topicRegex.match(line) && thresholdModuleRegex.match(line).nil?
if pspRegex.match(line).nil?
inPSPGoals = false
inTopic = true
topic = {}
topic["name"] = line.strip
topic["mod"] = current_mod
topics << topic
current_topic = topic["name"]
else
inPSPGoals = true
end
# in Module Notes
elsif current_mod != "" && moduleNotesRegex.match(line)
modules[current_mod]["notes"] << parseTextbookRef(line)
elsif inUnitNotes
unit["notes"] << line[2..line.size].strip
elsif inEligibleContent && standardRegex.match(line)
inUnitNotes = false
standards << parseStandard(line)
elsif inKeyConcepts && olRegex.match(line)
concept = createMatchDataHash(olRegex.match(line))
key_concepts << concept
elsif inTopic && olRegex.match(line)
goal = createMatchDataHash(olRegex.match(line))
goal["topic"] = current_topic
if inPSPGoals
goal["PSP"] = true
else
goal["PSP"] = false
end
goals << goal
elsif inKeyTerms && pspRegex.match(line)
inPSPterms = true
elsif inKeyTerms && keyTermRegex.match(line)
term = createMatchDataHash(keyTermRegex.match(line))
if inPSPterms
term["PSP"] = true
else
term["PSP"] = false
end
key_terms << term
elsif inMisconceptions
misconceptions << line[2..line.size].strip.gsub(/\?/, "'").capitalize
elsif thresholdModuleRegex.match(line)
current_mod = createMatchDataHash(thresholdModuleRegex.match(line))["mod_num"]
elsif inThresholdProblems && topicRegex.match(line)
if pspRegex.match(line).nil?
problem_type = line.strip
inPSPproblems = false
if problem_type.include?("problems")
problem_type = line.split(" ")[0]
end
else
inPSPproblems = true
end
elsif inThresholdProblems && thresholdProblemRegex.match(line)
problem = {}
problemLine = line[2..line.size].strip
problem["text"] = parseTextbookRef(problemLine)
problem["type"] = problem_type
problem["module"] = current_mod
if inPSPproblems
problem["PSP"] = true
else
problem["PSP"] = false
end
threshold_problems << problem
end
end
end
br = " ============================================================================= "
puts unit
puts br
puts modules
puts br
puts standards
puts br
puts key_concepts
puts br
puts topics
puts br
puts goals
puts br
puts key_terms
puts br
puts misconceptions
puts br
puts threshold_problems
end
end