-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.rb
More file actions
executable file
·108 lines (84 loc) · 3.66 KB
/
test.rb
File metadata and controls
executable file
·108 lines (84 loc) · 3.66 KB
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
#!/usr/bin/ruby
require 'nokogiri'
doc = File.open('gogi.xml') { |f| Nokogiri::XML(f) }
starttime_arr = []
endtime_arr = []
doc.children[0].children[1].children.each do |x|
starttime_arr.append(x['starttime']) if !x['starttime'].nil?
endtime_arr.append(x['endtime']) if !x['endtime'].nil?
end
subjects = Hash.new
classes = Hash.new
teachers = Hash.new
classrooms = Hash.new
lessons = Hash.new # id: [classes, subject, num_of_periods, teachers, classroom]
doc.children[0].children[11].children.each do |x|
subjects[x['id']] = x['short']
end
doc.children[0].children[13].children.each do |x|
teachers[x['id']] = x['short']
end
doc.children[0].children[15].children.each do |x|
classrooms[x['id']] = x['short']
end
doc.children[0].children[19].children.each do |x|
classes[x['id']] = x['name']
end
teacherclasssubjects = Hash.new # {teacher: {class: [subjects] }}
doc.children[0].children[27].children.each do |x|
next if x['subjectid'].nil?
lessons[x['id']] = Array.new(5)
lessons[x['id']][0] = x['classids'].split(',').map { |c| classes[c] }
lessons[x['id']][1] = subjects[x['subjectid']]
lessons[x['id']][2] = x['periodspercard'].to_i
lessons[x['id']][3] = x['teacherids'].split(',').map { |t| teachers[t] }
lessons[x['id']][4] = x['classroomids'].split(',').map { |c| classrooms[c] }
x['teacherids'].split(',').each do |t|
teacherclasssubjects[teachers[t]] ||= Hash.new
x['classids'].split(',').each do |c|
teacherclasssubjects[teachers[t]][classes[c]] ||= Array.new
teacherclasssubjects[teachers[t]][classes[c]].push(subjects[x['subjectid']])
end
end
end
schedule = Hash.new # {class: week[day[period[subject]]]}
teacher_schedule = Hash.new # {teacher: week[day[period[class]]]}
doc.children[0].children[29].children.each do |x|
next if x['weeks'].nil?
puts lessons[x['lessonid']]
puts x['weeks']
puts x['days']
puts x['period']
puts ''
x['classroomids'].split(',').each do |c|
puts classrooms[c]
end
puts ''
less = lessons[x['lessonid']]
less[0].each do |c|
schedule[c] ||= Array.new(2)
schedule[c][x['weeks'].index('1')] ||= Array.new(5)
schedule[c][x['weeks'].index('1')][x['days'].index('1')] ||= Array.new(15)
schedule[c][x['weeks'].index('1')][x['days'].index('1')][x['period'].to_i] ||= ''
schedule[c][x['weeks'].index('1')][x['days'].index('1')][x['period'].to_i] += '/' if schedule[c][x['weeks'].index('1')][x['days'].index('1')][x['period'].to_i] != ''
schedule[c][x['weeks'].index('1')][x['days'].index('1')][x['period'].to_i] += less[1]
end
less[3].each do |t|
teacher_schedule[t] ||= Array.new(2)
teacher_schedule[t][x['weeks'].index('1')] ||= Array.new(5)
teacher_schedule[t][x['weeks'].index('1')][x['days'].index('1')] ||= Array.new(15)
teacher_schedule[t][x['weeks'].index('1')][x['days'].index('1')][x['period'].to_i] = less[0][0]
end
end
puts schedule
#doc.children[0].children[31].children.each do |x|
# next if x['DayID'].nil? || x['DayID'] == ''
# puts classes[x['ClassID']].to_s + ' ' + x['DayID'].to_s + ' ' + subjects[x['SubjectGradeID']].to_s + ' ' + x['Period'].to_s + ' ' + x['LengthID'].to_s
# final[classes[x['ClassID']]] ||= Hash.new
# final[classes[x['ClassID']]][x['DayID']] ||= Array.new(15)
# final[classes[x['ClassID']]][x['DayID']][x['Period'].to_i] = subjects[x['SubjectGradeID']] if x['Period'].to_i > 0
#end
# doc.children[0].children[27].children.each do |x|
# next if x['ClassID'].nil?
# puts subjects[x['SubjectGradeID']].to_s + ' ' + classes[x['ClassID']].to_s + ' ' + teachers[x['TeacherID']].to_s
# end