Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def strata_and_substrata_configured?
def can_execute?
strata_and_substrata_configured? && !sample_participants.empty?
end

def executed?
status == "executed"
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,16 @@ input[readonly] {

.upload-census-btn {
margin: 0 !important;
}

.upload-disabled-wrapper {
cursor: not-allowed;
width: auto;

.upload-census-btn {
pointer-events: none;
border: 1px solid #3e4c5c;
background-color: #efefef;
color: #3e4c5c;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,21 @@ def export_json

private

def i18n_scope
"decidim.stratified_sortitions.admin.stratified_sortitions.execute"
end

def metadata_headers
@metadata_headers ||= %w(
algorithm total_participants generated_at generation_time
num_panels selected_at verification_seed random_value_used
selected_panel_probability
)
@metadata_headers ||= [
I18n.t("algorithm", scope: i18n_scope),
I18n.t("total_participants", scope: i18n_scope),
I18n.t("generated_at", scope: i18n_scope),
I18n.t("generation_time", scope: i18n_scope),
I18n.t("num_panels", scope: i18n_scope),
I18n.t("selected_at", scope: i18n_scope),
I18n.t("random_value_used", scope: i18n_scope),
I18n.t("selected_panel_probability", scope: i18n_scope),
]
end

def metadata_values
Expand All @@ -100,18 +109,23 @@ def metadata_values
@portfolio.generation_time_seconds,
@portfolio.num_panels,
@portfolio.selected_at,
@portfolio.verification_seed || "-",
@portfolio.random_value_used,
format_percentage(@portfolio.selected_panel_probability),
]
end

def participant_headers
@participant_headers ||= begin
headers = %w(personal_data_1 personal_data_2 personal_data_3 personal_data_4)
template_scope = "decidim.stratified_sortitions.admin.samples.template"
headers = [
I18n.t("personal_data_1", scope: template_scope),
I18n.t("personal_data_2", scope: template_scope),
I18n.t("personal_data_3", scope: template_scope),
I18n.t("personal_data_4", scope: template_scope),
]
@strata.each do |stratum|
stratum_name = stratum.name.values.compact.first || stratum.id.to_s
headers << "stratum_#{stratum_name}"
headers << stratum_name
end
headers
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<%= form.translated :text_field, :title, autofocus: true, aria: { label: :title } %>
</div>

<div class="row column">
<div class="row column mt-4">
<%= form.number_field :num_candidates %>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
<th><%= t(".generation_time") %></th>
<th><%= t(".num_panels") %></th>
<th><%= t(".selected_at") %></th>
<th><%= t(".verification_seed") %></th>
<th><%= t(".random_value_used") %></th>
<th><%= t(".selected_panel_probability") %></th>
</tr>
Expand All @@ -71,9 +70,8 @@
<td><%= number_with_precision(@portfolio.generation_time_seconds, precision: 2) %>s</td>
<td><%= @portfolio.num_panels %></td>
<td><%= l @portfolio.selected_at, format: :decidim_short %></td>
<td><code><%= @portfolio.verification_seed || "-" %></code></td>
<td><code><%= @portfolio.random_value_used %></code></td>
<td><%= number_to_percentage(@portfolio.selected_panel_probability.to_f * 100, precision: 4) %></td>
<td><%= number_to_percentage(@portfolio.selected_panel_probability.to_f * 100, precision: 2) %></td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
</div>
<%= render 'navigation_menu' %>
<div class="card mt-12">
<div class="item_show__header">
<h1 class="item_show__header-title">
<div>
<%= t(".upload_census") %>
</div>
</h1>
</div>
<div class="mt-1">
<%= t(".description") %>
</div>
Expand All @@ -15,7 +22,7 @@
<%= link_to t('.download_template'), download_template_samples_path(id: @stratified_sortition.id), class: 'button button__sm button__secondary' %>
</div>
</div>
<div class="row mt-4">
<div class="row mt-4 <%= 'upload-disabled-wrapper' if @stratified_sortition.executed? %>">
<%= decidim_form_for(@form, url: samples_path(id: @stratified_sortition.id), method: :post, html: { id: "sample-upload-form", class: "form", multipart: true }) do |form| %>
<%= form.upload :file,
label: false,
Expand Down
13 changes: 7 additions & 6 deletions config/locales/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ca:
created_at: Data de creació
title: Títol
description: Descripció
num_candidates: Nombre de candidats
num_candidates: Nombre de persones candidates a seleccionar
selection_criteria: Criteris de selecció
selected_profiles_description: Descripció dels perfils seleccionats
errors:
Expand Down Expand Up @@ -42,14 +42,14 @@ ca:
execute: Executar sorteig
new_stratified_sortition: "Nou sorteig estratificat"
title: "Accions"
census_management: Gestió cens
census_management: Gestionar mostra
models:
stratified_sortition:
fields:
created_at: Data de creació
title: Títol
description: Descripció
num_candidates: Nombre de candidats
num_candidates: Nombre de candidates a seleccionar
selection_criteria: Criteris de selecció
selected_profiles_description: Descripció dels perfils seleccionats
stratified_sortitions:
Expand Down Expand Up @@ -100,7 +100,7 @@ ca:
one: "1 participant seleccionat"
other: "%{count} participants seleccionats"
participant_id: ID
personal_data_1: Dada personal 1
personal_data_1: "Dada personal 1 (identificador únic)"
personal_data_2: Dada personal 2
personal_data_3: Dada personal 3
personal_data_4: Dada personal 4
Expand Down Expand Up @@ -182,7 +182,8 @@ ca:
remove_uploaded_samples: Eliminar tots els registres
confirm_remove_uploaded_samples: Estàs segur que vols eliminar totes les registres?
target: Objectiu
title: Importar nova mostra
title: Gestionar mostra
upload_census: Pujar una nova mostra
upload_file: Afegir arxiu
uploaded_file: Dades de la mostra carregada
uploaded_files: "S'han agregat els següents fitxers:"
Expand Down Expand Up @@ -252,7 +253,7 @@ ca:
one: S'ha seleccionat 1 participant
other: "S'han seleccionat %{count} participants"
sortition_details: Detalls del sorteig
num_candidates: Nombre de candidats
num_candidates: Nombre de candidates a seleccionar
status: Estat
strata_count: Nombre d'estrats
algorithm: Algorisme
Expand Down
11 changes: 6 additions & 5 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ en:
created_at: Created At
title: Title
description: Description
num_candidates: Number of Candidates
num_candidates: Number of candidates to select
selection_criteria: Selection Criteria
selected_profiles_description: Selected Profiles Description
errors:
Expand Down Expand Up @@ -42,14 +42,14 @@ en:
execute: Execute sortition
new_stratified_sortition: "New Stratified Sortition"
title: "Actions"
census_management: Census management
census_management: Manage sample
models:
stratified_sortition:
fields:
created_at: Created At
title: Title
description: Description
num_candidates: Number of Candidates
num_candidates: Number of candidates to select
selection_criteria: Selection Criteria
selected_profiles_description: Selected Profiles Description
stratified_sortitions:
Expand Down Expand Up @@ -182,7 +182,8 @@ en:
confirm_remove_uploaded_samples: Are you sure you want to remove all uploaded samples?
strata_not_configured: You must configure strata and substrata first
target: Target
title: Import new sample
title: Manage sample
upload_census: Upload new sample
upload_file: Upload file
uploaded_file: Uploaded sample data
uploaded_files: "The following files have been added:"
Expand Down Expand Up @@ -252,7 +253,7 @@ en:
one: 1 participant has been selected
other: "%{count} participants have been selected"
sortition_details: Sortition details
num_candidates: Number of candidates
num_candidates: Number of candidates to select
status: Status
strata_count: Number of strata
algorithm: Algorithm
Expand Down
11 changes: 6 additions & 5 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ es:
created_at: Fecha de creación
title: Título
description: Descripción
num_candidates: Número de candidatos
num_candidates: Número de personas candidatas a seleccionar
selection_criteria: Criterios de selección
selected_profiles_description: Descripción de los perfiles seleccionados
errors:
Expand Down Expand Up @@ -42,14 +42,14 @@ es:
execute: Ejecutar sorteo
new_stratified_sortition: "Nuevo sorteo estratificado"
title: "Acciones"
census_management: Gestión censo
census_management: Gestionar muestra
models:
stratified_sortition:
fields:
created_at: Fecha de creación
title: Título
description: Descripción
num_candidates: Número de candidatos
num_candidates: Número de candidatas a seleccionar
selection_criteria: Criterios de selección
selected_profiles_description: Descripción de los perfiles seleccionados
stratified_sortitions:
Expand Down Expand Up @@ -182,7 +182,8 @@ es:
confirm_remove_uploaded_samples: ¿Estás seguro de que quieres eliminar todas las muestras cargadas?
strata_not_configured: Primero debes configurar los estratos y subestratos
target: Objetivo
title: Importar nueva muestra
title: Gestionar muestra
upload_census: Subir una nueva muestra
upload_file: Subir archivo
uploaded_file: Datos de la muestra cargada
uploaded_files: "Se han agregado los siguientes archivos:"
Expand Down Expand Up @@ -252,7 +253,7 @@ es:
one: Se ha seleccionado 1 participante
other: "Se han seleccionado %{count} participantes"
sortition_details: Detalles del sorteo
num_candidates: Número de candidatos
num_candidates: Número de candidatas a seleccionar
status: Estado
strata_count: Número de estratos
algorithm: Algoritmo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ module StratifiedSortitions
let(:rows) { CSV.parse(result.read, col_sep: Decidim.default_csv_col_sep) }

it "has metadata headers in the first row" do
expect(rows[0]).to include("algorithm")
expect(rows[0]).to include("total_participants")
expect(rows[0]).to include("verification_seed")
expect(rows[0]).to include("Algorithm")
expect(rows[0]).to include("Total participants")
end

it "has metadata values in the second row" do
Expand All @@ -93,12 +92,12 @@ module StratifiedSortitions
end

it "has participant headers in the fourth row" do
expect(rows[3]).to include("personal_data_1")
expect(rows[3]).to include("personal_data_2")
expect(rows[3]).to include("Personal data 1 (unique identifier)")
expect(rows[3]).to include("Personal data 2")
end

it "has a stratum column header derived from stratum name" do
expect(rows[3]).to include("stratum_Gender")
expect(rows[3]).to include("Gender")
end

it "has participant data starting at the fifth row" do
Expand All @@ -108,7 +107,7 @@ module StratifiedSortitions
end

it "includes substratum names in the stratum column" do
stratum_col_idx = rows[3].index("stratum_Gender")
stratum_col_idx = rows[3].index("Gender")
substratum_values = rows[4..].map { |row| row[stratum_col_idx] }
expect(substratum_values).to include("Woman")
expect(substratum_values).to include("Man")
Expand Down Expand Up @@ -170,20 +169,20 @@ module StratifiedSortitions
end

it "has algorithm in metadata" do
expect(parsed["metadata"]["algorithm"]).to match(/LEXIMIN/)
expect(parsed["metadata"]["Algorithm"]).to match(/LEXIMIN/)
end

it "includes all selected participants" do
expect(parsed["participants"].size).to eq(2)
end

it "includes personal_data_1 for each participant" do
ids = parsed["participants"].map { |p| p["personal_data_1"] }
ids = parsed["participants"].map { |p| p["Personal data 1 (unique identifier)"] }
expect(ids).to include("ID001", "ID002")
end

it "includes stratum substratum values for each participant" do
genders = parsed["participants"].map { |p| p["stratum_Gender"] }
genders = parsed["participants"].map { |p| p["Gender"] }
expect(genders).to include("Woman", "Man")
end
end
Expand Down
Loading