generated from betagouv/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stats: compute stats from production with reusable classes
- Loading branch information
1 parent
26f3492
commit 1f5e272
Showing
27 changed files
with
1,013 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stats | ||
class Base | ||
def title | ||
raise NotImplementedError | ||
end | ||
|
||
def with_mef_and_establishment | ||
raise NotImplementedError | ||
end | ||
|
||
def with_establishment | ||
raise NotImplementedError | ||
end | ||
|
||
def global_data | ||
raise NotImplementedError | ||
end | ||
|
||
def bops_data | ||
raise NotImplementedError | ||
end | ||
|
||
def menj_academies_data | ||
raise NotImplementedError | ||
end | ||
|
||
def establishments_data | ||
raise NotImplementedError | ||
end | ||
|
||
def bop | ||
Arel.sql( | ||
%( | ||
CASE mefs.ministry | ||
WHEN 0 THEN (CASE private_contract_type_code WHEN '99' THEN 'ENPU' ELSE 'ENPR' END) | ||
ELSE mefs.ministry::text END | ||
) | ||
) | ||
end | ||
|
||
def bop_key_map(bop) | ||
%w[ENPU ENPR].include?(bop) ? bop : Mef.ministries.invert[bop.to_i].upcase | ||
end | ||
|
||
def group_per_bop(collection) | ||
collection.merge(with_mef_and_establishment) | ||
.group(bop) | ||
end | ||
|
||
def group_per_menj_academy(collection) | ||
collection.merge(with_mef_and_establishment) | ||
.where("mefs.ministry": :menj) | ||
.order(:academy_label) | ||
.group(:academy_label) | ||
end | ||
|
||
def group_per_establishment(collection) | ||
collection.merge(with_establishment) | ||
.order(:uai) | ||
.group(:uai) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stats | ||
class Count < Base | ||
attr_reader :all | ||
|
||
def initialize(all: 0) | ||
@all = all | ||
super() | ||
end | ||
|
||
def global_data | ||
all.count | ||
end | ||
|
||
def bops_data | ||
@bops_data ||= group_per_bop(all).count.transform_keys { |bop| bop_key_map(bop) } | ||
end | ||
|
||
def menj_academies_data | ||
@menj_academies_data ||= group_per_menj_academy(all).count | ||
end | ||
|
||
def establishments_data | ||
@establishments_data ||= group_per_establishment(all).count | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stats | ||
module Indicator | ||
class AttributiveDecisions < Ratio | ||
def initialize | ||
super( | ||
subset: Schooling.with_attributive_decisions, | ||
all: Schooling.all | ||
) | ||
end | ||
|
||
def title | ||
"Décisions d'attributions éditées" | ||
end | ||
|
||
def with_mef_and_establishment | ||
Schooling.joins(classe: %i[mef establishment]) | ||
end | ||
|
||
def with_establishment | ||
Schooling.joins(classe: :establishment) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stats | ||
module Indicator | ||
class Payments < Sum | ||
def initialize | ||
super( | ||
column: :amount, | ||
all: Payment.joins(pfmp: { schooling: { student: :rib } }) | ||
.merge(Pfmp.finished) | ||
.merge(Pfmp.in_state(:validated)) | ||
.merge(Schooling.with_attributive_decisions) | ||
.merge(Student.asp_ready) | ||
) | ||
end | ||
|
||
def title | ||
"Somme des PFMPs terminées validées avec RIB, DA & données élèves" | ||
end | ||
|
||
def with_mef_and_establishment | ||
Payment.joins(schooling: { classe: %i[mef establishment] }) | ||
end | ||
|
||
def with_establishment | ||
Payment.joins(schooling: { classe: :establishment }) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stats | ||
module Indicator | ||
class Pfmps < Count | ||
def initialize | ||
super( | ||
all: Pfmp.all | ||
) | ||
end | ||
|
||
def title | ||
"Toutes les PFMPs (même non complétées)" | ||
end | ||
|
||
def with_mef_and_establishment | ||
Pfmp.joins(schooling: { classe: %i[mef establishment] }) | ||
end | ||
|
||
def with_establishment | ||
Pfmp.joins(schooling: { classe: :establishment }) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stats | ||
module Indicator | ||
class Ribs < Ratio | ||
def initialize | ||
super( | ||
subset: Student.joins(:rib), | ||
all: Student.all | ||
) | ||
end | ||
|
||
def title | ||
"Coordonnées bancaires saisies" | ||
end | ||
|
||
def with_mef_and_establishment | ||
Student.joins(schoolings: { classe: %i[mef establishment] }) | ||
end | ||
|
||
def with_establishment | ||
Student.joins(schoolings: { classe: :establishment }) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stats | ||
module Indicator | ||
class Schoolings < Count | ||
def initialize | ||
super( | ||
all: Schooling.all | ||
) | ||
end | ||
|
||
def title | ||
"Scolarités concernées" | ||
end | ||
|
||
def with_mef_and_establishment | ||
Schooling.joins(classe: %i[mef establishment]) | ||
end | ||
|
||
def with_establishment | ||
Schooling.joins(classe: :establishment) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stats | ||
module Indicator | ||
class StudentsData < Ratio | ||
def initialize | ||
super( | ||
subset: Student.asp_ready, | ||
all: Student.all | ||
) | ||
end | ||
|
||
def title | ||
"Données d'élèves nécessaires présentes" | ||
end | ||
|
||
def with_mef_and_establishment | ||
Student.joins(schoolings: { classe: %i[mef establishment] }) | ||
end | ||
|
||
def with_establishment | ||
Student.joins(schoolings: { classe: :establishment }) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stats | ||
module Indicator | ||
class ValidatedPfmps < Ratio | ||
def initialize | ||
finished_pfmps = Pfmp.finished | ||
|
||
super( | ||
subset: finished_pfmps.in_state(:validated), | ||
all: finished_pfmps | ||
) | ||
end | ||
|
||
def title | ||
"PFMPs terminées et validées" | ||
end | ||
|
||
def with_mef_and_establishment | ||
Pfmp.joins(schooling: { classe: %i[mef establishment] }) | ||
end | ||
|
||
def with_establishment | ||
Pfmp.joins(schooling: { classe: :establishment }) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stats | ||
module Indicator | ||
class YearlyAmounts < Sum | ||
def initialize | ||
super( | ||
column: :yearly_cap, | ||
all: Schooling.joins(classe: :mef) | ||
.merge(Mef.with_wages) | ||
) | ||
end | ||
|
||
def title | ||
"Somme des montants annuels" | ||
end | ||
|
||
def with_mef_and_establishment | ||
Schooling.joins(classe: %i[mef establishment]) | ||
end | ||
|
||
def with_establishment | ||
Schooling.joins(classe: :establishment) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.