Skip to content

Commit

Permalink
Merge pull request #487 from cedarcode/sr--add-suppor-for-activity-pr…
Browse files Browse the repository at this point in the history
…erequisites

Añadir soporte para previas  'Actividad de instancia aprobada/reprobada'
  • Loading branch information
santiagorodriguez96 committed Jun 18, 2024
2 parents 4bf4c30 + 53fce2f commit c340c30
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 21 deletions.
4 changes: 4 additions & 0 deletions app/helpers/subjects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ def display_subject_prerequisite(subject_prerequisite)
def display_enrollment_prerequisite(enrollment_prerequisite)
"inscripto a #{display_name(enrollment_prerequisite.approvable_needed.subject)}"
end

def display_activity_prerequisite(activity_prerequisite)
"aprobado/reprobado #{display_subject_prerequisite(activity_prerequisite)}"
end
end
7 changes: 7 additions & 0 deletions app/models/activity_prerequisite.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ActivityPrerequisite < Prerequisite
belongs_to :approvable_needed, class_name: "Approvable"

def met?(approved_approvable_ids)
approvable_needed.available?(approved_approvable_ids)
end
end
2 changes: 2 additions & 0 deletions app/services/tree_preloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def preload_prerequisite(prereq)
prereq.association(:approvable_needed).target = approvable_by_id[prereq.approvable_needed_id]
when EnrollmentPrerequisite
prereq.association(:approvable_needed).target = approvable_by_id[prereq.approvable_needed_id]
when ActivityPrerequisite
prereq.association(:approvable_needed).target = approvable_by_id[prereq.approvable_needed_id]
else
raise "Unknown prerequisite type: #{prereq.class}"
end
Expand Down
1 change: 1 addition & 0 deletions app/services/yml_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def prerequisite_tree(prerequisite)
when 'all' then SubjectPrerequisite.new(approvable_needed: subject.exam || subject.course)
when 'course_enrollment' then EnrollmentPrerequisite.new(approvable_needed: subject.course)
when 'exam_enrollment' then EnrollmentPrerequisite.new(approvable_needed: subject.exam)
when 'exam_activity' then ActivityPrerequisite.new(approvable_needed: subject.exam)
else raise "Unknown approvable needed: #{prerequisite["needs"]}"
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= link_to subject_path(activity_prerequisite.approvable_needed.subject), class: 'mdc-deprecated-list-item' do %>
<span class="mdc-deprecated-list-item__ripple"></span>
<span class="mdc-deprecated-list-item__text">
<%= negative ? "No haber" : "Haber" %>
<%= display_activity_prerequisite(activity_prerequisite) %>
</span>

<%= render 'prerequisites/met_checkmark', prerequisite: activity_prerequisite, negative: %>
<% end %>
98 changes: 86 additions & 12 deletions db/data/scraped_prerequisites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -457,22 +457,10 @@
- type: logical
logical_operator: or
operands:
- type: subject
subject_needed_code: CP6
subject_needed_name: ANALISIS MATEMATICO II
needs: exam
- type: subject
subject_needed_code: CP25
subject_needed_name: ANALISIS MATEMATICO II (P. 74)
needs: exam
- type: subject
subject_needed_code: 1025P
subject_needed_name: CREDITOS NO ACUM PROB Y EST.
needs: exam
- type: subject
subject_needed_code: 1025T
subject_needed_name: CREDITOS NO ACUM PROBABILIDAD Y ESTADISTICA
needs: exam
- type: subject
subject_needed_code: '1025'
subject_needed_name: PROBABILIDAD Y ESTADISTICA
Expand All @@ -481,6 +469,17 @@
subject_needed_code: '1075'
subject_needed_name: PROBABILIDAD Y ESTADISTICA
needs: exam
- type: logical
logical_operator: or
operands:
- type: subject
subject_needed_code: '1443'
subject_needed_name: ARQUITECTURA DE COMPUTADORAS
needs: exam
- type: subject
subject_needed_code: 1443P
subject_needed_name: CREDITOS NO ACUM. CON ARQUITECTURA DE COMPUTADORAS
needs: exam
subject_code: '1438'
is_exam: false
- type: logical
Expand Down Expand Up @@ -7781,6 +7780,31 @@
needs: course
subject_code: '1773'
is_exam: false
- type: logical
logical_operator: not
operands:
- type: logical
logical_operator: or
operands:
- type: subject
subject_needed_code: SRN22
subject_needed_name: COMPRENSIÓN LECTORA DE INGLÉS
needs: exam
- type: subject
subject_needed_code: 816EU
subject_needed_name: INGLES CIENTÍFICO
needs: exam
subject_code: INFU1
is_exam: false
- type: logical
logical_operator: and
operands:
- type: subject
needs: course
subject_needed_code: INFU1
subject_needed_name: INGLES PARA FINES UNIVERSITARIOS I
subject_code: INFU1
is_exam: true
- type: logical
logical_operator: and
operands:
Expand Down Expand Up @@ -17768,6 +17792,56 @@
needs: all
subject_code: '1233'
is_exam: false
- type: logical
logical_operator: and
operands:
- type: logical
logical_operator: not
operands:
- type: subject
needs: all
subject_needed_code: '2217'
subject_needed_name: TUTORIAS ENTRE PARES 2
- type: logical
logical_operator: not
operands:
- type: subject
needs: all
subject_needed_code: '2216'
subject_needed_name: TUTORIAS ENTRE PARES 1
- type: logical
logical_operator: or
operands:
- type: subject
needs: exam_activity
subject_needed_code: '1151'
subject_needed_name: FISICA 1
- type: logical
logical_operator: and
operands:
- type: subject
subject_needed_code: '1061'
subject_needed_name: CALCULO DIF. E INTEGRAL EN UNA VARIABLE
needs: exam
- type: subject
subject_needed_code: '1062'
subject_needed_name: CALCULO DIF. E INTEGRAL EN VARIAS VARIABLES
needs: course
- type: logical
logical_operator: and
operands:
- type: subject
subject_needed_code: '1030'
subject_needed_name: GEOMETRIA Y ALGEBRA LINEAL 1
needs: exam
- type: subject
subject_needed_code: '1031'
subject_needed_name: GEOMETRIA Y ALGEBRA LINEAL 2
needs: course
- type: credits
credits: 55
subject_code: '5005'
is_exam: false
- type: logical
logical_operator: and
operands:
Expand Down
30 changes: 21 additions & 9 deletions db/data/scraped_subjects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3305,6 +3305,18 @@ CH8:
credits: 8
has_exam: false
subject_group: '5265'
INFU1:
code: INFU1
name: INGLES PARA FINES UNIVERSITARIOS I
credits: 8
has_exam: true
subject_group: '3582'
'5005':
code: '5005'
name: TUTORIAS ENTRE PARES ACADEMICAS PROGRESA/FING
credits: 8
has_exam: false
subject_group: '3582'
'1236':
code: '1236'
name: SEMINARIO SOBRE ENCUENTROS ENTRE ARTE Y TECNOLOGIAS
Expand All @@ -3321,7 +3333,7 @@ SRN22:
code: SRN22
name: COMPRENSIÓN LECTORA DE INGLÉS
credits: 8
has_exam: false
has_exam: true
subject_group: '3582'
SRN25:
code: SRN25
Expand Down Expand Up @@ -3363,7 +3375,7 @@ AT021:
code: 816EU
name: INGLES CIENTÍFICO
credits: 4
has_exam: false
has_exam: true
subject_group: '3582'
2107A:
code: 2107A
Expand Down Expand Up @@ -3427,7 +3439,7 @@ GP4:
subject_group: '3582'
'1438':
code: '1438'
name: APLICACION DE TEORIA DE LA INF.AL PROC.DE IMAG.
name: APLICACIONES DE TEORIA DE LA INFORMACION AL PROC. DE IMAG.
credits: 6
has_exam: false
subject_group: '3582'
Expand Down Expand Up @@ -3551,6 +3563,12 @@ C402:
credits: 0
has_exam: true
subject_group:
1443P:
code: 1443P
name: CREDITOS NO ACUM. CON ARQUITECTURA DE COMPUTADORAS
credits: 0
has_exam: true
subject_group:
107L:
code: 107L
name: CALCULO 1
Expand Down Expand Up @@ -3599,12 +3617,6 @@ R101:
credits: 0
has_exam: true
subject_group:
1443P:
code: 1443P
name: CREDITOS NO ACUM. CON ARQUITECTURA DE COMPUTADORAS
credits: 0
has_exam: true
subject_group:
1322P:
code: 1322P
name: CREDITOS NO ACUM PROGRAMACION 1
Expand Down
2 changes: 2 additions & 0 deletions lib/scraper/prerequisites_tree_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def process_leaf(node)
when 'Inscripción a Examen de la U.C.B:' then subject_prerequisite(content, 'exam_enrollment')
# U.C.B Aprobada: 1424 - ARQUITECTURA DE COMPUTADORES 1
when 'U.C.B Aprobada:' then subject_prerequisite(content, 'all')
# Actividad Examen aprobada/reprobada en la U.C.B: 1151 - FISICA 1
when 'Actividad Examen aprobada/reprobada en la U.C.B:' then subject_prerequisite(content, 'exam_activity')
else raise "Unknown node title: #{title}"
end
end
Expand Down
25 changes: 25 additions & 0 deletions spec/models/activity_prerequisite_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'rails_helper'

RSpec.describe ActivityPrerequisite, type: :model do
describe '#met?' do
context 'when the approvable needed is available' do
it 'returns true' do
subject_needed = create :subject, :with_exam
allow(subject_needed.exam).to receive(:available?).and_return(true)
prerequisite = create :activity_prerequisite, approvable_needed: subject_needed.exam

expect(prerequisite.met?([])).to be_truthy
end
end

context 'when the approvable needed is not available' do
it 'returns false' do
subject_needed = create :subject, :with_exam
allow(subject_needed.exam).to receive(:available?).and_return(false)
prerequisite = create :activity_prerequisite, approvable_needed: subject_needed.exam

expect(prerequisite.met?([])).to be_falsey
end
end
end
end
4 changes: 4 additions & 0 deletions test/factories/prerequisites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@
logical_operator { "at_least" }
end
end

factory :activity_prerequisite do
approvable_needed factory: :exam
end
end

0 comments on commit c340c30

Please sign in to comment.