Commit 8d35d1eb authored by Gustavo Soviersovski's avatar Gustavo Soviersovski

Merge branch 'prototipo_turmas' of gitlab.c3sl.ufpr.br:simcaq/simcaq into prototipo_turmas

parents 1d1d248a 7929312c
......@@ -7,7 +7,7 @@ class SchoolClassesController < ApplicationController
if params[:search]
# filter relevant parameters
@search_params = school_class_params.symbolize_keys
@avg_enrollments = apply_search_filters(@search_params)
@result = SchoolClass.search(@search_params)
end
end
......@@ -75,30 +75,7 @@ class SchoolClassesController < ApplicationController
def school_class_params
params.require(:school_class)
.permit(:search, :state_id, :city_id, :region_id, :census_year_start, :census_year_end,
:administrative_level_id)
:administrative_level_id, :variable, :location_id, :school_class_type_id)
.keep_if { |k,v| !v.nil? and !v.empty? }
end
def apply_search_filters(filtered_params)
school_classes = SchoolClass
filtered_params.each do |param, value|
if param.eql? :state_id
school_classes = school_classes.where([ "state_id = :state_id", { state_id: value.to_i} ])
elsif param.eql? :city_id
school_classes = school_classes.where([ "city_id = :city_id", { city_id: value.to_i } ])
#elsif param.eql? :region_id
# school_classes = school_classes.where([ "region_id = :region_id", { region_id: value.to_i } ])
elsif param.eql? :census_year_start
school_classes = school_classes.where([ "census_year >= :census_year", { census_year: value.to_i } ])
elsif param.eql? :census_year_end
school_classes = school_classes.where([ "census_year <= :census_year", { census_year: value.to_i } ])
end
end
if filtered_params.empty?
school_classes.all.average(:num_enrollments)
else
school_classes.average(:num_enrollments)
end
end
end
......@@ -27,7 +27,32 @@ class SchoolClass < ActiveRecord::Base
maximum(:census_year)
end
def search(params)
def self.search(filtered_params)
params = filtered_params
school_classes = self
if filtered_params.size > 1
school_classes = school_classes.where(state_id: params[:state_id]) if params[:state_id]
school_classes = school_classes.where(city_id: params[:city_id]) if params[:city_id]
school_classes = school_classes.where(school_type_id: params[:school_type_id]) if params[:school_type_id]
if params[:census_year_start]
school_classes = school_classes.where([ "census_year >= :census_year",
{ census_year: params[:census_year_start] } ])
end
if params[:census_year_end]
school_classes = school_classes.where([ "census_year <= :census_year",
{ census_year: params[:census_year_end] } ])
end
else
school_classes = school_classes.all
end
case params[:variable]
when "enrollments"
school_classes = school_classes.sum(:num_enrollments)
when "teachers"
school_classes = school_classes.sum(:num_enrollments)
when "schools"
school_classes = school_classes.sum(:num_enrollments)
end
end
end
......@@ -20,6 +20,10 @@
<%= Region.model_name.human %>:<br />
<%= select :school_class, :region_id, Region.all.ordered.collect { |p| [ p.name, p.id ] }, prompt: "Nenhuma região selecionada" %>
</div>
<div class="field">
<%= AdministrativeLevel.model_name.human %>:<br />
<%= select :school_class, :administrative_level_id, AdministrativeLevel.all.collect { |p| [ p.name, p.id ] }, prompt: "Nenhuma dependência administrativa selecionada" %>
</div>
</fieldset>
<fieldset>
......@@ -37,8 +41,22 @@
<fieldset>
<legend>Variáveis</legend>
<div class="field">
<%= AdministrativeLevel.model_name.human %>:<br />
<%= select :school_class, :administrative_level_id, AdministrativeLevel.all.collect { |p| [ p.name, p.id ] }, prompt: "Nenhuma dependência administrativa selecionada" %>
Selecione uma variável: <br />
<%= select :school_class, :variable, options_for_select([["Número de Matrículas", "enrollments"], ["Nùmero de Escolas", "schools"], ["Número de Professores", "teachers"]], :selected => params[:variable]) %>
</div>
</fieldset>
<fieldset>
<legend>Filtros Adicionais</legend>
<div class="field">
<%= Location.model_name.human %>:<br />
<%= select :school_class, :location_id, Location.all.collect { |p| [ p.name, p.id ] }, prompt: "Nenhuma localização selecionada" %>
</div>
<div class="field">
<%= SchoolClassType.model_name.human %>: <br />
<%= select :school_class, :school_class_type_id, SchoolClassType.all.collect { |p| [ p.description, p.id ] },
:default => SchoolClassType.find_by_description("Não se aplica").id %>
</div>
</fieldset>
......@@ -48,7 +66,14 @@
</fieldset>
<% end %>
<%= @avg_enrollments unless @avg_enrollments.nil? %><br>
<%= link_to "#{t(:new)} #{SchoolClass.model_name.human}", new_school_class_path %>
<% unless @result.nil? %>
<fieldset>
<legend>Resultado</legend>
Número de <%= (@search_params[:variable] == "enrollments") ? "matrículas" : "outros" %>: <%= @result %><br>
<br />
Você também pode baixar o conjunto de dados nos seguintes formatos: <br>
<fieldset>
<legend>Parametros da Consulta</legend>
</fieldset>
</fieldset>
<% end %>
......@@ -3,10 +3,12 @@ pt_BR:
activerecord:
models:
school_class: "Turma"
location: "Local"
school_class_type: "Tipo de Atendimento/Turma"
location: "Localização"
state: "Estado"
city: "Cidade"
region: "Região"
administrative_level: "Dependência Administrativa"
attributes:
city:
name: "Nome"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment