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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/cf/cli/line_yaml_validator.rb', line 4
def validate(yaml_path)
line_dump = YAML::load(File.read(yaml_path).strip)
errors = []
if line_dump['department'].nil?
errors << "The line Department is missing!"
end
input_formats = line_dump['input_formats']
if input_formats.nil?
errors << "The Input Format is missing!"
else
if input_formats.class == Array
input_formats.each_with_index do |input_format, index|
name = input_format['name']
required = input_format['required']
valid_type = input_format['valid_type']
if name.nil?
errors << "Input Format name is missing in Block #{index+1}!"
end
end
end
end
stations = line_dump['stations']
if stations.nil?
errors << "Station is missing!"
else
if stations.class == Array
if stations.first['station'].nil?
errors << "Station Settings missing!"
else
stations.each_with_index do |station, i|
station_index = station['station']['station_index']
errors << "Station Index is missing in Block station #{i+1}!" if station_index.nil?
station_type = station['station']['station_type']
errors << "Station type is missing in Block station #{i+1}!" if station_type.nil?
if station_type == "tournament"
jury_worker = station['station']['jury_worker']
auto_judge = station['station']['auto_judge']
errors << "Auto Judge enabled setting must be true in Block station #{i+1}!" if !auto_judge.nil? && auto_judge['enabled'] != true
if jury_worker.nil?
errors << "Jury worker setting is missing in Block station #{i+1}!"
elsif !jury_worker.nil?
reward = jury_worker['reward']
errors << "Reward for Jury worker is missing in block of Tournament Station #{i+1}!" if reward.nil?
end
acceptance_ratio = station['station']['acceptance_ratio']
if !acceptance_ratio.nil?
errors << "Acceptance ratio must lie between 0 and 1 in Block station #{i+1}!" if acceptance_ratio > 1 or acceptance_ratio < 0
end
end
worker = station['station']['worker']
if worker.class != Hash
errors << "Worker is missing in Block station #{i+1}!"
return errors
elsif worker.class == Hash
worker.each_pair do |k, v|
errors << "Should not be an array" if v.class == Array && k != "skill_badges"
end
worker_type = worker['worker_type']
if worker_type.nil?
errors << "Worker Type is missing!"
else
if worker_type != "human"
errors << "Worker type is invalid in Block station #{i+1}!" if worker_type.split("_").last != "robot"
if worker_type.split("_").last == "robot"
settings = worker['settings']
errors << "Settings for the robot worker is missing in Block station #{i+1}!" if settings.nil?
errors << "Settings for the robot worker is invalid in Block station #{i+1}!" if settings.class != Hash
end
elsif worker_type == "human"
num_workers = worker['num_workers']
if num_workers.nil?
errors << "Number of workers not specified in Block station #{i+1}!"
else
errors << "Number of workers must be greater than 0 in Block station #{i+1}!" if num_workers < 1
end
reward = worker['reward']
if reward.nil?
errors << "Reward of workers not specified in Block station #{i+1}!"
end
end
end
end
if station_type != "improve"
stat_badge = station['station']['worker']['stat_badge']
if !stat_badge.nil?
errors << "Stat badge setting is invalid in Block station #{i+1}!" if stat_badge.class != Hash
end
if worker_type == "human"
task_form = station['station']['task_form']
if task_form.nil?
custom_task_form = station['station']['custom_task_form']
if custom_task_form.nil?
errors << "Form is missing in Block station #{i+1}!"
elsif custom_task_form.class == Hash
form_title = custom_task_form['form_title']
errors << "Form Title is missing in Block station #{i+1}!" if form_title.nil?
instruction = custom_task_form['instruction']
errors << "Form Instruction is missing in Block station #{i+1}!" if instruction.nil?
errors << "station#{i+1}.html is missing in folder #{Dir.pwd} !" if !File.exist?("station#{i+1}.html")
end
elsif task_form.class == Hash
form_title = task_form['form_title']
errors << "Form Title is missing in Block station #{i+1}!" if form_title.nil?
instruction = task_form['instruction']
errors << "Form Instruction is missing in Block station #{i+1}!" if instruction.nil?
form_fields = task_form['form_fields']
errors << "Form Field is missing in Block station #{i+1}!" if form_fields.nil?
if form_fields.class == Array
form_fields.each_with_index do |form_field, index|
field_label = form_field['label']
errors << "Label is missing in block #{index+1} of Form Field within Station #{i+1}!" if field_label.nil?
required = form_field['required']
field_type = form_field['field_type']
if !field_type.nil?
unless %w(short_answer long_answer radio_button check_box select_box).include?(field_type)
errors << "Field Type of Form Field is invalid in Block #{index+1} of station Block #{i+1}!"
end
if field_type == "radio_button" || field_type == "select_box"
option_values = form_field['option_values']
if option_values.nil?
errors << "Option values is required for field_type => #{field_type} in block #{index+1} of Form Field within Station #{i+1} !"
elsif !option_values.nil?
if option_values.class != Array
errors << "Option values must be an array for field_type => #{field_type} in block #{index+1} of Form Field within Station #{i+1}!"
end
end
end
end
end
else
errors << "Form fields must be an array for Station #{i+1}!"
end
end
end
end
end
end
end
end
return errors
end
|