rhs-schedule 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rhs-schedule.rb +117 -75
- data/lib/rhs-schedule/period.rb +2 -0
- data/lib/rhs-schedule/scheduleday.rb +9 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45d9d22b1f06bf65d5f7f19cbb0f865696c07088
|
4
|
+
data.tar.gz: 83e50e970284e01b6812b0b35e0600fa0a0dcefa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4935fae5a8bb3fa729b7b5e49be49b18958aef622af9192a401ed0b055e10b44d6bcf5ceafde6e4eb97718a76b60a796cdfd96db41021c9b3132fc371337578
|
7
|
+
data.tar.gz: 26dc3d276c130f0a6b552ce4233389478a66d1324c1edeb09a630090071acb2b6b96fe7e150f770c71a04e90f01cc2f6e7d8389248f3b2f3133c318b797339c0
|
data/lib/rhs-schedule.rb
CHANGED
@@ -3,8 +3,10 @@ require 'json'
|
|
3
3
|
|
4
4
|
require_relative 'rhs-schedule/scheduleday'
|
5
5
|
require_relative 'rhs-schedule/period'
|
6
|
+
require_relative 'rhs-schedule/exports'
|
7
|
+
require_relative 'rhs-schedule/errors'
|
6
8
|
|
7
|
-
VERSION = '0.
|
9
|
+
VERSION = '0.3.0'.freeze
|
8
10
|
|
9
11
|
# 05/25/16 08:50 AM
|
10
12
|
DATE_FORMAT = '%m/%d/%y'.freeze
|
@@ -13,8 +15,14 @@ DATETIME_FORMAT = "#{DATE_FORMAT} #{TIME_FORMAT}".freeze
|
|
13
15
|
EXCEPTIONS = ['0', '1', '2', '3', 'WEBEIM Scheduled', 'SIS Scheduled'].freeze
|
14
16
|
|
15
17
|
class ScheduleSystem
|
18
|
+
include Exports
|
19
|
+
|
16
20
|
attr_reader :schedule_days
|
17
21
|
|
22
|
+
# Creates a new ScheduleSystem by parsing the schedule text file passed to it.
|
23
|
+
# If it cannot read the file the program aborts.
|
24
|
+
#
|
25
|
+
# @param path [String] the path to the text file (not the folder!)
|
18
26
|
def initialize(path)
|
19
27
|
puts "Initializing Schedule System v#{VERSION}"
|
20
28
|
abort "Cannot find schedule text file at '#{path}'. Please download it from http://intranet.regis.org/downloads/outlook_calendar_import/outlook_schedule_download.cfm." unless File.file? path
|
@@ -23,8 +31,13 @@ class ScheduleSystem
|
|
23
31
|
@classdays = []
|
24
32
|
@schedule_days = {}
|
25
33
|
parse
|
34
|
+
super(self) # Initialize the exports with the parsed schedule
|
26
35
|
end
|
27
36
|
|
37
|
+
# Gets the schedule day of the date passed.
|
38
|
+
#
|
39
|
+
# @param date [Date, DateTime] the date
|
40
|
+
# @return [String] the schedule day
|
28
41
|
def get_sd date
|
29
42
|
if date.is_a? DateTime
|
30
43
|
@schedule_days[date]
|
@@ -34,102 +47,131 @@ class ScheduleSystem
|
|
34
47
|
end
|
35
48
|
end
|
36
49
|
|
50
|
+
# Displays formatted info on the current day, including it's schedule day and classes in order.
|
37
51
|
def today
|
38
52
|
#false_date = Date.strptime('05/20/16', DATE_FORMAT)
|
39
53
|
@classdays.find { |cd| cd.schedule_day == @schedule_days[Date.parse(Time.now.to_s)]}
|
40
54
|
#@classdays.find { |cd| cd.schedule_day == @schedule_days[false_date] }
|
41
55
|
end
|
42
56
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
# Split the line and remove all the unnecessary values
|
52
|
-
values = line.split("\t")
|
53
|
-
|
54
|
-
# Determine schedule day or period
|
55
|
-
if line.include? ' Day'
|
56
|
-
# Use only date and schedule day
|
57
|
-
vital = [values[0], values[4]]
|
58
|
-
sds << vital
|
59
|
-
elsif values.length == 10
|
60
|
-
# Use only date, start time, end time, class name, and location
|
61
|
-
vital = [values[0], values[1], values[3], values[4], values[5]]
|
62
|
-
ps << vital
|
63
|
-
end
|
64
|
-
end
|
57
|
+
# Outputs a JSON object of all class days and their schedule days into the given file.
|
58
|
+
#
|
59
|
+
# @param path [String] the file path
|
60
|
+
def to_json(path)
|
61
|
+
puts 'Exporting schedule days to JSON'
|
62
|
+
File.open(path,'w') do |f|
|
63
|
+
f.write(JSON.pretty_generate(@schedule.schedule_days))
|
65
64
|
end
|
65
|
+
end
|
66
66
|
|
67
|
-
|
67
|
+
private
|
68
|
+
def check_valid_schedule lines
|
69
|
+
# Check for headers
|
70
|
+
first_line = lines.first.strip
|
71
|
+
raise InvalidScheduleError, 'Correct headers are missing.' if first_line != 'Start Date Start Time End Date End Time Subject Location All day event Reminder on/off Show time as Categories'
|
68
72
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
+
# Check length of file
|
74
|
+
raise InvalidScheduleError, 'File has less than 200 lines.' if lines.length < 200
|
75
|
+
|
76
|
+
# Check if there are period lines and schedule day lines
|
77
|
+
expected = lines.length * 10 # Expected data over all split by tabs
|
78
|
+
actual = 0
|
79
|
+
lines.each { |l| actual += l.split("\t").length }
|
80
|
+
raise InvalidScheduleError, 'Not all lines are valid.' unless expected == actual
|
81
|
+
#raise InvalidScheduleError, 'Missing schedule day lines' unless lines
|
73
82
|
|
74
|
-
lines = ps.find_all { |values| values[0] == date.strftime(DATE_FORMAT) }
|
75
|
-
next if lines.empty?
|
76
|
-
create_class_day sd, lines
|
77
|
-
handled << sd
|
78
83
|
end
|
79
|
-
end
|
80
84
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
85
|
+
# Reads the schedule text file and parses each line to decide periods and schedule days.
|
86
|
+
def parse
|
87
|
+
sds = [] # Schedule day lines
|
88
|
+
ps = [] # Period lines
|
89
|
+
|
90
|
+
File.open(@path, 'r') do |f|
|
91
|
+
lines = f.read.split("\r")
|
92
|
+
|
93
|
+
check_valid_schedule lines
|
94
|
+
|
95
|
+
lines.each do |line|
|
96
|
+
next if line.include? 'Start Date' or line.strip.empty?
|
97
|
+
|
98
|
+
# Split the line and remove all the unnecessary values
|
99
|
+
values = line.split("\t")
|
100
|
+
|
101
|
+
# Determine schedule day or period
|
102
|
+
if line.include? ' Day'
|
103
|
+
# Use only date and schedule day
|
104
|
+
vital = [values[0], values[4]]
|
105
|
+
sds << vital
|
106
|
+
elsif values.length == 10
|
107
|
+
# Use only date, start time, end time, class name, and location
|
108
|
+
vital = [values[0], values[1], values[3], values[4], values[5]]
|
109
|
+
ps << vital
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
86
113
|
|
87
|
-
|
88
|
-
periods = []
|
89
|
-
lines.each do |values|
|
90
|
-
# [date, start time, end time, class name, location]
|
91
|
-
course_title = values[3]
|
92
|
-
start_time = DateTime.strptime(values[1], TIME_FORMAT)
|
93
|
-
end_time = DateTime.strptime(values[2], TIME_FORMAT)
|
94
|
-
location = values[4]
|
114
|
+
puts "Found #{ps.length} periods for #{sds.length} class days"
|
95
115
|
|
96
|
-
|
97
|
-
|
116
|
+
sds.each { |values| handle_schedule_day_line values }
|
117
|
+
handled = [] # Holds what schedules have been made
|
118
|
+
@schedule_days.each do |date, sd|
|
119
|
+
next if handled.include? sd
|
98
120
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
121
|
+
lines = ps.find_all { |values| values[0] == date.strftime(DATE_FORMAT) }
|
122
|
+
next if lines.empty?
|
123
|
+
create_class_day sd, lines
|
124
|
+
handled << sd
|
125
|
+
end
|
126
|
+
end
|
103
127
|
|
104
|
-
|
105
|
-
|
106
|
-
|
128
|
+
def handle_schedule_day_line values
|
129
|
+
date = Date.strptime(values[0], DATE_FORMAT)
|
130
|
+
sd = values[1][0] # A Day -> A
|
131
|
+
@schedule_days[date] = sd
|
132
|
+
end
|
107
133
|
|
108
|
-
|
109
|
-
|
134
|
+
def create_class_day sd, lines
|
135
|
+
periods = []
|
136
|
+
lines.each do |values|
|
137
|
+
# [date, start time, end time, class name, location]
|
138
|
+
course_title = values[3]
|
139
|
+
start_time = DateTime.strptime(values[1], TIME_FORMAT)
|
140
|
+
end_time = DateTime.strptime(values[2], TIME_FORMAT)
|
141
|
+
location = values[4]
|
110
142
|
|
111
|
-
|
112
|
-
|
113
|
-
filled << Period.new('Unstructured Time', last_end, p.start_time, 'Anywhere') if p.start_time != last_end # I <3 Ruby
|
143
|
+
periods << Period.new(course_title, start_time, end_time, location)
|
144
|
+
end
|
114
145
|
|
115
|
-
|
116
|
-
|
146
|
+
day = ScheduleDay.new(sd, periods)
|
147
|
+
fill_periods day
|
148
|
+
@classdays << day
|
117
149
|
end
|
118
150
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
end
|
151
|
+
# Take a just created periods list and fill in the holes (lunch and frees)
|
152
|
+
def fill_periods(day)
|
153
|
+
old = day.periods
|
123
154
|
|
124
|
-
|
125
|
-
|
126
|
-
day.periods = filled
|
127
|
-
end
|
155
|
+
# AM Advisement isn't in schedule text file
|
156
|
+
filled = [Period.new('Morning Advisement', DateTime.strptime('8:40 AM', TIME_FORMAT), DateTime.strptime('8:50 AM', TIME_FORMAT), 'Advisement')]
|
128
157
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
158
|
+
last_end = filled.first.end_time # Don't use old.first since the day could start with a free period
|
159
|
+
old.each do |p|
|
160
|
+
filled << Period.new('Unstructured Time', last_end, p.start_time, 'Anywhere') if p.start_time != last_end # I <3 Ruby
|
161
|
+
|
162
|
+
filled << p
|
163
|
+
last_end = p.end_time
|
164
|
+
end
|
165
|
+
|
166
|
+
if filled.last.end_time.strftime('%I:%M %p') != '02:50 PM'
|
167
|
+
end_time = DateTime.strptime('2:50 PM', TIME_FORMAT)
|
168
|
+
filled << Period.new('Unstructured Time', filled.last.end_time, end_time, 'Anywhere')
|
169
|
+
end
|
170
|
+
|
171
|
+
# PM Advisement isn't in schedule text file
|
172
|
+
filled << Period.new('Afternoon Advisement', DateTime.strptime('2:50 PM', TIME_FORMAT), DateTime.strptime('3:00 PM', TIME_FORMAT), 'Advisement')
|
173
|
+
day.periods = filled
|
133
174
|
end
|
134
|
-
|
175
|
+
|
176
|
+
|
135
177
|
end
|
data/lib/rhs-schedule/period.rb
CHANGED
@@ -9,14 +9,6 @@ class ScheduleDay
|
|
9
9
|
@periods = periods
|
10
10
|
end
|
11
11
|
|
12
|
-
def add_period(period)
|
13
|
-
@periods << period
|
14
|
-
end
|
15
|
-
|
16
|
-
def sort_periods
|
17
|
-
@periods.sort! { |a, b| a.start_time <=> b.start_time }
|
18
|
-
end
|
19
|
-
|
20
12
|
def to_s
|
21
13
|
to_return = ["#{@schedule_day}-Day: #{@periods.length} periods"]
|
22
14
|
@periods.each do |p|
|
@@ -26,4 +18,13 @@ class ScheduleDay
|
|
26
18
|
|
27
19
|
to_return.join("\n")
|
28
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def add_period(period)
|
24
|
+
@periods << period
|
25
|
+
end
|
26
|
+
|
27
|
+
def sort_periods
|
28
|
+
@periods.sort! { |a, b| a.start_time <=> b.start_time }
|
29
|
+
end
|
29
30
|
end
|