Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
schedules
Commits
212e258a
Commit
212e258a
authored
Apr 07, 2018
by
Zac Wood
Browse files
Added data + DB seed script
parent
6968dd63
Changes
5
Hide whitespace changes
Inline
Side-by-side
schedules/Gemfile
View file @
212e258a
...
...
@@ -52,3 +52,5 @@ end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem
'tzinfo-data'
,
platforms:
[
:mingw
,
:mswin
,
:x64_mingw
,
:jruby
]
gem
'rubyXL'
\ No newline at end of file
schedules/db/data/allsections.xlsx
0 → 100644
View file @
212e258a
File added
schedules/db/data/small.xlsx
0 → 100644
View file @
212e258a
File added
schedules/db/schema.rb
0 → 100644
View file @
212e258a
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
20180407190750
)
do
create_table
"courses"
,
force: :cascade
do
|
t
|
t
.
string
"subject"
t
.
string
"course_number"
t
.
integer
"semester_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
index
[
"semester_id"
],
name:
"index_courses_on_semester_id"
end
create_table
"sections"
,
force: :cascade
do
|
t
|
t
.
string
"name"
t
.
string
"crn"
t
.
string
"section_type"
t
.
string
"title"
t
.
string
"instructor"
t
.
date
"start_date"
t
.
date
"end_date"
t
.
string
"days"
t
.
string
"start_time"
t
.
string
"end_time"
t
.
string
"location"
t
.
string
"status"
t
.
string
"campus"
t
.
string
"notes"
t
.
integer
"size_limit"
t
.
integer
"course_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
index
[
"course_id"
],
name:
"index_sections_on_course_id"
end
create_table
"semesters"
,
force: :cascade
do
|
t
|
t
.
string
"season"
t
.
string
"year"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
end
end
schedules/db/seeds.rb
View file @
212e258a
...
...
@@ -5,3 +5,98 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
require
'rubyXL'
# Open the data file...this takes a while
workbook
=
RubyXL
::
Parser
.
parse
(
'db/data/allsections.xlsx'
)
rows
=
workbook
[
0
]
puts
'Done parsing!'
# The first 16 rows are not actual data, so remove them
rows
=
rows
.
drop
(
16
)
# Keep track of the course each section is for
current_course
=
nil
# Create the Semester object that all courses will belong to
semester
=
Semester
.
create
season:
"Fall"
,
year:
"2018"
semester
.
save
# Loop through all the rows in the date
rows
.
each
do
|
row
|
# Get all the info out of the current row
course_name
=
row
&
.
cells
[
1
]
&
.
value
section_name
=
row
&
.
cells
[
2
]
&
.
value
crn
=
row
&
.
cells
[
6
]
&
.
value
schedule_type
=
row
&
.
cells
[
8
]
&
.
value
section_title
=
row
&
.
cells
[
11
]
&
.
value
instructor
=
row
&
.
cells
[
16
]
&
.
value
start_date
=
row
&
.
cells
[
18
]
&
.
value
end_date
=
row
&
.
cells
[
21
]
&
.
value
days
=
row
&
.
cells
[
22
]
&
.
value
times
=
row
&
.
cells
[
23
]
&
.
value
location
=
row
&
.
cells
[
25
]
&
.
value
# Ensure the course name is valid
if
course_name
&&
!
course_name
.
empty?
&&
course_name
!=
'Total'
# Split the name into its two components, i.e. "CS 112" => ["CS", "112"]
name_components
=
course_name
.
split
(
' '
)
# Create and save the course, and set it to be the current_course
current_course
=
Course
.
create
subject:
name_components
[
0
],
course_number:
name_components
[
1
],
semester:
semester
current_course
.
save
puts
"Created course named:
#{
current_course
.
subject
}
#{
current_course
.
course_number
}
"
end
# If there is no valid section name, just continue to the next row
if
!
section_name
||
section_name
&
.
empty?
||
section_name
==
'Total'
next
else
# Create the new section
section
=
Section
.
new
# Add all fields to the section, ensuring each is valid
section
.
name
=
section_name
section
.
course
=
current_course
if
crn
section
.
crn
=
crn
end
if
schedule_type
section
.
section_type
=
schedule_type
end
if
section_title
section
.
title
=
section_title
end
if
instructor
section
.
instructor
=
instructor
end
if
start_date
section
.
start_date
=
start_date
end
if
end_date
section
.
end_date
=
end_date
end
if
days
section
.
days
=
days
end
if
times
# The time field in the spreadsheet uses the format "start_time - end_time" i.e. "12:00 PM - 1:15 PM".
# So, split the times string by the - character
time_strs
=
times
.
split
(
'-'
)
section
.
start_time
=
time_strs
[
0
].
strip
section
.
end_date
=
time_strs
[
1
].
strip
end
if
location
section
.
location
=
location
end
# Save the section to the database
section
.
save
puts
"Created section for named
#{
section
.
name
}
"
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment