asker-tool 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/lib/asker/ai/ai.rb +6 -6
  4. data/lib/asker/ai/ai_calculate.rb +3 -3
  5. data/lib/asker/ai/code/base_code_ai.rb +5 -30
  6. data/lib/asker/ai/code/code_ai_factory.rb +6 -12
  7. data/lib/asker/ai/code/javascript_code_ai.rb +33 -34
  8. data/lib/asker/ai/code/python_code_ai.rb +35 -36
  9. data/lib/asker/ai/code/ruby_code_ai.rb +33 -33
  10. data/lib/asker/ai/code/sql_code_ai.rb +20 -21
  11. data/lib/asker/ai/concept_ai.rb +12 -22
  12. data/lib/asker/ai/problem/problem_ai.rb +226 -0
  13. data/lib/asker/ai/question.rb +34 -45
  14. data/lib/asker/ai/stages/base_stage.rb +7 -7
  15. data/lib/asker/ai/stages/stage_b.rb +62 -28
  16. data/lib/asker/ai/stages/stage_d.rb +10 -10
  17. data/lib/asker/ai/stages/stage_f.rb +17 -17
  18. data/lib/asker/ai/stages/stage_i.rb +8 -18
  19. data/lib/asker/ai/stages/stage_s.rb +28 -26
  20. data/lib/asker/ai/stages/stage_t.rb +40 -51
  21. data/lib/asker/application.rb +15 -14
  22. data/lib/asker/check_input/check_haml_data.rb +52 -51
  23. data/lib/asker/check_input/check_table.rb +17 -20
  24. data/lib/asker/check_input.rb +10 -23
  25. data/lib/asker/cli.rb +43 -24
  26. data/lib/asker/data/code.rb +10 -9
  27. data/lib/asker/data/column.rb +21 -17
  28. data/lib/asker/data/concept.rb +24 -37
  29. data/lib/asker/data/data_field.rb +2 -2
  30. data/lib/asker/data/problem.rb +112 -0
  31. data/lib/asker/data/project_data.rb +11 -15
  32. data/lib/asker/data/row.rb +25 -23
  33. data/lib/asker/data/table.rb +25 -46
  34. data/lib/asker/data/template.rb +7 -7
  35. data/lib/asker/data/world.rb +3 -3
  36. data/lib/asker/{formatter → deprecated}/question_moodlexml_formatter.rb +19 -21
  37. data/lib/asker/displayer/code_displayer.rb +10 -10
  38. data/lib/asker/displayer/concept_ai_displayer.erb +1 -1
  39. data/lib/asker/displayer/concept_ai_displayer.rb +16 -16
  40. data/lib/asker/displayer/concept_displayer.rb +4 -2
  41. data/lib/asker/displayer/problem_displayer.rb +45 -0
  42. data/lib/asker/displayer/stats_displayer.rb +7 -12
  43. data/lib/asker/exporter/code_gift_exporter.rb +2 -2
  44. data/lib/asker/exporter/concept_ai_gift_exporter.rb +4 -4
  45. data/lib/asker/exporter/concept_ai_yaml_exporter.rb +7 -7
  46. data/lib/asker/exporter/concept_doc_exporter.rb +5 -5
  47. data/lib/asker/exporter/data_gift_exporter.rb +14 -15
  48. data/lib/asker/exporter/data_moodle_exporter.rb +51 -20
  49. data/lib/asker/exporter/output_file_exporter.rb +9 -8
  50. data/lib/asker/exporter/problem_gift_exporter.rb +30 -0
  51. data/lib/asker/files/language/ca/templates.yaml +6 -0
  52. data/lib/asker/files/language/du/templates.yaml +6 -0
  53. data/lib/asker/files/language/en/templates.yaml +7 -1
  54. data/lib/asker/files/language/es/templates.yaml +6 -0
  55. data/lib/asker/files/language/fr/templates.yaml +6 -0
  56. data/lib/asker/formatter/code_string_formatter.rb +5 -5
  57. data/lib/asker/formatter/concept_doc_formatter.rb +3 -3
  58. data/lib/asker/formatter/concept_string_formatter.rb +6 -6
  59. data/lib/asker/formatter/moodle/ddmatch.erb +40 -0
  60. data/lib/asker/formatter/moodle/gapfill.erb +57 -0
  61. data/lib/asker/formatter/moodle/ordering.erb +41 -0
  62. data/lib/asker/formatter/question_gift_formatter.rb +41 -14
  63. data/lib/asker/formatter/question_hash_formatter.rb +5 -6
  64. data/lib/asker/formatter/question_moodle_formatter.rb +14 -7
  65. data/lib/asker/formatter/rb2haml_formatter.rb +8 -7
  66. data/lib/asker/lang/lang.rb +16 -16
  67. data/lib/asker/lang/lang_factory.rb +13 -16
  68. data/lib/asker/lang/text_actions.rb +20 -18
  69. data/lib/asker/loader/code_loader.rb +10 -22
  70. data/lib/asker/loader/content_loader.rb +42 -49
  71. data/lib/asker/loader/directory_loader.rb +13 -16
  72. data/lib/asker/loader/embedded_file.rb +14 -14
  73. data/lib/asker/loader/file_loader.rb +5 -4
  74. data/lib/asker/loader/haml_loader.rb +4 -3
  75. data/lib/asker/loader/image_url_loader.rb +6 -5
  76. data/lib/asker/loader/input_loader.rb +24 -10
  77. data/lib/asker/loader/problem_loader.rb +88 -0
  78. data/lib/asker/loader/project_loader.rb +5 -12
  79. data/lib/asker/logger.rb +19 -10
  80. data/lib/asker/skeleton.rb +19 -35
  81. data/lib/asker/start.rb +44 -0
  82. data/lib/asker/version.rb +1 -1
  83. data/lib/asker.rb +7 -52
  84. metadata +12 -6
  85. data/lib/asker/ai/code/problem_code_ai.rb +0 -176
  86. data/lib/asker/exporter/code_moodle_exporter.rb +0 -15
  87. data/lib/asker/exporter/concept_ai_moodle_exporter.rb +0 -15
@@ -1,176 +0,0 @@
1
-
2
- require_relative '../../lang/lang_factory'
3
- require_relative '../../ai/question'
4
- require_relative 'base_code_ai'
5
-
6
- ##
7
- # Class for RubyCodeAI objects
8
- class ProblemCodeAI < BaseCodeAI
9
- def initialize(code)
10
- @reduce = 1
11
- @reduce = 4 if code.lines.size > 25
12
- @lang = LangFactory.instance.get('es')
13
- super code
14
- end
15
-
16
- ##
17
- # Make errors about comments
18
- def make_comment_error
19
- questions = []
20
- # error_lines = []
21
- @lines.each_with_index do |line,index|
22
- if line.strip.start_with?('#')
23
- lines = clone_array @lines
24
- lines[index].sub!('#','').strip!
25
-
26
- q = Question.new(:short)
27
- q.name = "#{name}-#{num}-uncomment"
28
- q.text = @lang.text_for(:code1,lines_to_html(lines))
29
- q.shorts << (index+1)
30
- q.feedback = 'Comment symbol removed'
31
- questions << q
32
- elsif line.strip.size>0
33
- lines = clone_array @lines
34
- lines[index]='# ' + lines[index]
35
-
36
- q = Question.new(:short)
37
- q.name = "#{name}-#{num}-comment"
38
- q.text = @lang.text_for(:code1,lines_to_html(lines))
39
- q.shorts << (index+1)
40
- q.feedback = 'Comment symbol added'
41
- questions << q
42
- end
43
- end
44
- questions.shuffle[0,@lines.size/@reduce]
45
- end
46
-
47
- ##
48
- # Make questions without errors
49
- def make_no_error_changes
50
- questions = []
51
- empty_lines = []
52
- used_lines = []
53
- @lines.each_with_index do |line,index|
54
- if line.strip.size.zero?
55
- empty_lines << index
56
- else
57
- used_lines << index
58
- end
59
- end
60
-
61
- used_lines.each do |index|
62
- lines = clone_array(@lines)
63
- lines.insert(index, ' ' * (rand(4).to_i + 1))
64
- if @lines.size < 4 || rand(2) == 0
65
- q = Question.new(:short)
66
- q.name = "#{name}-#{num}-codeok"
67
- q.text = @lang.text_for(:code1,lines_to_html(lines))
68
- q.shorts << '0'
69
- q.feedback = 'Code is OK'
70
- questions << q
71
- else
72
- q = Question.new(:choice)
73
- q.name = "#{name}-#{num}-codeok"
74
- q.text = @lang.text_for(:code2,lines_to_html(lines))
75
- others = (1..@lines.size).to_a.shuffle!
76
- q.good = '0'
77
- q.bads << others[0].to_s
78
- q.bads << others[1].to_s
79
- q.bads << others[2].to_s
80
- q.feedback = 'Code is OK'
81
- end
82
- end
83
-
84
- questions.shuffle[0,@lines.size/@reduce]
85
- end
86
-
87
- ##
88
- # Make questions with syntax errors
89
- def make_syntax_error
90
- questions = []
91
-
92
- @lang.mistakes.each_pair do |key,values|
93
- error_lines = []
94
- @lines.each_with_index do |line,index|
95
- error_lines << index if line.include?(key.to_s)
96
- end
97
-
98
- v = values.split(',')
99
- v.each do |value|
100
- error_lines.each do |index|
101
- lines = clone_array(@lines)
102
- lines[index].sub!(key.to_s, value)
103
- if @lines.size < 4 || rand(2) == 0
104
- q = Question.new(:short)
105
- q.name = "#{name}-#{num}-syntaxerror"
106
- q.text = @lang.text_for(:code1,lines_to_html(lines))
107
- q.shorts << (index+1)
108
- q.feedback = "Syntax error: '#{value}' must be '#{key}'"
109
- else
110
- q = Question.new(:choice)
111
- q.name = "#{name}-#{num}-syntaxerror"
112
- q.text = @lang.text_for(:code2,lines_to_html(lines))
113
- others = (1..@lines.size).to_a.shuffle!
114
- others.delete(index+1)
115
- q.good = (index + 1).to_s
116
- q.bads << others[0].to_s
117
- q.bads << others[1].to_s
118
- q.bads << others[2].to_s
119
- q.feedback = "Syntax error: '#{value}' must be '#{key}'"
120
- end
121
- questions << q
122
- end
123
- end
124
- end
125
- questions.shuffle[0,@lines.size/@reduce]
126
- end
127
-
128
- ##
129
- # Make questions with variable errors
130
- def make_variable_error
131
- questions = []
132
- # error_lines = []
133
- @lines.each_with_index do |line, index|
134
- # Search Variable assignment
135
- m = /\s*(\w*)\s*\=\w*/.match(line)
136
- i = []
137
- unless m.nil?
138
- varname = (m.values_at 1)[0]
139
- # Search used Variable
140
- @lines.each_with_index do |line2, index2|
141
- next if index >= index2
142
- i << index2 if line2.include?(varname)
143
- end
144
- end
145
- next if i.size == 0
146
- i.shuffle!
147
- i.each do |k|
148
- lines = clone_array @lines
149
- temp = lines[index]
150
- lines[index] = lines[k]
151
- lines[k] = temp
152
-
153
- if rand(2) == 0
154
- q = Question.new(:short)
155
- q.name = "#{name}-#{num}-variable"
156
- q.text = @lang.text_for(:code1, lines_to_html(lines))
157
- q.shorts << (index + 1)
158
- q.feedback = "Variable error! Swapped lines #{(index+1)} with #{(k+1)}"
159
- else
160
- q = Question.new(:choice)
161
- q.name = "#{name}-#{num}-variable"
162
- q.text = @lang.text_for(:code2, lines_to_html(lines))
163
- others = (1..@lines.size).to_a.shuffle!
164
- others.delete(index+1)
165
- q.good = (index + 1).to_s
166
- q.bads << others[0].to_s
167
- q.bads << others[1].to_s
168
- q.bads << others[2].to_s
169
- q.feedback = "Variable error! Swapped lines #{(index+1)} with #{(k+1)}"
170
- end
171
- questions << q
172
- end
173
- end
174
- questions.shuffle[0,@lines.size/@reduce]
175
- end
176
- end
@@ -1,15 +0,0 @@
1
-
2
- require_relative '../formatter/question_moodle_formatter'
3
-
4
- module CodeMoodleExporter
5
-
6
- def self.run(code, file)
7
- return false unless code.process?
8
-
9
- code.questions.each do |question|
10
- file.write QuestionMoodleFormatter.to_s(question)
11
- end
12
- true
13
- end
14
-
15
- end
@@ -1,15 +0,0 @@
1
-
2
- require_relative '../formatter/question_moodle_formatter'
3
-
4
- module ConceptAIMoodleExporter
5
-
6
- def self.run(concept_ai, file)
7
- return unless concept_ai.concept.process?
8
-
9
- Application.instance.config['questions']['stages'].each do |stage|
10
- concept_ai.questions[stage].each do |question|
11
- file.write(QuestionMoodleFormatter.to_s(question))
12
- end
13
- end
14
- end
15
- end