-
Notifications
You must be signed in to change notification settings - Fork 479
/
generate_fixtures.rb
executable file
·115 lines (101 loc) · 3.6 KB
/
generate_fixtures.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
#!/usr/bin/env ruby
require_relative '../config/environment'
scripts_map = {
'hour_of_code' => 'Hour of Code',
'events' => 'events',
'jigsaw' => 'jigsaw',
'hourofcode' => 'hourofcode',
'starwars' => 'starwars',
'frozen' => 'frozen',
'playlab' => 'playlab',
'artist' => 'artist',
'algebra' => 'algebra',
'flappy' => 'flappy',
'20-hour' => '20-hour',
'course1' => 'course1',
'course2' => 'course2',
'course3' => 'course3',
'course4' => 'course4',
'cspunit1' => 'cspunit1',
'cspunit2' => 'cspunit2',
'cspunit3' => 'cspunit3',
'cspunit4' => 'cspunit4',
'cspunit5' => 'cspunit5',
'cspunit6' => 'cspunit6',
'ECSPD' => 'ECSPD',
'allthethings' => 'allthethings',
'coursea-2017' => 'coursea-2017',
'courseb-2017' => 'courseb-2017',
'coursec-2017' => 'coursec-2017',
'coursed-2017' => 'coursed-2017',
'coursee-2017' => 'coursee-2017',
'coursef-2017' => 'coursef-2017',
'express-2017' => 'express-2017',
'pre-express-2017' => 'pre-express-2017'
}
@course_offerings = {}
@course_versions = {}
@unit_groups = {}
@plc_courses = {}
@scripts = {}
@plc_course_units = {}
@lesson_groups = {}
@lessons = {}
@script_levels = {}
@callouts = {}
scripts_map.each do |_script_id, name|
puts name
script = Unit.find_by_name name
@scripts[name] = script.attributes
script.unit_groups&.each do |unit_group|
@unit_groups[unit_group.name] = unit_group.attributes
end
course_version = script.get_course_version
if course_version
course_version_identifier = course_version.course_offering.key + '-' + course_version.key
@course_versions[course_version_identifier] = course_version.attributes
@course_offerings[course_version.course_offering.key] = course_version.course_offering.attributes
end
plc_course_unit = script.plc_course_unit
if plc_course_unit
plc_cu_attributes = plc_course_unit.attributes.clone
plc_cu_attributes.delete('id')
@plc_course_units[plc_course_unit.unit_name] = plc_cu_attributes
if plc_course_unit.plc_course
@plc_courses[plc_course_unit.plc_course.name] = plc_course_unit.plc_course.attributes
@unit_groups[plc_course_unit.plc_course.unit_group.name] = plc_course_unit.plc_course.unit_group.attributes
end
end
script.lesson_groups.each do |lesson_group|
@lesson_groups["lesson_group_#{lesson_group.id}"] = lesson_group.attributes
end
script.lessons.each do |lesson|
@lessons["lesson_#{lesson.id}"] = lesson.attributes
end
script.script_levels.to_a[0, 10000].each do |sl|
key = "script_level_#{sl.script_id}_#{sl.level_id}"
@script_levels[key] = sl.attributes.merge({"levels" => "level_#{sl.level_id}"})
sl.callouts.each do |c|
@callouts["callout_#{c.id}"] = c.attributes
end
end
end
def yamlize(hsh)
hsh.each do |_k, v|
if v.key? "properties"
v['properties'] = v['properties'].to_json
end
end
return hsh.to_yaml[4..]
end
prefix = Rails.root.join('test/fixtures/')
File.new("#{prefix}course_offerings.yml", 'w').write(yamlize(@course_offerings))
File.new("#{prefix}course_versions.yml", 'w').write(yamlize(@course_versions))
File.new("#{prefix}unit_groups.yml", 'w').write(yamlize(@unit_groups))
File.new("#{prefix}plc_courses.yml", 'w').write(yamlize(@plc_courses))
File.new("#{prefix}unit.yml", 'w').write(yamlize(@scripts))
File.new("#{prefix}plc_course_units.yml", 'w').write(yamlize(@plc_course_units))
File.new("#{prefix}lesson_group.yml", 'w').write(yamlize(@lesson_groups))
File.new("#{prefix}lesson.yml", 'w').write(yamlize(@lessons))
File.new("#{prefix}script_level.yml", 'w').write(yamlize(@script_levels))
File.new("#{prefix}callout.yml", 'w').write(yamlize(@callouts))