@stamhoofd/metabase 2.148.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/LICENSE.md +32 -0
  2. package/README.md +136 -0
  3. package/dist/api.d.ts +217 -0
  4. package/dist/api.d.ts.map +1 -0
  5. package/dist/api.js +334 -0
  6. package/dist/api.js.map +1 -0
  7. package/dist/naming.d.ts +36 -0
  8. package/dist/naming.d.ts.map +1 -0
  9. package/dist/naming.js +42 -0
  10. package/dist/naming.js.map +1 -0
  11. package/dist/report.d.ts +141 -0
  12. package/dist/report.d.ts.map +1 -0
  13. package/dist/report.js +297 -0
  14. package/dist/report.js.map +1 -0
  15. package/dist/sync-report.d.ts +212 -0
  16. package/dist/sync-report.d.ts.map +1 -0
  17. package/dist/sync-report.js +653 -0
  18. package/dist/sync-report.js.map +1 -0
  19. package/package.json +33 -0
  20. package/report/eenheden.sql +459 -0
  21. package/report/filters.sql +65 -0
  22. package/report/includes/aangesloten.sql +23 -0
  23. package/report/includes/aansluiting.sql +26 -0
  24. package/report/includes/facts-alle-jaren.sql +53 -0
  25. package/report/includes/facts.sql +102 -0
  26. package/report/includes/gtp.sql +49 -0
  27. package/report/includes/ingeschreven-voor.sql +27 -0
  28. package/report/includes/jaren.sql +20 -0
  29. package/report/includes/keeo/tak-categorie.sql +30 -0
  30. package/report/includes/leden-per-jaar.sql +29 -0
  31. package/report/includes/leden.sql +39 -0
  32. package/report/includes/omkaderingscijfer.sql +17 -0
  33. package/report/includes/postcode-coordinaten.sql +8 -0
  34. package/report/includes/ravot/gtp.sql +32 -0
  35. package/report/includes/ravot/omkaderingscijfer.sql +25 -0
  36. package/report/includes/ravot/tak-categorie.sql +28 -0
  37. package/report/includes/ravot/type-deelnemers.sql +22 -0
  38. package/report/includes/tak-categorie.sql +18 -0
  39. package/report/includes/takken.sql +20 -0
  40. package/report/includes/tarief.sql +14 -0
  41. package/report/includes/type-deelnemers.sql +14 -0
  42. package/report/includes/uldk.sql +23 -0
  43. package/report/jeugdbewegingen.sql +221 -0
  44. package/report/nationaal.sql +229 -0
  45. package/report/netwerk.sql +70 -0
  46. package/report/varia.sql +35 -0
@@ -0,0 +1,53 @@
1
+ -- The same grain as `facts`, but never filtered by scoutsjaar: the cards that draw a line across the
2
+ -- years need every year regardless of which one the dashboard filter has selected. Keep the two in
3
+ -- step when changing what counts as an active registration.
4
+ WITH
5
+ -- @include takken
6
+ facts AS (
7
+ SELECT
8
+ r.memberId AS member_id,
9
+ r.organizationId AS organization_id,
10
+ o.name AS `Eenheid`,
11
+ o.postalCode AS eenheid_postcode,
12
+ o.city AS eenheid_gemeente,
13
+ p.id AS period_id,
14
+ p.name AS `Scoutsjaar`,
15
+ p.startDate AS period_start,
16
+ g.type AS group_type,
17
+ COALESCE(dag.name, g.name) AS `Tak`,
18
+ dag.id AS tak_id,
19
+ dag.category AS tak_category,
20
+ dag.minAge AS tak_min_age,
21
+ dag.maxAge AS tak_max_age,
22
+ COALESCE(
23
+ dag.category,
24
+ CASE WHEN dag.maxAge < 18 THEN 'child' END,
25
+ CASE WHEN TIMESTAMPDIFF(YEAR, m.birthDate, p.startDate) < 18 THEN 'child' END
26
+ ) AS effective_category,
27
+ CASE m.gender
28
+ WHEN 'Male' THEN 'Man'
29
+ WHEN 'Female' THEN 'Vrouw'
30
+ WHEN 'Other' THEN 'Andere'
31
+ ELSE 'Onbekend'
32
+ END AS `Geslacht`,
33
+ m.birthDate AS birth_date,
34
+ TIMESTAMPDIFF(YEAR, m.birthDate, p.startDate) AS leeftijd,
35
+ m.postalCode AS postcode
36
+ FROM registrations r
37
+ JOIN registration_periods p ON p.id = r.periodId
38
+ JOIN `groups` g ON g.id = r.groupId AND g.deletedAt IS NULL
39
+ -- The tak, the member and the eenheid are each recorded per year, so the period is part of what
40
+ -- identifies the row to join to: a tak that is renamed or a member who moves changes the year it
41
+ -- happened in, not every year they were ever counted in.
42
+ LEFT JOIN takken dag ON dag.id = g.defaultAgeGroupId AND dag.periodId = r.periodId
43
+ JOIN members m ON m.id = r.memberId AND m.periodId = r.periodId
44
+ JOIN organizations o ON o.id = r.organizationId AND o.periodId = r.periodId
45
+ WHERE r.deactivatedAt IS NULL
46
+ AND r.registeredAt IS NOT NULL
47
+ -- Not the koepel's own organization: it is the national body rather than an eenheid, and the
48
+ -- ledenstatistieken count none of its structuurvrijwilligers. See `facts.sql`.
49
+ AND NOT EXISTS (SELECT 1 FROM platform pf WHERE pf.membershipOrganizationId = r.organizationId)
50
+ [[AND o.name = {{eenheid}}]]
51
+ -- @include aansluiting
52
+ -- @include ingeschreven-voor
53
+ )
@@ -0,0 +1,102 @@
1
+ -- One row per member per group per scoutsjaar: the grain every figure in the report is counted from.
2
+ --
3
+ -- The scoutsjaar is the period's name, not its id. A registration points at the period of its own
4
+ -- organization, and every organization holds its own row for the same year, so the id identifies a
5
+ -- unit's year rather than the year itself. The name is what those rows share, which makes it the
6
+ -- only thing a national figure can group on. Imported years are single platform-wide rows and fall
7
+ -- out of the same rule.
8
+ --
9
+ -- A registration counts when it is active: not cancelled and actually registered. A member in two
10
+ -- groups appears twice here, so member counts are always COUNT(DISTINCT).
11
+ --
12
+ -- Which kinds of group count is the reader's, through `ingeschreven-voor.sql`: the ledenstatistieken
13
+ -- open on the leeftijdsgroepen alone and can be asked for the activiteiten and the wachtlijsten
14
+ -- beside them. `group_type` carries what that filter reads, so a card that may not be asked -- the
15
+ -- aanlevering, which is about leden of a jeugdbeweging and about nothing else -- says so itself.
16
+ --
17
+ -- Two columns say what a registration counts as, and they answer different questions.
18
+ -- `tak_category` is what the tak counts as -- kinderen, leiding or volwassenen -- as `takken.sql`
19
+ -- decides it, and is null wherever nobody has said. The aanlevering reads that one, and so do the
20
+ -- figures that weigh leiding against kinderen: a sheet delivered to a department may not guess, and a
21
+ -- division with leiding on one side cannot lean on a fallback that reads every young leider as a
22
+ -- kind. `effective_category` is that same answer with the fallbacks the ledenstatistieken need behind
23
+ -- it -- the tak's age range, and then the member's own age at the start of the year -- so that nobody
24
+ -- drops out of a total for want of a tak that was never categorised.
25
+ --
26
+ -- That last fallback catches what the import could not name. The client's export leaves the tak empty
27
+ -- on the children of the years before 2020-2021; the import reads those from the member's age, except
28
+ -- where a date of birth puts them outside every tak. Without the fallback each of those few counts
29
+ -- towards the total while showing up in none of the three categories. The handful of adults among
30
+ -- them stay null, because nothing here tells leiding from volwassenen.
31
+ --
32
+ -- Three names for the same rows, each one dropping something the one before it keeps:
33
+ --
34
+ -- * `all_registrations` is every registration of the werkjaar, the ones that were cancelled during
35
+ -- it included. Only the aanlevering reads it: the department counts everyone who was registered
36
+ -- at some point between september and august, not who was still registered in august.
37
+ -- * `all_facts` keeps the ones that are still active, which is what the report means by a lid.
38
+ -- * `facts` is that without the koepel's own organization. Every figure of the ledenstatistieken
39
+ -- is counted from it, through `leden.sql`, which narrows it to one row per member.
40
+ WITH
41
+ -- @include takken
42
+ all_registrations AS (
43
+ SELECT
44
+ r.memberId AS member_id,
45
+ r.organizationId AS organization_id,
46
+ o.name AS `Eenheid`,
47
+ o.postalCode AS eenheid_postcode,
48
+ o.city AS eenheid_gemeente,
49
+ p.id AS period_id,
50
+ p.name AS `Scoutsjaar`,
51
+ p.startDate AS period_start,
52
+ g.type AS group_type,
53
+ COALESCE(dag.name, g.name) AS `Tak`,
54
+ dag.id AS tak_id,
55
+ dag.category AS tak_category,
56
+ dag.minAge AS tak_min_age,
57
+ dag.maxAge AS tak_max_age,
58
+ COALESCE(
59
+ dag.category,
60
+ CASE WHEN dag.maxAge < 18 THEN 'child' END,
61
+ CASE WHEN TIMESTAMPDIFF(YEAR, m.birthDate, p.startDate) < 18 THEN 'child' END
62
+ ) AS effective_category,
63
+ CASE m.gender
64
+ WHEN 'Male' THEN 'Man'
65
+ WHEN 'Female' THEN 'Vrouw'
66
+ WHEN 'Other' THEN 'Andere'
67
+ ELSE 'Onbekend'
68
+ END AS `Geslacht`,
69
+ m.birthDate AS birth_date,
70
+ TIMESTAMPDIFF(YEAR, m.birthDate, p.startDate) AS leeftijd,
71
+ m.postalCode AS postcode,
72
+ r.deactivatedAt AS deactivated_at
73
+ FROM registrations r
74
+ JOIN registration_periods p ON p.id = r.periodId
75
+ JOIN `groups` g ON g.id = r.groupId AND g.deletedAt IS NULL
76
+ -- The tak, the member and the eenheid are each recorded per year, so the period is part of what
77
+ -- identifies the row to join to: a tak that is renamed or a member who moves changes the year it
78
+ -- happened in, not every year they were ever counted in.
79
+ LEFT JOIN takken dag ON dag.id = g.defaultAgeGroupId AND dag.periodId = r.periodId
80
+ JOIN members m ON m.id = r.memberId AND m.periodId = r.periodId
81
+ JOIN organizations o ON o.id = r.organizationId AND o.periodId = r.periodId
82
+ WHERE r.registeredAt IS NOT NULL
83
+ [[AND p.name = {{scoutsjaar}}]]
84
+ [[AND o.name = {{eenheid}}]]
85
+ -- @include aansluiting
86
+ -- @include ingeschreven-voor
87
+ ),
88
+ -- Where a registration that was cancelled during the year drops out. It stays a registration of that
89
+ -- werkjaar -- someone who left in november was a lid of that year -- but it is no longer one of the
90
+ -- registrations the ledenstatistieken count, which are the ones that are still standing.
91
+ all_facts AS (
92
+ SELECT f.* FROM all_registrations f WHERE f.deactivated_at IS NULL
93
+ ),
94
+ -- The koepel's own organization is not an eenheid: it is the national body, and the client's report
95
+ -- counts the structuurvrijwilligers of its ploegen as nobody's leden and nobody's leiding. Which
96
+ -- organization it is comes from `platform.membershipOrganizationId`, the only thing that says so --
97
+ -- the import writes the koepel under that same id, so the years it owns drop out here exactly as the
98
+ -- synced ones do.
99
+ facts AS (
100
+ SELECT f.* FROM all_facts f
101
+ WHERE NOT EXISTS (SELECT 1 FROM platform pf WHERE pf.membershipOrganizationId = f.organization_id)
102
+ )
@@ -0,0 +1,49 @@
1
+ -- The GTP index (Gezond Toekomst Perspectief).
2
+ --
3
+ -- Bevers / 3 + Eekhoorns / 3 + Welpen / 3 + Wolven + JVG/JG-A + VG/G-J * 2 + Seniors * 3
4
+ -- + leiding - omkaderingscijfer * 2
5
+ --
6
+ -- A unit ideally scores 100 or more. The scale only says something up to roughly 150 members.
7
+ --
8
+ -- Not every platform weighs the index this way: ravot reads the age of a lid rather than the tak, in
9
+ -- `ravot/gtp.sql`, which is what `@include gtp` expands to there.
10
+ --
11
+ -- The takken are matched on `tak_id`, the id of the row in `default_age_groups` a group points at,
12
+ -- which is the same id `keeo/tak-categorie.sql` names them by. Not on the name, which the takken were
13
+ -- weighed by until it turned out to weigh almost nothing: the client's formula spells them as its own
14
+ -- system does -- `Jongverkenners/Jonggidsen - Aspiranten` against the platform's `Jongverkenners,
15
+ -- Jonggidsen, JVG's of Aspiranten` -- and three of the terms matched no tak at all. A name is also
16
+ -- what a tak carries per year, so a rename would drop it out of the index in the year it happened.
17
+ --
18
+ -- A group pointing at no tak has no id and weighs nothing, which is what keeps a group an eenheid
19
+ -- named `Bevers` itself from weighing as the tak it is named after. That makes asking for the category
20
+ -- as well unnecessary: an id is one tak, and `keeo/tak-categorie.sql` is what says that tak is
21
+ -- kinderen.
22
+ --
23
+ -- Eekhoorns and Wolven are not named by the client's formula. Wolven weigh one, like the JVG/JG-A they
24
+ -- sit just below. Eekhoorns weigh a third, with the takken of the same ages, and need no term of their
25
+ -- own: the platform holds one tak for the Bevers and the Zeehonden that an eenheid's Eekhoorns are
26
+ -- registered in, so the first term already counts them.
27
+ --
28
+ -- Reads from `leden`, which holds one row per member per eenheid: the tak a member counts under is
29
+ -- decided there, so nobody is weighed in two terms at once and leiding weigh as leiding only.
30
+ -- Members registered at two eenheden still hold a row each, which is why every term counts distinct
31
+ -- members.
32
+ --
33
+ -- What the years before 2020-2021 weigh rests on the import: the client's export names no tak on the
34
+ -- children of those years, and the import reads one from their age. The few it could not place --
35
+ -- a date of birth that falls outside every tak -- point at no tak and weigh nothing here.
36
+ --
37
+ -- The omkaderingscijfer is the one from `omkaderingscijfer.sql`, unrounded -- only what reaches the
38
+ -- screen is rounded. A unit without leiding has none, and NULLIF keeps the index null there rather
39
+ -- than letting the charts draw a zero.
40
+ ROUND(
41
+ ( COUNT(DISTINCT CASE WHEN tak_id = 'f274a949-9318-4c2b-ae35-e50114efe686' THEN member_id END) -- Bevers of Zeehonden, which an eenheid's Eekhoorns are registered in
42
+ + COUNT(DISTINCT CASE WHEN tak_id = '316ea554-675a-493e-a152-365012851ae3' THEN member_id END) ) / 3 -- Welpen
43
+ + COUNT(DISTINCT CASE WHEN tak_id = '01d62f7d-c3fa-4314-a33a-21da526a35ff' THEN member_id END) -- Wolven
44
+ + COUNT(DISTINCT CASE WHEN tak_id = '57143f32-e4d2-46a7-96e2-9bf82f121e1c' THEN member_id END) -- Jongverkenners, Jonggidsen, JVG's of Aspiranten
45
+ + 2 * COUNT(DISTINCT CASE WHEN tak_id = '0eacf56f-3a1d-4e15-bebc-2bc66fc74c7a' THEN member_id END) -- Verkenners, Gidsen, VG's of Juniors
46
+ + 3 * COUNT(DISTINCT CASE WHEN tak_id = 'b2275ec6-04ad-4232-bfe3-0eefed97f83b' THEN member_id END) -- Seniors
47
+ + COUNT(DISTINCT CASE WHEN tak_category = 'leader' THEN member_id END)
48
+ - 2 * COUNT(DISTINCT CASE WHEN tak_category = 'child' THEN member_id END)
49
+ / NULLIF(COUNT(DISTINCT CASE WHEN tak_category = 'leader' THEN member_id END), 0), 2)
@@ -0,0 +1,27 @@
1
+ -- Which registrations are counted, as the filter above the dashboards asks it: a registration stands
2
+ -- in a group, and the reader picks which kinds of group say someone is a lid.
3
+ --
4
+ -- Three names for the three kinds a group can be. A leeftijdsgroep is a tak of the eenheid and is
5
+ -- what the ledenstatistieken are read as; an activiteit is a single event someone registered for, and
6
+ -- a wachtlijst is a place they are waiting for. The last two are registrations at an eenheid without
7
+ -- being a lid of it, which is why the filter opens on leeftijdsgroepen alone and the other two are
8
+ -- something a reader asks for.
9
+ --
10
+ -- Said in those words rather than on `g.type` itself, because the filter is a list a reader picks
11
+ -- from and 'EventRegistration' is not a word this report uses anywhere else. A type the CASE does not
12
+ -- name falls under no option and drops out until the report says what to call it: a new kind of group
13
+ -- is nobody's lid until someone has decided that it is.
14
+ --
15
+ -- Nothing chosen drops the whole clause and counts every registration, the way the aansluiting filter
16
+ -- does. No dashboard opens that way -- the filter starts on Leeftijdsgroepen -- so it is what a
17
+ -- reader who empties the filter asked for rather than a state they can land in.
18
+ --
19
+ -- The years imported from the client's own statistics carry the default of the column, which is what
20
+ -- those years are: an export of takken and nothing else.
21
+ --
22
+ -- Belongs in a WHERE clause that has the group as `g`.
23
+ [[AND CASE g.type
24
+ WHEN 'Membership' THEN 'Leeftijdsgroepen'
25
+ WHEN 'EventRegistration' THEN 'Activiteiten'
26
+ WHEN 'WaitingList' THEN 'Wachtlijsten'
27
+ END IN ({{ingeschreven_voor}})]]
@@ -0,0 +1,20 @@
1
+ -- Elk scoutsjaar met het scoutsjaar erna, waarin het ledenbehoud van dat jaar gemeten wordt. Een
2
+ -- scoutsjaar is de naam van de periode: elke eenheid houdt een eigen periode-rij voor hetzelfde jaar,
3
+ -- dus alleen de naam is over alle eenheden heen hetzelfde.
4
+ --
5
+ -- Het ledenbehoud hoort bij het jaar van de leden zelf, niet bij het jaar waarin ze terugkomen: naast
6
+ -- scoutsjaar N staat het percentage van de leden van N dat in N+1 nog lid was, zoals het rapport van
7
+ -- de klant het ook zet. Het laatste jaar heeft daardoor geen cijfer -- `volgend` is dan NULL -- en
8
+ -- moet uit elke kaart gefilterd worden, anders leest het als 0% ledenbehoud.
9
+ --
10
+ -- Alleen jaren met leden vormen de ketting. Een periode zonder leden -- een jaar dat nog niet
11
+ -- gesynchroniseerd is, of een eigen periode van een eenheid -- zou het jaar ervoor anders op 0%
12
+ -- ledenbehoud zetten, en het jaar zelf heeft leden nodig om er lid in te kunnen zijn.
13
+ --
14
+ -- Hoort na `leden-per-jaar`, waar het de jaren met leden uit haalt.
15
+ , jaren AS (
16
+ SELECT name, MIN(startDate) AS startDate, LEAD(name) OVER (ORDER BY MIN(startDate)) AS volgend
17
+ FROM registration_periods
18
+ WHERE name IN (SELECT `Scoutsjaar` FROM leden_per_jaar)
19
+ GROUP BY name
20
+ )
@@ -0,0 +1,30 @@
1
+ -- The takken of keeo, by the id they carry in the platform configuration.
2
+ --
3
+ -- Said here rather than in a hand-filled column of the statistics database, so that the answer lives
4
+ -- with the report instead of in a database nobody can read back: such a column survives no rebuild,
5
+ -- and setting it again means an UPDATE nothing records. Written out in the query, it also stands in
6
+ -- front of whoever opens the question in Metabase, who can correct a tak there and tell us after.
7
+ --
8
+ -- The id rather than the name: a tak holds a row per year, and a rename would silently drop it out of
9
+ -- the list in the year it happened. Ordered as the report divides them.
10
+ --
11
+ -- This is the whole answer, so a tak of keeo that is missing here counts as nothing at all: it is
12
+ -- held by the totals but by none of the three categories, and by no figure that divides leiding from
13
+ -- kinderen. A tak added to the platform configuration has to be added here as well.
14
+ CASE dag.id
15
+ -- Kinderen
16
+ WHEN 'f274a949-9318-4c2b-ae35-e50114efe686' THEN 'child' -- Bevers of Zeehonden
17
+ WHEN '316ea554-675a-493e-a152-365012851ae3' THEN 'child' -- Welpen
18
+ WHEN '01d62f7d-c3fa-4314-a33a-21da526a35ff' THEN 'child' -- Wolven
19
+ WHEN '57143f32-e4d2-46a7-96e2-9bf82f121e1c' THEN 'child' -- Jongverkenners, Jonggidsen, JVG's of Aspiranten
20
+ WHEN '0eacf56f-3a1d-4e15-bebc-2bc66fc74c7a' THEN 'child' -- Verkenners, Gidsen, VG's of Juniors
21
+ WHEN 'b2275ec6-04ad-4232-bfe3-0eefed97f83b' THEN 'child' -- Seniors
22
+ -- Leiding
23
+ WHEN 'b90e0833-7047-4283-8e25-cd65c5f09129' THEN 'leader' -- Leiding
24
+ -- Volwassenen
25
+ WHEN '6fc0775e-2851-4fe1-90cd-af9c74243ccd' THEN 'adult' -- Stam
26
+ WHEN '77c2530c-2834-4da3-83c5-1cff9cf05c7e' THEN 'adult' -- Nationaal vrijwilligers
27
+ WHEN 'd4bb14bf-4a52-44e4-a014-3333c5ebb36a' THEN 'adult' -- Nationaal vrijwilligers, rechtstreeks aan FOS
28
+ WHEN '8d42d2df-7787-4959-995d-c5a85d0e48c9' THEN 'adult' -- Ereleden
29
+ WHEN 'ac8848e9-9868-44a1-a057-2a189cce68ea' THEN 'adult' -- Ondersteunende leden, VZW, Steuncomité of Helpende handen
30
+ END AS category
@@ -0,0 +1,29 @@
1
+ -- Wie in welk scoutsjaar lid was, over het hele platform en zonder filters op wie meetelt.
2
+ --
3
+ -- Dit is de "is nog lid"-kant van het ledenbehoud. Een lid dat het jaar erna bij een andere eenheid
4
+ -- opduikt telt als blijver: zo rekent het rapport van de klant het ook. De cijfers van 9e Wandelaar
5
+ -- tonen het verschil — 38, 54 en 46 blijvers met deze telling, 37, 51 en 45 als alleen dezelfde
6
+ -- eenheid meetelt.
7
+ --
8
+ -- Bewust niet uit `facts` gehaald: die is gefilterd op de gekozen eenheid, en dan zou een lid dat
9
+ -- verhuist juist wel als vertrekker tellen.
10
+ --
11
+ -- Op één filter na. Waar iemand lid is doet er niet toe, wat voor inschrijving het is wel: als de
12
+ -- teller enkel leeftijdsgroepen telt en de noemer elke inschrijving, dan is wie vertrokken is maar
13
+ -- het jaar erna één activiteit meedoet een blijver. `ingeschreven-voor.sql` staat daarom aan beide
14
+ -- kanten van de breuk, zodat "is nog lid" hetzelfde betekent als "was lid".
15
+ , leden_per_jaar AS (
16
+ SELECT DISTINCT
17
+ r.memberId AS member_id,
18
+ p.name AS `Scoutsjaar`
19
+ FROM registrations r
20
+ JOIN registration_periods p ON p.id = r.periodId
21
+ JOIN `groups` g ON g.id = r.groupId AND g.deletedAt IS NULL
22
+ WHERE r.deactivatedAt IS NULL
23
+ AND r.registeredAt IS NOT NULL
24
+ -- Wie het jaar erna alleen nog bij de koepel zelf ingeschreven staat is geen blijver: dat is
25
+ -- dezelfde organisatie die `facts` weglaat, en een cijfer dat hier wel meetelt en daar niet zou
26
+ -- een ledenbehoud boven de leden zetten waar het over gaat.
27
+ AND NOT EXISTS (SELECT 1 FROM platform pf WHERE pf.membershipOrganizationId = r.organizationId)
28
+ -- @include ingeschreven-voor
29
+ )
@@ -0,0 +1,39 @@
1
+ -- One row per member per eenheid per scoutsjaar: what someone is, decided once, before the figures
2
+ -- that weigh leiding against kinderen count them.
3
+ --
4
+ -- `facts` holds a row per registration, so a member registered in two takken of the same eenheid
5
+ -- stands in it twice. Counted as they stand there, someone who is leiding in one tak and lid in
6
+ -- another is counted as both -- in the omkaderingscijfer as a kind and as the leider they are
7
+ -- divided by at once -- and the GTP index weighs such a member in two of its terms. This picks the
8
+ -- one registration that says what they are, the way `jeugdbewegingen.sql` picks it for the
9
+ -- aanlevering: leiding beats lid, and between two takken the oldest one wins, since that is the one a
10
+ -- member has grown into. The name of the tak breaks a tie no age can, so that two runs of the same
11
+ -- query cannot pick differently.
12
+ --
13
+ -- What a member is comes from `tak_category`, what the tak was recorded as, and never from
14
+ -- `effective_category`, which falls back to the member's own age. That fallback cannot tell leiding
15
+ -- from anything, so a leider of sixteen would read as a kind and be counted on both sides of the same
16
+ -- division. It does decide between two rows that the takken leave equally unsaid, so that a member
17
+ -- whose only reading is the fallback keeps it rather than losing it to whichever row sorted first.
18
+ --
19
+ -- Every member keeps a row, whether their tak is categorised or not, and every row keeps both
20
+ -- columns: a card that counts kinderen the way the totals do goes on reading `effective_category`
21
+ -- here, and only counts a member once now.
22
+ --
23
+ -- Belongs after `facts` or `facts-alle-jaren`, whichever grain the card reads.
24
+ , leden AS (
25
+ SELECT g.* FROM (
26
+ SELECT
27
+ f.*,
28
+ ROW_NUMBER() OVER (
29
+ PARTITION BY f.organization_id, f.`Scoutsjaar`, f.member_id
30
+ ORDER BY
31
+ CASE f.tak_category WHEN 'leader' THEN 3 WHEN 'child' THEN 2 WHEN 'adult' THEN 1 ELSE 0 END DESC,
32
+ CASE f.effective_category WHEN 'leader' THEN 3 WHEN 'child' THEN 2 WHEN 'adult' THEN 1 ELSE 0 END DESC,
33
+ f.tak_min_age DESC,
34
+ f.`Tak`
35
+ ) AS rang
36
+ FROM facts f
37
+ ) g
38
+ WHERE g.rang = 1
39
+ )
@@ -0,0 +1,17 @@
1
+ -- The omkaderingscijfer: how many children a leider looks after on average.
2
+ --
3
+ -- Aantal kinderen / Aantal leiding
4
+ --
5
+ -- Low is good, and from 10 upwards keeping an eye on everyone gets hard. Also the divisor of the GTP
6
+ -- index, which takes it from here unrounded -- only what reaches the screen is rounded here.
7
+ --
8
+ -- Counts the kinderen and the leiding of a categorised tak, so that nobody stands on both sides of
9
+ -- the division: someone who is leiding in one tak and lid in another is a leider here and not also
10
+ -- one of the children they look after. A member whose tak nobody has categorised is neither, and is
11
+ -- counted by the totals beside this rather than by the division -- which is why `Aantal kinderen`
12
+ -- divided by `Aantal leiding` off the same page can come out slightly higher.
13
+ --
14
+ -- Reads from `leden`, one row per member per eenheid, where that is decided.
15
+ ROUND(
16
+ COUNT(DISTINCT CASE WHEN tak_category = 'child' THEN member_id END)
17
+ / NULLIF(COUNT(DISTINCT CASE WHEN tak_category = 'leader' THEN member_id END), 0), 2)
@@ -0,0 +1,8 @@
1
+ -- Where a postal code is, so Metabase can put a point on the map for it.
2
+ --
3
+ -- The maps attach this with a LEFT JOIN, because what members have in their postal code field is not
4
+ -- always a Belgian postal code: typos, a Dutch one, or a whole address typed into the box. Those
5
+ -- members keep counting towards the totals, they just get no pin. An INNER JOIN would drop them.
6
+ , postcode_coordinaten AS (
7
+ SELECT postalCode, latitude, longitude FROM postal_codes
8
+ )
@@ -0,0 +1,32 @@
1
+ -- The GTP index (Gezond Toekomst Perspectief) as ravot weighs it.
2
+ --
3
+ -- leden < 10 / 3 + leden 10-13 + leden 14-15 * 2 + leden 16 * 3
4
+ -- + leiding * 1,5 - omkaderingscijfer * 2
5
+ --
6
+ -- The same index as `../gtp.sql` on the same rows, weighed differently: ravot reads the age of a lid
7
+ -- rather than the tak they are in, and counts a leider as one and a half.
8
+ --
9
+ -- A unit ideally scores 100 or more. The scale only says something up to roughly 150 members.
10
+ --
11
+ -- `leeftijd` is the age at the start of the werkjaar, the age the rest of the report charts members
12
+ -- by. A kind of seventeen or older is in none of the buckets the formula names and weighs nothing
13
+ -- there, nor in the omkaderingscijfer it subtracts, and a member whose date of birth is unknown has
14
+ -- no age and falls outside them the same way.
15
+ --
16
+ -- Reads from `leden`, which holds one row per member per eenheid with what they are decided on it:
17
+ -- `tak_category` is the tak they were recorded in rather than their age, so a leider of sixteen
18
+ -- weighs as leiding and not as a kind of sixteen as well, and a kind of a group nobody has
19
+ -- categorised weighs nothing. Members registered at two eenheden still hold a row each, which is why
20
+ -- every term counts distinct members.
21
+ --
22
+ -- The omkaderingscijfer is the one from `omkaderingscijfer.sql` beside this, over the same kinderen
23
+ -- under seventeen, unrounded -- only what reaches the screen is rounded. A unit without leiding has
24
+ -- none, and NULLIF keeps the index null there rather than letting the charts draw a zero.
25
+ ROUND(
26
+ COUNT(DISTINCT CASE WHEN tak_category = 'child' AND leeftijd < 10 THEN member_id END) / 3
27
+ + COUNT(DISTINCT CASE WHEN tak_category = 'child' AND leeftijd BETWEEN 10 AND 13 THEN member_id END)
28
+ + 2 * COUNT(DISTINCT CASE WHEN tak_category = 'child' AND leeftijd BETWEEN 14 AND 15 THEN member_id END)
29
+ + 3 * COUNT(DISTINCT CASE WHEN tak_category = 'child' AND leeftijd = 16 THEN member_id END)
30
+ + 1.5 * COUNT(DISTINCT CASE WHEN tak_category = 'leader' THEN member_id END)
31
+ - 2 * COUNT(DISTINCT CASE WHEN tak_category = 'child' AND leeftijd < 17 THEN member_id END)
32
+ / NULLIF(COUNT(DISTINCT CASE WHEN tak_category = 'leader' THEN member_id END), 0), 2)
@@ -0,0 +1,25 @@
1
+ -- The omkaderingscijfer as ravot counts it: how many kinderen a leider looks after on average.
2
+ --
3
+ -- Aantal kinderen jonger dan 17 / Aantal leiding
4
+ --
5
+ -- The same figure as `../omkaderingscijfer.sql` on the same rows, over fewer kinderen: ravot reads
6
+ -- the age of a lid rather than the tak they are in, here as in `gtp.sql` beside it, and counts only
7
+ -- the kinderen that index weighs. Low is good, and from 10 upwards keeping an eye on everyone gets
8
+ -- hard. Also the divisor of the GTP index, which takes it from here unrounded -- only what reaches
9
+ -- the screen is rounded here.
10
+ --
11
+ -- `leeftijd` is the age at the start of the werkjaar, the age the rest of the report charts members
12
+ -- by. A kind of seventeen or older weighs in no term of the index and is outside this division too,
13
+ -- and a member whose date of birth is unknown has no age and falls outside it the same way.
14
+ --
15
+ -- Counts the kinderen and the leiding of a categorised tak, so that nobody stands on both sides of
16
+ -- the division: someone who is leiding in one tak and lid in another is a leider here and not also
17
+ -- one of the children they look after. A member whose tak nobody has categorised is neither, and is
18
+ -- counted by the totals beside this rather than by the division -- which is why `Aantal kinderen`
19
+ -- divided by `Aantal leiding` off the same page comes out higher: those totals count a kind by the
20
+ -- category of their tak, so they hold the kinderen of seventeen and over as well.
21
+ --
22
+ -- Reads from `leden`, one row per member per eenheid, where that is decided.
23
+ ROUND(
24
+ COUNT(DISTINCT CASE WHEN tak_category = 'child' AND leeftijd < 17 THEN member_id END)
25
+ / NULLIF(COUNT(DISTINCT CASE WHEN tak_category = 'leader' THEN member_id END), 0), 2)
@@ -0,0 +1,28 @@
1
+ -- The takken of ravot, by the id they carry in the platform configuration.
2
+ --
3
+ -- Said here rather than in a hand-filled column of the statistics database, for the reasons
4
+ -- `../tak-categorie.sql` gives. This is the whole answer, so a tak of ravot that is missing here
5
+ -- counts as nothing at all, and a tak added to the platform configuration has to be added here too.
6
+ --
7
+ -- The ondersteunende leden are volwassenen and may not be categorised as leiding: the
8
+ -- omkaderingscijfer and the GTP index would then read them as leiding that the kinderen of an eenheid
9
+ -- are looked after by. The aanlevering, which does deliver them among the leiding because the
10
+ -- department has no third word for them, names the tak itself instead -- see `type-deelnemers.sql`.
11
+ --
12
+ -- The two oldest takken of kinderen carry members of seventeen and over, which is what
13
+ -- `omkaderingscijfer.sql` means when it says the totals beside it hold those as well. They weigh in
14
+ -- no term of the GTP index, which stops at sixteen.
15
+ CASE dag.id
16
+ -- Kinderen
17
+ WHEN 'bd63a6ef-d4a1-497d-87a5-d7c36b4ad220' THEN 'child' -- Leeuwkes, Kabouters of Sloebers (6-8)
18
+ WHEN '23607074-624b-472f-926f-c719bb44e314' THEN 'child' -- Springers of Pagadders (8-10)
19
+ WHEN '5730f613-fb72-465b-b902-45b281a0e8b8' THEN 'child' -- Jongknapen, Roodkapjes of Joro's (10-12)
20
+ WHEN '3d56a0b2-9f4b-46ac-998b-d45a9b64cab2' THEN 'child' -- Knapen, Jimmers of Knimmers (12-14)
21
+ WHEN '03680919-689c-4df1-8976-bb71758cc025' THEN 'child' -- Sjo'ers, Simmers of Jonghernieuwers (14-16)
22
+ WHEN 'bed9b513-e0ff-4cc3-a0f3-1c021fc880a9' THEN 'child' -- +16, leiding in spe (16 en ouder)
23
+ WHEN '1ad6b686-d5fa-4168-8fa2-064d49f8c0e8' THEN 'child' -- Hernieuwers
24
+ -- Leiding
25
+ WHEN 'e3ec8d48-0d10-4f5d-9e50-dd3151c6666b' THEN 'leader' -- Leiding
26
+ -- Volwassenen
27
+ WHEN 'a28d290c-af71-4282-92cc-2224a18d3091' THEN 'adult' -- Ondersteunende leden
28
+ END AS category
@@ -0,0 +1,22 @@
1
+ -- What a deelnemer of a lokale groep is delivered as, as ravot counts it: the same as
2
+ -- `../type-deelnemers.sql` with the ondersteunende leden among the leiding.
3
+ --
4
+ -- Ondersteunende leden are volwassenen who carry a group rather than a tak of kinderen, and the
5
+ -- metadatafiche counts the volwassen begeleiders, kassabeheerders and secretarissen of a group as
6
+ -- leiding -- the department has no third word for them. The tak is not categorised as leiding, and
7
+ -- may not be: the omkaderingscijfer and the GTP index would then read it as leiding the kinderen of
8
+ -- an eenheid are looked after by. The aanlevering therefore names the tak itself.
9
+ --
10
+ -- Named by `tak_id`, the id of the row in `default_age_groups`, the way `gtp.sql` weighs the takken
11
+ -- it names: a name is what a tak carries per year, so a rename would stop delivering it in the year
12
+ -- it happened. The id is the one `tak-categorie.sql` beside this names it by.
13
+ --
14
+ -- A group an eenheid named `Ondersteunende leden` itself points at no tak, so it carries no id and is
15
+ -- delivered as neither. Under the name it was matched by before, such a group was delivered as
16
+ -- leiding.
17
+ CASE
18
+ WHEN f.tak_category = 'leader' THEN 2
19
+ WHEN f.tak_id = 'a28d290c-af71-4282-92cc-2224a18d3091' THEN 2 -- Ondersteunende leden
20
+ WHEN f.tak_category = 'child' THEN 1
21
+ ELSE 0
22
+ END
@@ -0,0 +1,18 @@
1
+ -- What a tak counts as -- kinderen, leiding or volwassenen -- for the platform reading the report.
2
+ --
3
+ -- Nothing in the administration knows it. The platform configuration has no such field, and the ages
4
+ -- do not answer it, since leiding and stam carry no age range and a tak of kinderen need not carry
5
+ -- one either. The statistics database does not hold it either: it kept a hand-filled `category`
6
+ -- column on `default_age_groups` until the reports began naming their takken themselves, and that
7
+ -- column is dropped.
8
+ --
9
+ -- So a platform says which of its takken are which here, in `includes/<env>/tak-categorie.sql`, which
10
+ -- is what `@include tak-categorie` expands to there. This unqualified one is what a platform that has
11
+ -- not is left with: nothing. That is not a failure -- the reports count a tak nobody has categorised
12
+ -- separately rather than guessing at it, and `effective_category` still reads the ages behind it so
13
+ -- that no kind drops out of a total -- but every figure dividing leiding from kinderen stays empty
14
+ -- until the list is written.
15
+ --
16
+ -- Belongs in the select list of the `takken` fragment, which has the row of `default_age_groups` as
17
+ -- `dag`. It is the column the rest of the report reads as `dag.category`.
18
+ CAST(NULL AS CHAR(16)) AS category
@@ -0,0 +1,20 @@
1
+ -- The takken every organization's groups map onto, as the report reads them: the rows of
2
+ -- `default_age_groups` with their category decided.
3
+ --
4
+ -- A fragment of its own because both grains of `facts` join it, and because it is where the one thing
5
+ -- about a tak that is neither synced nor derivable is settled -- see `tak-categorie.sql`. `category`
6
+ -- is no column of `default_age_groups`: it is added here, which is why the takken are read through
7
+ -- this rather than joined straight from the table. Everything downstream reads it as `dag`, so a
8
+ -- tak's name, ages and category are asked for the same way.
9
+ --
10
+ -- Belongs at the head of a `WITH`, and carries the comma to whatever CTE follows it.
11
+ takken AS (
12
+ SELECT
13
+ dag.id,
14
+ dag.periodId,
15
+ dag.name,
16
+ dag.minAge,
17
+ dag.maxAge,
18
+ -- @include tak-categorie
19
+ FROM default_age_groups dag
20
+ ),
@@ -0,0 +1,14 @@
1
+ -- Het tarief waaraan een lidgeld is aangerekend: het standaardtarief, of het verlaagde tarief van de
2
+ -- koepel. Dat is wat de rapporten "type lidgeld" noemen -- de aansluiting zegt waarvoor iemand is
3
+ -- aangesloten, dit zegt wat ervoor betaald werd.
4
+ --
5
+ -- De naam van het verlaagde tarief is die van de koepel zelf (SOMkort, kansentarief). Ze staat op de
6
+ -- platformrij, want alleen het platform zelf weet hoe het dat tarief noemt. Er is één zo'n rij, dus
7
+ -- de subquery levert één naam; een platform dat er geen naam aan geeft valt terug op de bewoording
8
+ -- hier, en een databank waarin nog niets gesynchroniseerd is ook.
9
+ --
10
+ -- Hoort bij een query die de lidgelden als `mpm` heeft.
11
+ CASE WHEN mpm.reducedPrice = 1
12
+ THEN COALESCE((SELECT pf.reducedPriceName FROM platform pf WHERE pf.reducedPriceName IS NOT NULL LIMIT 1), 'Verlaagd tarief')
13
+ ELSE 'Standaardtarief'
14
+ END
@@ -0,0 +1,14 @@
1
+ -- What a deelnemer of a lokale groep is delivered as on the aanlevering: leiding, leden, or neither.
2
+ --
3
+ -- Read from `tak_category`, what the takken were recorded as, on a registration of
4
+ -- `all_registrations` as `f`. Only the two words the template allows are delivered: a tak recorded as
5
+ -- volwassenen is neither, and a tak nobody has categorised delivers nobody rather than being guessed
6
+ -- at.
7
+ --
8
+ -- The numbers rank rather than label -- leiding beats leden, and leden beats a tak that is neither --
9
+ -- so the MAX over a member's registrations picks the strongest thing any of them says.
10
+ --
11
+ -- Not every platform delivers the same people as leiding: ravot counts its ondersteunende leden
12
+ -- among them, in `ravot/type-deelnemers.sql`, which is what `@include type-deelnemers` expands to
13
+ -- there.
14
+ CASE WHEN f.tak_category = 'leader' THEN 2 WHEN f.tak_category = 'child' THEN 1 ELSE 0 END
@@ -0,0 +1,23 @@
1
+ -- The ULDK figures per eenheid: the kinderen and the leiding of every eenheid split by geslacht, one
2
+ -- row per eenheid.
3
+ --
4
+ -- Shared because the totals under the table are the same figures added up. Counted again in a query
5
+ -- of their own they would be a second reading of the same thing, and a total that is not the sum of
6
+ -- the column above it reads as a mistake in either of the two.
7
+ --
8
+ -- Belongs after `leden`.
9
+ , uldk AS (
10
+ SELECT
11
+ `Eenheid` AS `Name`,
12
+ eenheid_gemeente AS `City`,
13
+ COUNT(DISTINCT CASE WHEN effective_category = 'child' AND `Geslacht` = 'Man' THEN member_id END) AS `Aantal kinderen/Man`,
14
+ COUNT(DISTINCT CASE WHEN effective_category = 'child' AND `Geslacht` = 'Vrouw' THEN member_id END) AS `Aantal kinderen/Vrouw`,
15
+ COUNT(DISTINCT CASE WHEN effective_category = 'child' AND `Geslacht` = 'Andere' THEN member_id END) AS `Aantal kinderen/Andere`,
16
+ COUNT(DISTINCT CASE WHEN effective_category = 'child' AND `Geslacht` = 'Onbekend' THEN member_id END) AS `Aantal kinderen/Onbekend`,
17
+ COUNT(DISTINCT CASE WHEN effective_category = 'leader' AND `Geslacht` = 'Man' THEN member_id END) AS `Aantal leiding/Man`,
18
+ COUNT(DISTINCT CASE WHEN effective_category = 'leader' AND `Geslacht` = 'Vrouw' THEN member_id END) AS `Aantal leiding/Vrouw`,
19
+ COUNT(DISTINCT CASE WHEN effective_category = 'leader' AND `Geslacht` = 'Andere' THEN member_id END) AS `Aantal leiding/Andere`,
20
+ COUNT(DISTINCT CASE WHEN effective_category = 'leader' AND `Geslacht` = 'Onbekend' THEN member_id END) AS `Aantal leiding/Onbekend`
21
+ FROM leden
22
+ GROUP BY `Eenheid`, eenheid_gemeente
23
+ )