-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Populate user subjects based on documents #634
Open
frankete333
wants to merge
14
commits into
master
Choose a base branch
from
populate-user-subjects-based-on-documents
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2be7baa
Add pdf reader gem
frankete333 6d018fa
Add new styles
frankete333 9144e46
Add force_add
frankete333 627d6a5
Add new routes and button
frankete333 4badc00
Add controller and view
frankete333 a0ff0de
Merge branch 'master' into populate-user-subjects-based-on-documents
frankete333 2cb0d5a
Move pdf parsing logic to lib
frankete333 35f51c0
Add pdf processor test
frankete333 ebc0c71
Rubocop fixes
frankete333 86aadbf
Change process to be an enumerator
frankete333 ba09deb
Remove scss
frankete333 1439e3d
Make PdfProcessor an enum
frankete333 6177348
Merge branch 'master' into populate-user-subjects-based-on-documents
frankete333 f49b2fc
Fix lint
frankete333 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
require 'pdf-reader' | ||
|
||
class AcademicHistoriesController < ApplicationController | ||
AcademicEntry = Struct.new(:name, :credits, :number_of_failures, :date_of_completion, :grade) do | ||
def approved? | ||
grade != '***' | ||
end | ||
end | ||
|
||
def index | ||
redirect_to new_academic_history_path | ||
end | ||
|
||
def new | ||
end | ||
|
||
def create | ||
file = params[:file] | ||
@failed_entries = [] | ||
@successful_entries = [] | ||
|
||
if file && file.content_type == 'application/pdf' | ||
@academic_entries = academic_entries(file) | ||
@academic_entries.each do |entry| | ||
frankete333 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
save_academic_entry(entry) if entry.approved? | ||
end | ||
else | ||
flash[:error] = 'Please upload a valid PDF file' | ||
end | ||
render :new | ||
end | ||
|
||
private | ||
|
||
def save_academic_entry(entry) | ||
subject_match = Subject.where("lower(unaccent(name)) = lower(unaccent(?))", entry.name) | ||
subject_match = subject_match.select { |subject| subject.credits == entry.credits.to_i } | ||
active_subjects = subject_match.select { |subject| !subject.inactive? } | ||
if subject_match.length == 1 | ||
save_subject(subject_match.first) | ||
elsif active_subjects.length == 1 | ||
save_subject(active_subjects.first) | ||
else | ||
@failed_entries << entry | ||
end | ||
end | ||
|
||
def save_subject(subject) | ||
current_student.force_add(subject) | ||
@successful_entries << subject | ||
end | ||
|
||
def academic_entries(file) | ||
reader = PDF::Reader.new(file.path) | ||
academic_entries = [] | ||
|
||
reader.pages.each do |page| | ||
page.text.split("\n").each do |line| | ||
line.match(subject_regex) do |match| | ||
academic_entries << AcademicEntry.new(match[1], match[2], match[3], match[4], match[5]) | ||
end | ||
end | ||
end | ||
|
||
academic_entries | ||
end | ||
|
||
# SubjectName Credits NumberOfFailures DateOfCompletion Grade | ||
def subject_regex | ||
/\s*(.*?)\s+(\d+)\s+(\d+)\s+(#{date_regex.source})\s+(#{grade_regex.source})/ | ||
end | ||
|
||
# The date can be either a date in the format DD/MM/YYYY or ********** | ||
def date_regex | ||
/\*{10}|\d\d\/\d\d\/\d\d\d\d/ | ||
end | ||
|
||
# The grade can be either a number from 0 to 12, S/N or *** | ||
def grade_regex | ||
/\d+|S\/N|\*{3}/ | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<h3 class="mdc-deprecated-list-group__subheader mdc-typography--headline5 sign-in mb-3">Resumen por Grupo</h3> | ||
<p class="mb-3">Carga tu escolaridad para marcar automaticamente las materias que ya cursaste.</p> | ||
<p>1) Entrar a <a href="https://bedelias.udelar.edu.uy/" target="_blank">Bedelias</a> e iniciar session</p> | ||
<p>2) Entrar a "Estudiante" -> "Escolaridad" -> "Solicitar Escolaridad"</p> | ||
<p>3) Seleccionar tu carrera y "No" en "Resultados Intermedios"</p> | ||
<%= form_with url: academic_histories_path, method: :post, local: true, html: { multipart: true } do |form| %> | ||
<div class="sign-in my-6"> | ||
<%= form.label :file, "Upload PDF" %> | ||
<%= form.file_field :file, accept: "application/pdf" %> | ||
|
||
<%= form.button class: "mdc-button mdc-button--raised" do %> | ||
<span class="mdc-button__ripple"></span> | ||
<span class='mdc-button__label'> | ||
Subir | ||
</span> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
<div class="sign-in"> | ||
<% if @successful_entries&.present? %> | ||
<p class="color-green mb-2"><%= @successful_entries.length %> Materias marcadas correctamente</p> | ||
<% @successful_entries.each do |entry| %> | ||
<p><%= entry.code %> - <%= entry.name %></p> | ||
<% end %> | ||
<% end %> | ||
<% if @failed_entries&.present? %> | ||
<p class="color-red my-2"><%= @failed_entries.length %> Materias no encontradas</p> | ||
<% @failed_entries.each do |entry| %> | ||
<p><%= entry.name %></p> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
<p class="subtle-text sign-in mt-3"> | ||
La escolaridad no incluye codigos de materias, por lo que en caso de multiples candidatos con el mismo nombre, se marca la materia mas reciente y actualmente activa | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Por que definis el index si el boton en el menu lleva al new? Se podria sacar?