Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrations #54

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions db/20240911151440_add_school_staff_ids.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddSchoolStaffIds < ActiveRecord::Migration[5.2]
def change
add_column :pupils, :school_id, :string, default: "", null: false
add_column :staffs, :user_code, :string, default: "", null: false
end
end
6 changes: 4 additions & 2 deletions lib/import/misimport/mispupil.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class MIS_Pupil < MIS_Record
:email,
:house_name,
:current,
:datasource_id
:datasource_id,
:school_id
]

FIELDS_TO_UPDATE = [
Expand All @@ -29,7 +30,8 @@ class MIS_Pupil < MIS_Record
:known_as,
:email,
:house_name,
:current
:current,
:school_id
]

def force_save
Expand Down
6 changes: 4 additions & 2 deletions lib/import/misimport/misstaff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ class MIS_Staff < MIS_Record
:email,
:active,
:current,
:datasource_id]
:datasource_id,
:user_code]
FIELDS_TO_UPDATE = [:name,
:initials,
:surname,
:title,
:forename,
:email,
:active,
:current]
:current,
:user_code]

#
# The MIS-specific code should override everything below here.
Expand Down
128 changes: 128 additions & 0 deletions lib/import/socsmusic/options.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
require 'optparse'
require 'optparse/date'

class Options
attr_reader :event_category_name, :verbose, :start_date, :end_date

def initialize
@event_category_name = "Lesson"
@verbose = false
@start_date = nil
@end_date = nil

parser = OptionParser.new do |opts|
opts.banner = "Usage: music_import.rb [options]"

opts.on("-c", "--category [EVENTCATEGORY]",
"Specify the name of the event category",
"to be used for all the fixtures.",
"Defaults to \"Music\".") do |name|
@event_category_name = name
end

opts.on("-s", "--start_date [DATE]", "Specify the start date (e.g. 2024-09-05)") do |date|
@start_date = Date.parse(date)
end

opts.on("-e", "--end_date [DATE]", "Specify the end date (e.g. 2024-09-06)") do |date|
@end_date = Date.parse(date)
end

opts.on("-v", "--verbose",
"Run with verbose output") do
@verbose = true
end

opts.on("-h", "--help", "Show this message") do
puts opts
exit
end
end

parse_options(parser)
end

private

def parse_options(parser)
begin
parser.parse!
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
puts e.message
puts parser
exit 1
rescue SystemExit
# Allow SystemExit to propagate for clean exit
raise
rescue StandardError => e
puts "An error occurred: #{e.message}"
puts parser
exit 1
end
end
end

scheduler@devxronos:~/Work/Coding/scheduler/lib/import/socsmusic$ cat options.rb
require 'optparse'
require 'optparse/date'

class Options
attr_reader :event_category_name, :verbose, :start_date, :end_date

def initialize
@event_category_name = "Lesson"
@verbose = false
@start_date = nil
@end_date = nil

parser = OptionParser.new do |opts|
opts.banner = "Usage: music_import.rb [options]"

opts.on("-c", "--category [EVENTCATEGORY]",
"Specify the name of the event category",
"to be used for all the fixtures.",
"Defaults to \"Music\".") do |name|
@event_category_name = name
end

opts.on("-s", "--start_date [DATE]", "Specify the start date (e.g. 2024-09-05)") do |date|
@start_date = Date.parse(date)
end

opts.on("-e", "--end_date [DATE]", "Specify the end date (e.g. 2024-09-06)") do |date|
@end_date = Date.parse(date)
end

opts.on("-v", "--verbose",
"Run with verbose output") do
@verbose = true
end

opts.on("-h", "--help", "Show this message") do
puts opts
exit
end
end

parse_options(parser)
end

private

def parse_options(parser)
begin
parser.parse!
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
puts e.message
puts parser
exit 1
rescue SystemExit
# Allow SystemExit to propagate for clean exit
raise
rescue StandardError => e
puts "An error occurred: #{e.message}"
puts parser
exit 1
end
end
end
48 changes: 48 additions & 0 deletions lib/import/socsmusic/socsmusic_lessons.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# app/models/music_fixture.rb
class MusicFixture
attr_reader :lesson_id, :instrument, :title, :starts_at, :ends_at, :location, :staff_id, :pupil_id, :attendance
def initialize(xml_node)
@lesson_id = xml_node.at_xpath('lessonid').text
start_date = xml_node.at_xpath('startdate').text
start_time = xml_node.at_xpath('starttime').text
end_time = xml_node.at_xpath('endtime').text
@instrument = xml_node.at_xpath('instrument').text
@title = xml_node.at_xpath('title').text
@starts_at = Time.parse("#{start_date} #{start_time}")
@ends_at = Time.parse("#{start_date} #{end_time}")
@location = xml_node.at_xpath('location').text
@staff_id = xml_node.at_xpath('staffid').text
@pupil_id = xml_node.at_xpath('pupilid').text
@attendance = xml_node.at_xpath('attendance').text
end
def home_location
@location
end
def away?
# If there's a need to define "away" logic, it can be based on location or other attributes
false
end
end
# app/models/music_fixture_set.rb
class MusicFixtureSet
attr_reader :fixtures
def initialize(xml, options = {})
@fixtures = xml.xpath('//lesson').map { |node| MusicFixture.new(node) }
@options = options
end
def empty?
@fixtures.empty?
end
def fixtures_on(date)
@fixtures.select { |f| f.starts_at.to_date == date }
end
def last_date
@fixtures.map(&:starts_at).max.to_date
end
def instruments
@fixtures.map(&:instrument).uniq
end
def home_locations
@fixtures.map(&:home_location).uniq
end
end
Loading