asker-tool 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -19
  3. data/bin/asker +2 -1
  4. data/lib/asker/ai/ai.rb +10 -3
  5. data/lib/asker/ai/ai_calculate.rb +20 -6
  6. data/lib/asker/ai/code/base_code_ai.rb +104 -0
  7. data/lib/asker/{code/ai → ai/code}/code_ai_factory.rb +11 -1
  8. data/lib/asker/{code/ai → ai/code}/javascript_code_ai.rb +2 -5
  9. data/lib/asker/ai/code/problem_code_ai.rb +176 -0
  10. data/lib/asker/{code/ai → ai/code}/python_code_ai.rb +2 -5
  11. data/lib/asker/{code/ai → ai/code}/ruby_code_ai.rb +14 -7
  12. data/lib/asker/{code/ai → ai/code}/sql_code_ai.rb +2 -5
  13. data/lib/asker/ai/concept_ai.rb +12 -2
  14. data/lib/asker/ai/question.rb +28 -6
  15. data/lib/asker/ai/stages/base_stage.rb +45 -6
  16. data/lib/asker/ai/stages/stage_b.rb +100 -50
  17. data/lib/asker/ai/stages/stage_d.rb +75 -90
  18. data/lib/asker/ai/stages/stage_f.rb +64 -36
  19. data/lib/asker/ai/stages/stage_i.rb +79 -92
  20. data/lib/asker/ai/stages/stage_s.rb +41 -36
  21. data/lib/asker/ai/stages/stage_t.rb +149 -108
  22. data/lib/asker/application.rb +24 -7
  23. data/lib/asker/checker.rb +149 -52
  24. data/lib/asker/cli.rb +37 -32
  25. data/lib/asker/data/code.rb +76 -0
  26. data/lib/asker/data/column.rb +31 -21
  27. data/lib/asker/data/concept.rb +108 -65
  28. data/lib/asker/data/data_field.rb +14 -0
  29. data/lib/asker/data/row.rb +75 -52
  30. data/lib/asker/data/table.rb +91 -42
  31. data/lib/asker/data/template.rb +3 -1
  32. data/lib/asker/data/world.rb +61 -32
  33. data/lib/asker/{exporter/code_screen_exporter.rb → displayer/code_displayer.rb} +13 -6
  34. data/lib/asker/displayer/concept_ai_displayer.erb +10 -0
  35. data/lib/asker/displayer/concept_ai_displayer.rb +133 -0
  36. data/lib/asker/displayer/concept_displayer.rb +34 -0
  37. data/lib/asker/displayer/stats_displayer.rb +22 -0
  38. data/lib/asker/exporter/code_gift_exporter.rb +10 -11
  39. data/lib/asker/exporter/concept_ai_gift_exporter.rb +21 -13
  40. data/lib/asker/exporter/concept_ai_moodle_exporter.rb +44 -0
  41. data/lib/asker/exporter/concept_ai_yaml_exporter.rb +14 -9
  42. data/lib/asker/exporter/concept_doc_exporter.rb +21 -14
  43. data/lib/asker/exporter/data_gift_exporter.rb +29 -0
  44. data/lib/asker/exporter/output_file_exporter.rb +21 -0
  45. data/lib/asker/files/{config.ini → asker.ini} +48 -1
  46. data/lib/asker/files/example-concept.haml +24 -8
  47. data/lib/asker/files/language/du/connectors.yaml +81 -0
  48. data/lib/asker/files/language/du/mistakes.yaml +82 -0
  49. data/lib/asker/files/language/du/templates.yaml +29 -0
  50. data/lib/asker/files/language/en/connectors.yaml +44 -0
  51. data/lib/asker/files/language/en/mistakes.yaml +37 -0
  52. data/lib/asker/files/language/en/templates.yaml +29 -0
  53. data/lib/asker/files/language/es/connectors.yaml +92 -0
  54. data/lib/asker/files/language/es/mistakes.yaml +84 -0
  55. data/lib/asker/files/language/es/templates.yaml +29 -0
  56. data/lib/asker/files/language/fr/connectors.yaml +76 -0
  57. data/lib/asker/files/language/fr/mistakes.yaml +82 -0
  58. data/lib/asker/files/language/fr/templates.yaml +29 -0
  59. data/lib/asker/files/language/javascript/connectors.yaml +11 -0
  60. data/lib/asker/files/language/javascript/mistakes.yaml +30 -0
  61. data/lib/asker/files/language/javascript/templates.yaml +3 -0
  62. data/lib/asker/files/language/math/connectors.yaml +2 -0
  63. data/lib/asker/files/language/math/mistakes.yaml +2 -0
  64. data/lib/asker/files/language/math/templates.yaml +1 -0
  65. data/lib/asker/files/language/python/connectors.yaml +11 -0
  66. data/lib/asker/files/language/python/mistakes.yaml +26 -0
  67. data/lib/asker/files/language/python/templates.yaml +3 -0
  68. data/lib/asker/files/language/ruby/connectors.yaml +11 -0
  69. data/lib/asker/files/language/ruby/mistakes.yaml +33 -0
  70. data/lib/asker/files/language/ruby/templates.yaml +3 -0
  71. data/lib/asker/files/language/sql/connectors.yaml +6 -0
  72. data/lib/asker/files/language/sql/mistakes.yaml +11 -0
  73. data/lib/asker/files/language/sql/templates.yaml +2 -0
  74. data/lib/asker/formatter/concept_string_formatter.rb +13 -9
  75. data/lib/asker/formatter/moodle/matching.erb +38 -0
  76. data/lib/asker/formatter/moodle/multichoice.erb +49 -0
  77. data/lib/asker/formatter/moodle/shortanswer.erb +30 -0
  78. data/lib/asker/formatter/moodle/truefalse.erb +47 -0
  79. data/lib/asker/formatter/question_gift_formatter.rb +30 -20
  80. data/lib/asker/formatter/question_moodle_formatter.rb +27 -0
  81. data/lib/asker/lang/lang.rb +18 -12
  82. data/lib/asker/lang/lang_factory.rb +32 -5
  83. data/lib/asker/lang/text_actions.rb +87 -69
  84. data/lib/asker/loader/code_loader.rb +4 -4
  85. data/lib/asker/loader/content_loader.rb +16 -12
  86. data/lib/asker/loader/directory_loader.rb +3 -3
  87. data/lib/asker/loader/embedded_file.rb +42 -0
  88. data/lib/asker/loader/file_loader.rb +3 -12
  89. data/lib/asker/loader/haml_loader.rb +15 -0
  90. data/lib/asker/loader/image_url_loader.rb +9 -11
  91. data/lib/asker/loader/input_loader.rb +24 -8
  92. data/lib/asker/loader/project_loader.rb +42 -30
  93. data/lib/asker/logger.rb +30 -6
  94. data/lib/asker/project.rb +28 -117
  95. data/lib/asker/skeleton.rb +40 -29
  96. data/lib/asker.rb +68 -79
  97. metadata +57 -74
  98. data/docs/changelog/v2.1.md +0 -99
  99. data/docs/commands.md +0 -12
  100. data/docs/contributions.md +0 -18
  101. data/docs/history.md +0 -40
  102. data/docs/idea.md +0 -44
  103. data/docs/inputs/README.md +0 -39
  104. data/docs/inputs/code.md +0 -69
  105. data/docs/inputs/concepts.md +0 -142
  106. data/docs/inputs/jedi.md +0 -68
  107. data/docs/inputs/tables.md +0 -112
  108. data/docs/inputs/templates.md +0 -87
  109. data/docs/install/README.md +0 -38
  110. data/docs/install/manual.md +0 -26
  111. data/docs/install/scripts.md +0 -38
  112. data/docs/revise/asker-file.md +0 -41
  113. data/docs/revise/buenas-practicas/01-convocatoria.md +0 -30
  114. data/docs/revise/buenas-practicas/02-formulario.md +0 -35
  115. data/docs/revise/buenas-practicas/03-descripcion.md +0 -63
  116. data/docs/revise/buenas-practicas/04-resultados.md +0 -17
  117. data/docs/revise/buenas-practicas/05-reproducir.md +0 -10
  118. data/docs/revise/ejemplos/01/README.md +0 -27
  119. data/docs/revise/ejemplos/02/README.md +0 -31
  120. data/docs/revise/ejemplos/03/README.md +0 -31
  121. data/docs/revise/ejemplos/04/README.md +0 -37
  122. data/docs/revise/ejemplos/05/README.md +0 -25
  123. data/docs/revise/ejemplos/06/README.md +0 -43
  124. data/docs/revise/ejemplos/README.md +0 -11
  125. data/docs/revise/projects.md +0 -74
  126. data/lib/asker/code/ai/base_code_ai.rb +0 -48
  127. data/lib/asker/code/code.rb +0 -53
  128. data/lib/asker/exporter/concept_ai_screen_exporter.rb +0 -115
  129. data/lib/asker/exporter/concept_screen_exporter.rb +0 -25
  130. data/lib/asker/exporter/main.rb +0 -9
@@ -1,13 +1,20 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  require_relative 'base_stage'
3
4
  require_relative '../question'
4
5
 
5
6
  # StageF: process tables with 1 field
7
+ # rubocop:disable Metrics/ClassLength
6
8
  class StageF < BaseStage
9
+ ##
10
+ # run stage_f: generate guqestion for tables with 1 field
11
+ # @param table (Table)
12
+ # @param list1 (Array) List of Rows from this table
13
+ # @param list2 (Array) List of Row from other tables
7
14
  def run(table, list1, list2)
8
15
  # process_table1field
9
16
  questions = []
10
- return questions if table.fields.count>1
17
+ return questions if table.fields.count > 1
11
18
 
12
19
  questions += run_only_this_concept(table, list1)
13
20
  questions += run_with_other_concepts(table, list1, list2)
@@ -15,29 +22,32 @@ class StageF < BaseStage
15
22
  questions
16
23
  end
17
24
 
18
- private
25
+ private
19
26
 
27
+ # rubocop:disable Metrics/AbcSize
28
+ # rubocop:disable Metrics/MethodLength
20
29
  def run_only_this_concept(table, list1)
21
30
  questions = []
22
- s1 = Set.new #Set of rows from this concept
31
+ lang = concept.lang
32
+ s1 = Set.new # Set of rows from this concept
23
33
  list1.each { |item| s1 << item[:data][0] }
24
34
  a1 = s1.to_a
25
35
  a1.shuffle!
26
36
 
27
37
  if a1.size > 3
28
- a1.each_cons(4) do |e1,e2,e3,e4|
29
- e = [ e1, e2, e3, e4 ]
38
+ a1.each_cons(4) do |e1, e2, e3, e4|
39
+ e = [e1, e2, e3, e4]
30
40
  questions += make_questions_with(e, table)
31
41
 
32
- #Question filtered text
33
- e = [ e1, e2, e3, e4 ]
42
+ # Question filtered text
43
+ e = [e1, e2, e3, e4]
34
44
  e.shuffle!
35
45
  t = "(a) #{e[0]}, (b) #{e[1]}, (c) #{e[2]}, (d) #{e[3]}"
36
- filtered=lang.text_with_connectors(t)
46
+ filtered = lang.text_with_connectors(t)
37
47
  indexes = filtered[:indexes]
38
48
 
39
- groups = (indexes.combination(4).to_a).shuffle
40
- max = (indexes.size/4).to_i
49
+ groups = indexes.combination(4).to_a.shuffle
50
+ max = (indexes.size / 4).to_i
41
51
  groups[0, max].each do |i|
42
52
  i.sort!
43
53
  q = Question.new(:match)
@@ -46,9 +56,10 @@ private
46
56
  s = lang.build_text_from_filtered(filtered, i)
47
57
  q.text = random_image_for(name(:raw))
48
58
  q.text += lang.text_for(:f3, name(:decorated), table.fields[0].capitalize, s)
49
- i.each_with_index do |value,index|
59
+ i.each_with_index do |value, index|
50
60
  q.matching << [(index + 1).to_s, filtered[:words][value][:word].downcase]
51
61
  end
62
+ q.matching << ['', lang.do_mistake_to(filtered[:words][rand(filtered[:words].size)][:word].downcase)]
52
63
  questions << q
53
64
  end
54
65
  end
@@ -58,59 +69,72 @@ private
58
69
  end
59
70
  questions
60
71
  end
72
+ # rubocop:enable Metrics/AbcSize
73
+ # rubocop:enable Metrics/MethodLength
61
74
 
62
- def make_questions_with(e, table)
75
+ # rubocop:disable Lint/BooleanSymbol
76
+ # rubocop:disable Metrics/MethodLength
77
+ # rubocop:disable Metrics/AbcSize
78
+ def make_questions_with(values, table)
63
79
  questions = []
80
+ lang = concept.lang
64
81
 
65
- e.shuffle!
82
+ values.shuffle!
66
83
  q = Question.new(:choice)
67
- q.name = "#{name(:id)}-#{num}-f1true#{e.size}-#{table.name}"
84
+ q.name = "#{name(:id)}-#{num}-f1true#{values.size}-#{table.name}"
68
85
  q.text = random_image_for(name(:raw))
69
- q.text += lang.text_for(:f1, name(:decorated), table.fields[0].capitalize, e.join('</li><li>'))
86
+ q.text += lang.text_for(:f1, name(:decorated), table.fields[0].capitalize, values.join('</li><li>'))
70
87
  q.good = lang.text_for(:true)
71
88
  q.bads << lang.text_for(:misspelling)
72
89
  q.bads << lang.text_for(:false)
73
90
 
74
- if type == 'text'
75
- e.shuffle!
91
+ if concept.type == 'text'
92
+ values.shuffle!
76
93
  q = Question.new(:short)
77
- q.name = "#{name(:id)}-#{num}-f1short#{e.size}-#{table.name}"
94
+ q.name = "#{name(:id)}-#{num}-f1short#{values.size}-#{table.name}"
78
95
  q.text = random_image_for(name(:raw))
79
- q.text += lang.text_for(:f1, lang.hide_text(name(:raw)), table.fields[0].capitalize, e.join('</li><li>'))
96
+ q.text += lang.text_for(:f1, lang.hide_text(name(:raw)), table.fields[0].capitalize, values.join('</li><li>'))
80
97
  q.shorts << name(:raw)
81
98
  q.shorts << name(:raw).tr('-_', ' ')
82
99
  questions << q
83
100
 
84
- e.shuffle!
85
- save = e[0]
86
- e[0] = lang.do_mistake_to(e[0])
101
+ values.shuffle!
102
+ save = values[0]
103
+ values[0] = lang.do_mistake_to(values[0])
87
104
  q = Question.new(:choice)
88
- q.name = "#{name(:id)}-#{num}-f1name-misspelled#{e.size}-#{table.name}"
105
+ q.name = "#{name(:id)}-#{num}-f1name-misspelled#{values.size}-#{table.name}"
89
106
  q.text = random_image_for(name(:raw))
90
- q.text += lang.text_for(:f1, lang.do_mistake_to(name(:decorated)), table.fields[0].capitalize, e.join('</li><li>'))
107
+ q.text += lang.text_for(:f1, lang.do_mistake_to(name(:decorated)), \
108
+ table.fields[0].capitalize, values.join('</li><li>'))
91
109
  q.good = lang.text_for(:misspelling)
92
110
  q.bads << lang.text_for(:true)
93
111
  q.bads << lang.text_for(:false)
94
112
  q.feedback = "Concept name #{name(:raw)} misspelled!"
95
- e[0] = save
113
+ values[0] = save
96
114
  questions << q
97
115
  end
98
116
 
99
- e.shuffle!
100
- save = e[0]
101
- e[0] = lang.do_mistake_to(e[0])
117
+ values.shuffle!
118
+ save = values[0]
119
+ values[0] = lang.do_mistake_to(values[0])
102
120
  q = Question.new(:choice)
103
- q.name = "#{name(:id)}-#{num}-f1true-misspelled#{e.size}-#{table.name}"
121
+ q.name = "#{name(:id)}-#{num}-f1true-misspelled#{values.size}-#{table.name}"
104
122
  q.text = random_image_for(name(:raw))
105
- q.text += lang.text_for(:f1, name(:decorated), table.fields[0].capitalize, e.join('</li><li>'))
123
+ q.text += lang.text_for(:f1, name(:decorated), table.fields[0].capitalize, values.join('</li><li>'))
106
124
  q.good = lang.text_for(:misspelling)
107
125
  q.bads << lang.text_for(:true)
108
126
  q.bads << lang.text_for(:false)
109
127
  q.feedback = "Text #{save} mispelled!"
110
- e[0] = save
128
+ values[0] = save
111
129
  questions << q
112
130
  end
131
+ # rubocop:enable Lint/BooleanSymbol
132
+ # rubocop:enable Metrics/MethodLength
133
+ # rubocop:enable Metrics/AbcSize
113
134
 
135
+ # rubocop:disable Lint/BooleanSymbol
136
+ # rubocop:disable Metrics/MethodLength
137
+ # rubocop:disable Metrics/AbcSize
114
138
  def run_with_other_concepts(table, list1, list2)
115
139
  questions = []
116
140
 
@@ -133,17 +157,17 @@ private
133
157
  q = Question.new(:choice)
134
158
  q.name = "#{name(:id)}-#{num}-f1false-#{table.name}"
135
159
  q.text = random_image_for(name(:raw))
136
- q.text += lang.text_for(:f1, name(:decorated), table.fields[0].capitalize, e.join('</li><li>'))
137
- q.good = lang.text_for(:false)
138
- q.bads << lang.text_for(:misspelling)
139
- q.bads << lang.text_for(:true)
160
+ q.text += concept.lang.text_for(:f1, name(:decorated), table.fields[0].capitalize, e.join('</li><li>'))
161
+ q.good = concept.lang.text_for(:false)
162
+ q.bads << concept.lang.text_for(:misspelling)
163
+ q.bads << concept.lang.text_for(:true)
140
164
  questions << q
141
165
 
142
166
  f4 = a2.shuffle![0]
143
167
  q = Question.new(:choice)
144
168
  q.name = "#{name(:id)}-#{num}-f2outsider-#{table.name}"
145
169
  q.text = random_image_for(name(:raw))
146
- q.text += lang.text_for(:f2, name(:decorated), table.fields[0].capitalize)
170
+ q.text += concept.lang.text_for(:f2, name(:decorated), table.fields[0].capitalize)
147
171
  q.good = f4
148
172
  q.bads << e1
149
173
  q.bads << e2
@@ -153,4 +177,8 @@ private
153
177
 
154
178
  questions
155
179
  end
180
+ # rubocop:enable Lint/BooleanSymbol
181
+ # rubocop:enable Metrics/MethodLength
182
+ # rubocop:enable Metrics/AbcSize
156
183
  end
184
+ # rubocop:enable Metrics/ClassLength
@@ -1,42 +1,49 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'base64_compatible' # TODO: Don't work with Moodle Gift images
4
3
  require 'set'
5
4
 
6
5
  require_relative 'base_stage'
7
6
  require_relative '../question'
8
7
 
8
+ # range i1, i2, i3, i4
9
9
  class StageI < BaseStage
10
- # range i1, i2, i3
11
-
10
+ # Stage I: process every image from <def> tag
11
+ # rubocop:disable Metrics/BlockLength
12
+ # rubocop:disable Metrics/MethodLength
13
+ # rubocop:disable Metrics/AbcSize
14
+ # rubocop:disable Metrics/CyclomaticComplexity
15
+ # rubocop:disable Metrics/PerceivedComplexity
12
16
  def run
13
- # Stage I: process every image from <def> tag
14
- questions=[]
15
- return questions unless type=="text"
17
+ questions = []
18
+ return questions unless concept.type == 'text'
16
19
 
20
+ lang = concept.lang
17
21
  # for every <image> do this
18
- images.each do |url|
19
- s=Set.new [name, lang.text_for(:none)]
20
- neighbors.each { |n| s.add n[:concept].name }
21
- a=s.to_a
22
-
23
- # Question type <f1>: choose between 4 options
24
- if s.count>3 then
25
- q=Question.new(:choice)
26
- q.name="#{name}-#{num}-i1choice"
27
- q.text=lang.text_for(:i1, url )
28
- q.good=name
22
+ concept.images.each do |image|
23
+ url = image[:text]
24
+ s = Set.new [name, lang.text_for(:none)]
25
+ concept.neighbors.each { |n| s.add n[:concept].name }
26
+ a = s.to_a
27
+
28
+ # Question type <i1>: choose between 4 options
29
+ if s.count > 3
30
+ q = Question.new(:choice)
31
+ q.name = "#{name}-#{num}-i1choice"
32
+ q.text = lang.text_for(:i1, url)
33
+ q.encode = image[:file]
34
+ q.good = name
29
35
  q.bads << lang.text_for(:none)
30
36
  q.bads << a[2]
31
37
  q.bads << a[3]
32
38
  questions << q
33
39
  end
34
40
 
35
- #Question type <i1>: choose between 4 options, good none (Syntax error)
36
- if s.count>3 then
37
- q=Question.new(:choice)
38
- q.name="#{name}-#{num}-i1misspelling"
39
- q.text=lang.text_for(:i1, url )
41
+ # Question type <i1>: choose between 4 options, good none (Syntax error)
42
+ if s.count > 3
43
+ q = Question.new(:choice)
44
+ q.name = "#{name}-#{num}-i1misspelling"
45
+ q.text = lang.text_for(:i1, url)
46
+ q.encode = image[:file]
40
47
  q.good = lang.text_for(:none)
41
48
  q.bads << lang.do_mistake_to(name)
42
49
  q.bads << a[2]
@@ -45,96 +52,76 @@ class StageI < BaseStage
45
52
  end
46
53
 
47
54
  s.delete(name)
48
- a=s.to_a
55
+ a = s.to_a
49
56
 
50
- #Question type <i1>: choose between 4 options, good none
51
- if s.count>3 then
57
+ # Question type <i1>: choose between 4 options, good none
58
+ if s.count > 3
52
59
  q = Question.new(:choice)
53
- q.name="#{name}-#{num}-i1none"
54
- q.text=lang.text_for(:i1, url )
55
- q.good=lang.text_for(:none)
60
+ q.name = "#{name}-#{num}-i1none"
61
+ q.text = lang.text_for(:i1, url)
62
+ q.encode = image[:file]
63
+ q.good = lang.text_for(:none)
56
64
  q.bads << a[1]
57
65
  q.bads << a[2]
58
66
  q.bads << a[3]
59
67
  questions << q
60
68
  end
61
69
 
62
- #Question type <f2>: boolean => TRUE
70
+ # Question type <i2>: boolean => TRUE
63
71
  q = Question.new(:boolean)
64
- q.name="#{name}-#{num}-i2true"
65
- q.text=lang.text_for(:i2, url, name )
66
- q.good="TRUE"
72
+ q.name = "#{name}-#{num}-i2true"
73
+ q.text = lang.text_for(:i2, url, name)
74
+ q.encode = image[:file]
75
+ q.good = 'TRUE'
67
76
  questions << q
68
77
 
69
- #Question type <i2>: boolean => FALSE
70
- if neighbors.count>0 then
78
+ # Question type <i2>: boolean => FALSE
79
+ if concept.neighbors.count.positive?
71
80
  q = Question.new(:boolean)
72
- q.name="#{name}-#{num}-i2false"
73
- q.text=lang.text_for(:i2, url, neighbors[0][:concept].name )
74
- q.good="FALSE"
81
+ q.name = "#{name}-#{num}-i2false"
82
+ q.text = lang.text_for(:i2, url, concept.neighbors[0][:concept].name)
83
+ q.encode = image[:file]
84
+ q.good = 'FALSE'
75
85
  questions << q
76
86
  end
77
87
 
78
- #Question type <i3>: hidden name questions
88
+ # Question type <i3>: hidden name questions
79
89
  q = Question.new(:short)
80
- q.name="#{name}-#{num}-i3short"
81
- q.text=lang.text_for(:i3, url, lang.hide_text(name) )
90
+ q.name = "#{name}-#{num}-i3short"
91
+ q.text = lang.text_for(:i3, url, lang.hide_text(name))
92
+ q.encode = image[:file]
82
93
  q.shorts << name
83
- q.shorts << name.gsub("-"," ").gsub("_"," ")
94
+ q.shorts << name.gsub('-', ' ').gsub('_', ' ')
84
95
  questions << q
85
96
 
86
- #Question filtered text questions
87
- texts.each do |t|
88
- filtered=lang.text_with_connectors(t)
89
-
90
- if filtered[:words].size>=4 then
91
- # indexes=Set.new
92
- # words=filtered[:words]
93
- # while indexes.size<4
94
- # i=rand(filtered[:words].size)
95
- # flag=true
96
- # flag=false if words[i].include?("[") or words[i].include?("]") or words[i].include?("(") or words[i].include?(")") or words[i].include?("\"")
97
- # indexes << i if flag
98
- # end
99
- # indexes=indexes.to_a.sort
100
- indexes = filtered[:indexes]
101
- groups = (indexes.combination(4).to_a).shuffle
102
- max = (indexes.size/4).to_i
103
- groups[0,max].each do |e|
104
- q = Question.new(:match)
105
- q.shuffle_off
106
- q.name = "#{name}-#{num}-i4filtered"
107
- e.sort!
108
- s=lang.build_text_from_filtered( filtered, e )
109
- q.text = lang.text_for(:i4, url , s)
110
- e.each_with_index do |value,index|
111
- q.matching << [ (index+1).to_s, filtered[:words][value][:word].downcase ]
112
- end
97
+ # Question filtered text questions
98
+ concept.texts.each do |t|
99
+ filtered = lang.text_with_connectors(t)
100
+ next if filtered[:words].size < 4
101
+
102
+ indexes = filtered[:indexes]
103
+ groups = indexes.combination(4).to_a.shuffle
104
+ max = (indexes.size / 4).to_i
105
+ groups[0, max].each do |e|
106
+ q = Question.new(:match)
107
+ q.shuffle_off
108
+ q.name = "#{name}-#{num}-i4filtered"
109
+ q.encode = image[:file]
110
+ e.sort!
111
+ s = lang.build_text_from_filtered(filtered, e)
112
+ q.text = lang.text_for(:i4, url, s)
113
+ e.each_with_index do |value, index|
114
+ q.matching << [index.next.to_s, filtered[:words][value][:word].downcase]
113
115
  end
114
- questions << q
115
116
  end
116
- end #each texts
117
- end #each images
118
- return questions
119
- end
120
-
121
- private
122
-
123
- def html_for_raw_image(filename)
124
- dirname = File.dirname(@concept_ia.filename)
125
- filepath = File.join(dirname,filename)
126
- content = File.open(filepath).read
127
- content64 = Base64Compatible.encode64( content )
128
- output =""
129
- until(content64.nil?) do
130
- output = output + content64[0,76]+"\n"
131
- tmp = content64[76,9999999]
132
- content64 = tmp
117
+ questions << q
118
+ end
133
119
  end
134
-
135
- ext = File.extname(filename)
136
- output = "<img src='data:image/#{ext};base64,#{output}' />"
137
- return output
120
+ questions
138
121
  end
139
-
122
+ # rubocop:enable Metrics/BlockLength
123
+ # rubocop:enable Metrics/MethodLength
124
+ # rubocop:enable Metrics/AbcSize
125
+ # rubocop:enable Metrics/CyclomaticComplexity
126
+ # rubocop:enable Metrics/PerceivedComplexity
140
127
  end
@@ -1,52 +1,57 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base_stage'
4
4
  require_relative '../question'
5
5
 
6
+ # process_sequence
6
7
  class StageS < BaseStage
7
-
8
- def run(pTable, pList1, pList2)
9
- #process_sequence
8
+ # process_sequence
9
+ # rubocop:disable Metrics/MethodLength
10
+ # rubocop:disable Metrics/AbcSize
11
+ # rubocop:disable Metrics/CyclomaticComplexity
12
+ # rubocop:disable Metrics/PerceivedComplexity
13
+ def run(table, list1, _list2)
10
14
  questions = []
11
- return questions unless ( pTable.fields.count==1 and pTable.sequence? and pTable.sequence[0]!="")
12
-
13
- #TODO
14
- #items=[]
15
- #pList1.each_with_index { |i,j| items<<[ i[:data][0], j] }
16
- #puts Rainbow(items).blue.bright
17
-
18
- #Question type <d3sequence>: items are part of a sequence
19
- if pList1.count>3
20
- a=0..(pList1.count-4)
21
- a.each_entry do |i|
22
- q=Question.new(:match)
23
- q.name="#{name}-#{num.to_s}-s1sequence-#{pTable.name}"
24
- q.text= random_image_for(name) + lang.text_for(:s1, name, pTable.fields[0].capitalize, pTable.sequence[0] )
25
- q.matching << [ pList1[i+0][:data][0], '' ]
26
- q.matching << [ pList1[i+1][:data][0], '2º' ]
27
- q.matching << [ pList1[i+2][:data][0], '3º' ]
28
- q.matching << [ pList1[i+3][:data][0], '4º' ]
15
+ return questions unless table.fields.count == 1 && table.sequence? && table.sequence[0] != ''
16
+
17
+ lang = concept.lang
18
+ # Question type <d3sequence>: items are part of a sequence
19
+ if list1.count > 3
20
+ a = 0..(list1.count - 4)
21
+ a.each_entry do |i|
22
+ q = Question.new(:match)
23
+ q.name = "#{name}-#{num}-s1sequence-#{table.name}"
24
+ q.text = random_image_for(name) + lang.text_for(:s1, name, table.fields[0].capitalize, table.sequence[0])
25
+ q.matching << [list1[i + 0][:data][0], '1º']
26
+ q.matching << [list1[i + 1][:data][0], '2º']
27
+ q.matching << [list1[i + 2][:data][0], '3º']
28
+ q.matching << [list1[i + 3][:data][0], '4º']
29
+ q.matching << ['', lang.text_for(:error)]
29
30
  questions << q
30
31
  end
31
32
  end
32
33
 
33
- #Question type <d4sequence>: items are part of a reverse sequence
34
- if pList1.count>3 and pTable.sequence.size>1
35
- a=0..(pList1.count-4)
36
- a.each_entry do |i|
37
- q=Question.new
34
+ # Question type <d4sequence>: items are part of a reverse sequence
35
+ if list1.count > 3 && table.sequence.size > 1
36
+ a = 0..(list1.count - 4)
37
+ a.each_entry do |i|
38
+ q = Question.new
38
39
  q.set_match
39
- q.name="#{name}-#{num.to_s}-s2sequence-#{pTable.name}"
40
- q.text= random_image_for(name) + lang.text_for(:s1, name, pTable.fields[0].capitalize, pTable.sequence[1] )
41
- q.matching << [ pList1[i+3][:data][0], '1º' ]
42
- q.matching << [ pList1[i+2][:data][0], '2º' ]
43
- q.matching << [ pList1[i+1][:data][0], '3º' ]
44
- q.matching << [ pList1[i+0][:data][0], '4º' ]
40
+ q.name = "#{name}-#{num}-s2sequence-#{table.name}"
41
+ q.text = random_image_for(name) + lang.text_for(:s1, name, table.fields[0].capitalize, table.sequence[1])
42
+ q.matching << [list1[i + 3][:data][0], '1º']
43
+ q.matching << [list1[i + 2][:data][0], '2º']
44
+ q.matching << [list1[i + 1][:data][0], '3º']
45
+ q.matching << [list1[i + 0][:data][0], '4º']
46
+ q.matching << ['', lang.text_for(:error)]
45
47
  questions << q
46
48
  end
47
- end
49
+ end
48
50
 
49
- return questions
51
+ questions
50
52
  end
51
-
53
+ # rubocop:enable Metrics/MethodLength
54
+ # rubocop:enable Metrics/AbcSize
55
+ # rubocop:enable Metrics/CyclomaticComplexity
56
+ # rubocop:enable Metrics/PerceivedComplexity
52
57
  end