-
Notifications
You must be signed in to change notification settings - Fork 0
/
mama.rb
268 lines (202 loc) · 9.45 KB
/
mama.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
require 'icalendar'
require 'sinatra'
require 'sinatra/reloader'
require 'nokogiri'
require 'open-uri'
require './all_courses.rb'
require './emailer.rb'
require './events.rb'
require './practice_hash'
require './scraper.rb'
require 'date'
require 'time'
enable :sessions
enable :method_override
# cal = Icalendar::Calendar.new
# event = cal.event do |e|
# e.dtstart = DateTime.civil(2014, 6, 13, 8, 30)
# e.dtend = DateTime.civil(2014, 6, 13, 9, 30)
# e.summary = "This is a summary with params."
# end
# email = "[email protected]"
# event.alarm do |a|
# a.action = "EMAIL"
# a.description = "This is an event reminder" # email body (required)
# a.summary = "Mama Homeschool Reminding you!" # email subject (required)
# a.attendee = ["mailto:" + email] # one or more email recipients (required)
# a.trigger = "-PT20M" # 15 minutes before
# # a.append_attach Icalendar::Values::Uri.new "ftp://host.com/novo-procs/felizano.exe", "fmttype" => "application/binary" # email attachments (optional)
# end
# cal_string = cal.to_ical
# File.open('public/newcal.ics', 'w') { |file| file.write(cal_string) }
def convert_to_time (number)
if number >= 12
number_s =
if number == 12
number.to_s
else
(number % 12).to_s
end
number_s += "pm"
else
number_s =
if number == 0
number = 12
number.to_s
else
number.to_s
end
number_s += "am"
end
return number_s
end
get '/' do
session['pickedcourses'] = false
session['pickedschedule'] = false
erb :index
end
get '/courses' do
courses = stored_courses
erb :courseselection, locals: {courses: courses}
end
get '/scheduler' do
dayarr = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
erb :scheduler, locals: {dayarr: dayarr}
end
get '/scheduler/yournewschedule' do
erb :userschedule
end
get '/about' do
erb :about
end
def dateConverter(datestr)
monthsH = {"January"=>1, "February"=>2, "March"=>3, "April"=>4, "May"=>5, "June"=>6, "July"=>7,
"August"=>8, "September"=>9, "October"=>10, "November"=>11, "December"=>12}
startdatearr = datestr.delete(',').split(" ")
year = startdatearr[2].to_i
# puts startdatearr
# puts monthsH
month = monthsH[startdatearr[1]]
# puts month
day = startdatearr[0].to_i
DateTime.new(year, month, day, 0, 0, 0, -4)
end
def timeToNum(timestr)
if timestr == nil || timestr == ''
timenum = 0
else
timearr = timestr.split(':')
timenum = timearr[0].to_i
if timestr.include?('PM')
if timenum != 12
timenum += 12
end
end
if timenum == 12 && timestr.include?('AM')
timenum = 0
end
end
timenum
end
def createDayArray(starttime, endtime)
hoursInDay = Array.new(24) {false}
for i in starttime...endtime
hoursInDay[i] = true
end
return hoursInDay
end
post '/scheduler/yournewschedule' do
session['email'] ||= "[email protected]"
session['pickedschedule'] = true
daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
hoursInWeek = Array.new(168)
hoursInWeek.each {|hour| hour = false}
if params['startdate'] == ''
startdate = DateTime.now
else
startdate = dateConverter(params['startdate'])
end
daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
# daysOfWeek.each do |day, hash|
# starttime = timeToNum(params[day+"-starttime"])
# endtime = timeToNum(params[day+"-endtime"])
# puts "Starttime" + params[day+"-starttime"] + " Parsed Input: " + starttime.to_s
# puts "EndTime" + params[day+"-endtime"] + " Parsed Input: " + endtime.to_s
# hash[:availableHours] = createDayArray(starttime, endtime)
# hash[:totalHours] = endtime - starttime
# end
#Figures out the slots of time that are available each week
weekavail = WeekAvailability.new
daysOfWeek.each do |day|
starttime = timeToNum(params[day+"-starttime"])
endtime = timeToNum(params[day+"-endtime"])
#Find slots of time that are available each day
case day
when "Monday"
weekavail.Monday = DayAvailability.new(day, createDayArray(starttime, endtime), endtime-starttime)
when "Tuesday"
weekavail.Tuesday = DayAvailability.new(day, createDayArray(starttime, endtime), endtime-starttime)
when "Wednesday"
weekavail.Wednesday= DayAvailability.new(day, createDayArray(starttime, endtime), endtime-starttime)
when "Thursday"
weekavail.Thursday = DayAvailability.new(day, createDayArray(starttime, endtime), endtime-starttime)
when "Friday"
weekavail.Friday = DayAvailability.new(day, createDayArray(starttime, endtime), endtime-starttime)
when "Saturday"
weekavail.Saturday = DayAvailability.new(day, createDayArray(starttime, endtime), endtime-starttime)
when "Sunday"
weekavail.Sunday = DayAvailability.new(day, createDayArray(starttime, endtime), endtime-starttime)
end
end
#hours Per Week that you are willing to work
hoursperweek = params['hoursPerWeek'].to_i
weeksched = WeekSchedule.new(startdate, weekavail.weekArray, hoursperweek.to_i)
#create a schedule of weekly availability
weeklysched = weeksched.createSchedule
# puts weeklysched
#create total schedule
#puts session['selectedcourses']
totalsched = TotalSchedule.new(stored_courses, session['selectedcourses'], hoursperweek)
# h = {:professor=>"Shiller, Robert J.", :number=>"ECON 252", :link=>"/economics/econ-252-08", :department=>"Economics", :department_link=>"/economics", :title=>"Financial Markets (2008)", :sessions=>[{:title=>"Finance and Insurance as Powerful Forces in Our Economy and Society", :link=>"/economics/econ-252-08/lecture-1"}, {:title=>"The Universal Principle of Risk Management: Pooling and the Hedging of Risks", :link=>"/economics/econ-252-08/lecture-2"}, {:title=>"Technology and Invention in Finance", :link=>"/economics/econ-252-08/lecture-3"}, {:title=>"Portfolio Diversification and Supporting Financial Institutions (CAPM Model)", :link=>"/economics/econ-252-08/lecture-4"}, {:title=>"Insurance: The Archetypal Risk Management Institution", :link=>"/economics/econ-252-08/lecture-5"}, {:title=>"Efficient Markets vs. Excess Volatility", :link=>"/economics/econ-252-08/lecture-6"}, {:title=>"Behavioral Finance: The Role of Psychology", :link=>"/economics/econ-252-08/lecture-7"}, {:title=>"Human Foibles, Fraud, Manipulation, and Regulation", :link=>"/economics/econ-252-08/lecture-8"}, {:title=>"Guest Lecture by David Swensen", :link=>"/economics/econ-252-08/lecture-9"}, {:title=>"Debt Markets: Term Structure", :link=>"/economics/econ-252-08/lecture-10"}, {:title=>"Midterm Exam 1", :link=>"/economics/econ-252-08/exam-1"}, {:title=>"Stocks", :link=>"/economics/econ-252-08/lecture-11"}, {:title=>"Real Estate Finance and Its Vulnerability to Crisis", :link=>"/economics/econ-252-08/lecture-12"}, {:title=>"Banking: Successes and Failures", :link=>"/economics/econ-252-08/lecture-13"}, {:title=>"Guest Lecture by Andrew Redleaf", :link=>"/economics/econ-252-08/lecture-14"}, {:title=>"Guest Lecture by Carl Icahn", :link=>"/economics/econ-252-08/lecture-15"}, {:title=>"The Evolution and Perfection of Monetary Policy", :link=>"/economics/econ-252-08/lecture-16"}, {:title=>"Midterm Exam 2", :link=>"/economics/econ-252-08/exam-2"}, {:title=>"Investment Banking and Secondary Markets", :link=>"/economics/econ-252-08/lecture-17"}, {:title=>"Professional Money Managers and Their Influence", :link=>"/economics/econ-252-08/lecture-18"}, {:title=>"Brokerage, ECNs, etc.", :link=>"/economics/econ-252-08/lecture-19"}, {:title=>"Guest Lecture by Stephen Schwarzman", :link=>"/economics/econ-252-08/lecture-20"}, {:title=>"Forwards and Futures", :link=>"/economics/econ-252-08/lecture-21"}, {:title=>"Stock Index, Oil and Other Futures Markets", :link=>"/economics/econ-252-08/lecture-22"}, {:title=>"Options Markets", :link=>"/economics/econ-252-08/lecture-23"}, {:title=>"Making It Work for Real People: The Democratization of Finance", :link=>"/economics/econ-252-08/lecture-24"}, {:title=>"Okun Lecture: Learning from and Responding to Financial Crisis, Part I (Guest Lecture by Lawrence Summers)", :link=>"/economics/econ-252-08/lecture-25"}, {:title=>"Okun Lecture: Learning from and Responding to Financial Crisis, Part II (Guest Lecture by Lawrence Summers)", :link=>"/economics/econ-252-08/lecture-26"}, {:title=>"Final Exam", :link=>"/economics/econ-252-08/exam-3"}], :time=>58}
# totalsched.createAvailabilityArray(h)
# totalsched.createCourseArray(h)
totalsched.createAvailabilityArray(weeklysched)
totalsched.createCourseArray
coursearr = totalsched.createScheduleArray
#puts coursearr.to_s
cal = Icalendar::Calendar.new
cal = add_to_cal(cal,startdate,coursearr,session['email'])
cal_string = cal.to_ical
File.open('public/newcal.ics', 'w') { |file| file.write(cal_string) }
# puts totalsched.to_s
# puts coursearr.to_s
# starttime = timeToNum(starttime)
# endtime = timeToNum(endtime)
erb :availabilitysuccess
end
# get '/courses' do
# if session[:availiable_hours] == nil
# erb :no_courseselection
# else
# erb :courseselection, locals: {session: session}
# end
# end
post '/courses' do
session['pickedcourses'] = true
session['selectedcourses'] ||= {}
session['selectedcourses'] = params[:item]
courses = []
if params[:item] == nil
erb :no_courseselection
else
session['selectedcourses'].each do |course|
courses.push(stored_courses[course.to_i])
end
erb :coursesuccess, locals: {courses: courses, session: session}
end
end
post '/about' do
session['email'] ||= ''
session['email'] = params['youremail']
erb :availabilitysuccess
end