@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,221 @@
1
+ -- @tab jeugdbewegingen
2
+ -- title: Jeugdbewegingen
3
+ -- dashboard: Groepen en Deelnemers - Departement Jeugd
4
+ -- description: De jaarlijkse aanlevering 'Groepen en Deelnemers Jeugdbewegingen' aan het Departement Cultuur, Jeugd en Media. Eén kaart per tabblad van het sjabloon: download ze via het pijltje rechtsonder op de kaart als .xlsx en plak ze in het aanleversjabloon.
5
+ -- filters: scoutsjaar, aansluiting
6
+ --
7
+ -- The dataset a koepel delivers every september, over the werkjaar that ended in august. One card per
8
+ -- sheet of the delivery template, holding the columns the koepel fills in, in the order and under the
9
+ -- exact names that template gives them. The columns the department fills in itself -- Werkjaar,
10
+ -- Type_organisatie, NIS-code -- are deliberately absent.
11
+ --
12
+ -- On a dashboard of its own, unlike every other tab here: this mirrors no page of the client's own
13
+ -- report, and what it is for -- an aanlevering to a government department, once a year -- has nothing
14
+ -- to do with the figures the ledenstatistieken are read for.
15
+ --
16
+ -- A werkjaar runs september to august, which is what a period spans here, so the scoutsjaar filter is
17
+ -- what picks one. No sheet carries it as a column, since the department fills that in itself, but it
18
+ -- decides which organisations and which deelnemers each of them holds.
19
+ --
20
+ -- The aansluiting filter reaches the two deelnemers sheets and neither of the organisatie ones:
21
+ -- those list which groups existed in the werkjaar, which is not a question about members. Delivering
22
+ -- under a chosen aansluiting therefore hands the department groups whose deelnemers were counted
23
+ -- under it only -- the aanlevering itself is filed with the filter empty.
24
+ --
25
+ -- What the ledenstatistieken offer as "Ingeschreven voor" is not offered here. The department counts
26
+ -- the deelnemers of a jeugdbeweging: someone waiting for a place has not joined one, and someone who
27
+ -- came to a single activity is a deelnemer of that activity rather than of the group that held it.
28
+ -- Both sheets therefore say `group_type = 'Membership'` themselves rather than leaving it to a filter
29
+ -- this dashboard does not show -- an unanswered filter counts every registration, which is the wrong
30
+ -- way for a sheet to fail.
31
+
32
+ -- @card organisatie-bovenlokaal
33
+ -- title: Organisatie_Bovenlokaal
34
+ -- display: table
35
+ -- size: full
36
+ -- columns: ID_Organisatie, Naam_Organisatie
37
+ -- description: Tabblad 'Organisatie_Bovenlokaal': de bovenlokale of nationale ondersteuningsstructuur, namelijk de eigen organisatie van de koepel.
38
+ --
39
+ -- One row: the organization the platform runs itself, which `platform.membershipOrganizationId`
40
+ -- points at. Everything else in the administration is a local group, and the ploegen of the koepel
41
+ -- count as a single structure, so this sheet holds exactly that one organization.
42
+ --
43
+ -- Named as it stood in the werkjaar, which is why the name comes from `organizations` and not from
44
+ -- the platform: a unit's name is recorded per period, and a rename lands in the year it happened in.
45
+ -- A werkjaar the koepel's own organization holds no row for -- one it had no registrations in --
46
+ -- delivers nothing rather than a name from another year.
47
+ SELECT
48
+ o.id AS `ID_Organisatie`,
49
+ o.name AS `Naam_Organisatie`
50
+ FROM organizations o
51
+ JOIN platform pf ON pf.membershipOrganizationId = o.id
52
+ JOIN registration_periods p ON p.id = o.periodId [[AND p.name = {{scoutsjaar}}]]
53
+ GROUP BY o.id, o.name
54
+ ORDER BY o.name
55
+
56
+ -- @card deelnemers-bovenlokaal
57
+ -- title: Deelnemers_Bovenlokaal
58
+ -- display: table
59
+ -- size: full
60
+ -- columns: ID_Organisatie, Geboortejaar_deelnemers, Gender_deelnemers, Aantal_deelnemers
61
+ -- description: Tabblad 'Deelnemers_Bovenlokaal': de structuurvrijwilligers van de koepel, per geboortejaar en geslacht, met een aansluiting in dat werkjaar. Unieke personen, geen inschrijvingen: zo vraagt de metadatafiche het voor de nationale ploegen.
62
+ --
63
+ -- The deelnemers of the structure the sheet above delivers: everyone aangesloten at the koepel's own
64
+ -- organization in that werkjaar. Being registered there is the engagement that makes someone a
65
+ -- structuurvrijwilliger -- nothing in the administration says what a person does within a ploeg -- so
66
+ -- a registration with an aansluiting behind it is what this counts.
67
+ --
68
+ -- Unique people rather than registrations, which is what the metadatafiche asks for at this one
69
+ -- organization: the national ploegen count as a single structure, so someone in two of them is one
70
+ -- deelnemer. Someone who is also leiding at a local group keeps counting there as well, on the sheet
71
+ -- of that group -- the two are counted at different organizations.
72
+ --
73
+ -- An empty cell wherever the administration has no answer, which is what the metadatafiche asks for
74
+ -- rather than a value of its own: a member without a date of birth gets no geboortejaar, and one
75
+ -- whose geslacht was never filled in gets no letter, since the CASE has no ELSE to fall back on.
76
+ --
77
+ -- Read from `all_registrations` rather than from `facts`, on two counts. The ledenstatistieken leave
78
+ -- this organization out and this sheet is the one thing that is about it; and they leave out a
79
+ -- registration that was cancelled during the year, while the department counts everyone who was
80
+ -- registered at some point in the werkjaar -- someone who stopped in november was a deelnemer of that
81
+ -- year, and the aansluiting the koepel charged them says so.
82
+ -- @include facts
83
+ SELECT
84
+ f.organization_id AS `ID_Organisatie`,
85
+ YEAR(f.birth_date) AS `Geboortejaar_deelnemers`,
86
+ CASE f.`Geslacht` WHEN 'Man' THEN 'M' WHEN 'Vrouw' THEN 'V' ELSE NULL END AS `Gender_deelnemers`,
87
+ COUNT(DISTINCT f.member_id) AS `Aantal_deelnemers`
88
+ FROM all_registrations f
89
+ JOIN platform pf ON pf.membershipOrganizationId = f.organization_id
90
+ WHERE
91
+ -- @include aangesloten
92
+ -- A ploeg of the koepel, never one of the national events it also runs its registrations for: those
93
+ -- are open to the deelnemers of every group, and counted here every one of them would be delivered
94
+ -- as a structuurvrijwilliger of the bovenlokale structuur.
95
+ AND f.group_type = 'Membership'
96
+ GROUP BY `ID_Organisatie`, `Geboortejaar_deelnemers`, `Gender_deelnemers`
97
+ ORDER BY `Geboortejaar_deelnemers`, `Gender_deelnemers`
98
+
99
+ -- @card organisatie-lokale-groep
100
+ -- title: Organisatie_Lokale_groep
101
+ -- display: table
102
+ -- size: full
103
+ -- columns: ID_Organisatie, Naam_Organisatie, Postcode
104
+ -- description: Tabblad 'Organisatie_Lokale_groep': elke lokale jeugdbewegingsgroep met haar postcode. De eigen organisatie van de koepel staat hier niet in, die hoort op het tabblad Organisatie_Bovenlokaal. DCJM vult zelf Werkjaar, Type_organisatie en NIS-code aan.
105
+ --
106
+ -- Every organization in the administration except the one the platform runs itself: that one is the
107
+ -- bovenlokale structuur of the sheet above, and the department reads one organization per row across
108
+ -- the two, so a unit on both would be a unit counted twice. Dropped on
109
+ -- `platform.membershipOrganizationId`, the way every card of the ledenstatistieken drops it.
110
+ --
111
+ -- Read from `organizations` rather than from the members: what the sheet lists is which groups
112
+ -- existed in that werkjaar, so a unit that registered nobody is a group with no deelnemers rather
113
+ -- than no group. That also means a unit that has stopped keeps being delivered while its year is
114
+ -- still open, since a row here is not evidence of anything having happened.
115
+ --
116
+ -- The template's datatype for a postcode is a four digit number, and what the administration holds is
117
+ -- free text: a foreign postcode, or an entire address typed into the box. Anything that is not four
118
+ -- digits leaves the cell empty -- a required field the koepel can see and fill in -- rather than
119
+ -- delivering a number that is wrong.
120
+ SELECT
121
+ o.id AS `ID_Organisatie`,
122
+ o.name AS `Naam_Organisatie`,
123
+ CASE WHEN o.postalCode REGEXP '^[0-9]{4}$' THEN CAST(o.postalCode AS UNSIGNED) END AS `Postcode`
124
+ FROM organizations o
125
+ JOIN registration_periods p ON p.id = o.periodId [[AND p.name = {{scoutsjaar}}]]
126
+ WHERE NOT EXISTS (SELECT 1 FROM platform pf WHERE pf.membershipOrganizationId = o.id)
127
+ GROUP BY `ID_Organisatie`, `Naam_Organisatie`, `Postcode`
128
+ ORDER BY `Naam_Organisatie`
129
+
130
+ -- @card deelnemers-lokale-groep
131
+ -- title: Deelnemers_Lokale_groep
132
+ -- display: table
133
+ -- size: full
134
+ -- columns: ID_Organisatie, Type_deelnemers, Geboortejaar_deelnemers, Gender_deelnemers, Aantal_deelnemers
135
+ -- description: Tabblad 'Deelnemers_Lokale_groep': de leden en de leiding van elke lokale groep, per geboortejaar en geslacht, met een aansluiting in dat werkjaar. Wie leiding is in de ene tak en lid in de andere, telt enkel als leiding. Takken zonder categorie leveren niemand: vul die eerst aan.
136
+ -- description@ravot: Tabblad 'Deelnemers_Lokale_groep': de leden en de leiding van elke lokale groep, per geboortejaar en geslacht, met een aansluiting in dat werkjaar. De tak 'Ondersteunende leden' telt hier mee als leiding. Wie leiding is in de ene tak en lid in de andere, telt enkel als leiding. Takken zonder categorie leveren niemand: vul die eerst aan.
137
+ --
138
+ -- The deelnemers of the groups the sheet above delivers, split into the two words the template
139
+ -- allows: 'leden' and 'leiding', that exact spelling.
140
+ --
141
+ -- Read from `tak_category`, what the takken were recorded as, and never from `effective_category`,
142
+ -- which the ledenstatistieken split by. That one falls back to the ages so nobody drops out of a
143
+ -- total, and the ages cannot tell leiding from anything: a leider of seventeen reads as a kind and
144
+ -- one of twenty as nothing at all. A sheet that goes to a department may not guess, so a tak nobody
145
+ -- has categorised delivers nobody here -- visibly missing rather than quietly counted as leden.
146
+ --
147
+ -- Only the two the template allows are delivered. A tak recorded as volwassenen is neither, and its
148
+ -- members are left out of the sheet entirely; the metadatafiche does count the volwassen
149
+ -- begeleiders, kassabeheerders and secretarissen of a group as leiding, so a koepel with such a tak
150
+ -- has to say whether it is leiding rather than leaving it as volwassenen. Which of the two a
151
+ -- registration is worth is `type-deelnemers.sql`, since a koepel with a tak the categories cannot
152
+ -- say this of -- the ondersteunende leden of ravot -- names it there and nowhere else.
153
+ --
154
+ -- The numbers that fragment gives rank rather than label: leiding beats leden, and leden beats a tak
155
+ -- that is neither, so the MAX below picks the strongest thing any registration of that member says.
156
+ --
157
+ -- Decided once per member per group, before anything is counted. Someone can be a lid in one tak and
158
+ -- leiding in another of the same unit, and the metadatafiche is explicit that they are leiding there
159
+ -- and not a lid; counted per registration they would be one person delivered in both rows, and the
160
+ -- group would report more deelnemers than it has. The date of birth and the geslacht are taken the
161
+ -- same way, so that a member whose answer was corrected between two werkjaren cannot split into two
162
+ -- people either.
163
+ --
164
+ -- Decided by the registrations that still stand, and by the cancelled ones only when none of them do.
165
+ -- A cancelled registration says someone was there, not what they were: an administrator who puts a
166
+ -- lid in the Leiding tak by mistake and undoes it would otherwise leave them leiding for the rest of
167
+ -- the werkjaar, while the registration they really hold says what they are. A member whose
168
+ -- registrations at the group were all cancelled -- someone who left during the year -- has nothing
169
+ -- else to be read from, and is what the cancelled ones are kept for.
170
+ --
171
+ -- One row per member per group is also what the counting asks for. The metadatafiche counts
172
+ -- inschrijvingen rather than unique inschrijvers, and says what it means by that: someone registered
173
+ -- at two groups counts at both. Within one group they are one deelnemer, however many takken they are
174
+ -- registered in.
175
+ --
176
+ -- Read from `all_registrations`, which keeps the registrations that were cancelled during the year:
177
+ -- someone who stopped in november was a deelnemer of that werkjaar. The koepel's own organization is
178
+ -- dropped here rather than by reading `facts`, since that would drop those registrations with it.
179
+ -- @include facts
180
+ , inschrijvingen AS (
181
+ SELECT
182
+ f.organization_id,
183
+ f.member_id,
184
+ f.birth_date,
185
+ f.`Geslacht`,
186
+ f.deactivated_at,
187
+ -- @include type-deelnemers
188
+ AS type_number
189
+ FROM all_registrations f
190
+ WHERE
191
+ -- @include aangesloten
192
+ -- The takken of the group and nothing else. A wachtlijst and an activiteit carry no tak, so
193
+ -- they already deliver nobody through `type_number` below; said here as well because that is a
194
+ -- consequence of a group nobody categorised rather than a rule, and a koepel that categorises
195
+ -- one of its wachtlijsten would start delivering the people waiting on it as leden.
196
+ AND f.group_type = 'Membership'
197
+ AND NOT EXISTS (SELECT 1 FROM platform pf WHERE pf.membershipOrganizationId = f.organization_id)
198
+ ),
199
+ deelnemers AS (
200
+ SELECT
201
+ i.organization_id,
202
+ i.member_id,
203
+ MAX(i.birth_date) AS birth_date,
204
+ MAX(i.`Geslacht`) AS `Geslacht`,
205
+ COALESCE(
206
+ MAX(CASE WHEN i.deactivated_at IS NULL THEN i.type_number END),
207
+ MAX(i.type_number)
208
+ ) AS type_number
209
+ FROM inschrijvingen i
210
+ GROUP BY i.organization_id, i.member_id
211
+ )
212
+ SELECT
213
+ d.organization_id AS `ID_Organisatie`,
214
+ CASE WHEN d.type_number = 2 THEN 'leiding' ELSE 'leden' END AS `Type_deelnemers`,
215
+ YEAR(d.birth_date) AS `Geboortejaar_deelnemers`,
216
+ CASE d.`Geslacht` WHEN 'Man' THEN 'M' WHEN 'Vrouw' THEN 'V' ELSE NULL END AS `Gender_deelnemers`,
217
+ COUNT(DISTINCT d.member_id) AS `Aantal_deelnemers`
218
+ FROM deelnemers d
219
+ where d.type_number > 0
220
+ GROUP BY `ID_Organisatie`, `Type_deelnemers`, `Geboortejaar_deelnemers`, `Gender_deelnemers`
221
+ ORDER BY `ID_Organisatie`, `Type_deelnemers`, `Geboortejaar_deelnemers`, `Gender_deelnemers`
@@ -0,0 +1,229 @@
1
+ -- @tab nationaal
2
+ -- title: Nationaal
3
+ -- description: Ledenaantallen over het hele platform voor het gekozen scoutsjaar.
4
+ -- filters: scoutsjaar, aansluiting, ingeschreven_voor
5
+
6
+ -- @card aantal-eenheden
7
+ -- title: Aantal eenheden
8
+ -- display: scalar
9
+ -- size: sixth
10
+ -- @include facts
11
+ -- @include leden
12
+ SELECT COUNT(DISTINCT organization_id) AS `Aantal eenheden` FROM leden
13
+
14
+ -- @card totaal-leden
15
+ -- title: Totaal leden
16
+ -- display: scalar
17
+ -- size: sixth
18
+ -- @include facts
19
+ -- @include leden
20
+ SELECT COUNT(DISTINCT member_id) AS `Totaal leden` FROM leden
21
+
22
+ -- @card aantal-kinderen
23
+ -- title: Aantal kinderen
24
+ -- display: scalar
25
+ -- size: sixth
26
+ -- @include facts
27
+ -- @include leden
28
+ SELECT COUNT(DISTINCT member_id) AS `Aantal kinderen` FROM leden WHERE effective_category = 'child'
29
+
30
+ -- @card aantal-leiding
31
+ -- title: Aantal leiding
32
+ -- display: scalar
33
+ -- size: sixth
34
+ -- @include facts
35
+ -- @include leden
36
+ SELECT COUNT(DISTINCT member_id) AS `Aantal leiding` FROM leden WHERE effective_category = 'leader'
37
+
38
+ -- @card aantal-volwassenen
39
+ -- title: Aantal volwassenen
40
+ -- display: scalar
41
+ -- size: sixth
42
+ -- @include facts
43
+ -- @include leden
44
+ SELECT COUNT(DISTINCT member_id) AS `Aantal volwassenen` FROM leden WHERE effective_category = 'adult'
45
+
46
+ -- @card leden-per-eenheid
47
+ -- title: Aantal leden per eenheid & GTP index per eenheid
48
+ -- display: combo
49
+ -- size: full
50
+ -- dimensions: Eenheid
51
+ -- metrics: Aantal leden, GTP index
52
+ -- xlabels: rotate-90
53
+ -- description: GTP staat voor Gezond Toekomst Perspectief. Idealiter scoort een eenheid 100 of meer.
54
+ -- Rechtop, niet schuin: Metabase laat een label vallen zodra het het vorige raakt, en schuin heeft
55
+ -- een naam per eenheid daar net te weinig plaats voor.
56
+ -- @include facts
57
+ -- @include leden
58
+ SELECT
59
+ `Eenheid`,
60
+ COUNT(DISTINCT member_id) AS `Aantal leden`,
61
+ -- @include gtp
62
+ AS `GTP index`
63
+ FROM leden
64
+ GROUP BY `Eenheid`
65
+ ORDER BY `Aantal leden` DESC
66
+
67
+ -- @card leden-per-tak-vergelijking
68
+ -- title: Vergelijking aantal leden per tak met vorig scoutsjaar
69
+ -- display: bar
70
+ -- size: half
71
+ -- dimensions: Tak
72
+ -- metrics: Aantal leden dit jaar, Aantal leden vorig jaar
73
+ -- xlabels: rotate-45
74
+ -- @include facts-alle-jaren
75
+ -- @include leden
76
+ -- Zie `includes/jaren.sql`: het scoutsjaar is de naam, niet het id. Hier tellen ook de jaren zonder
77
+ -- leden mee, want een vergelijking met een leeg jaar is nog steeds een geldige vergelijking.
78
+ , jaren AS (
79
+ SELECT name, MIN(startDate) AS startDate, LAG(name) OVER (ORDER BY MIN(startDate)) AS vorig
80
+ FROM registration_periods
81
+ GROUP BY name
82
+ )
83
+ -- The selected year, or the most recent one when the filter is empty, plus the year before it.
84
+ , gekozen AS (
85
+ SELECT name, vorig FROM jaren
86
+ WHERE 1 = 1 [[AND name = {{scoutsjaar}}]]
87
+ ORDER BY startDate DESC
88
+ LIMIT 1
89
+ )
90
+ SELECT
91
+ f.`Tak`,
92
+ COUNT(DISTINCT CASE WHEN f.`Scoutsjaar` = g.name THEN f.member_id END) AS `Aantal leden dit jaar`,
93
+ COUNT(DISTINCT CASE WHEN f.`Scoutsjaar` = g.vorig THEN f.member_id END) AS `Aantal leden vorig jaar`
94
+ FROM leden f
95
+ CROSS JOIN gekozen g
96
+ WHERE f.`Scoutsjaar` IN (g.name, g.vorig)
97
+ GROUP BY f.`Tak`
98
+ ORDER BY MIN(COALESCE(f.tak_min_age, 99)), f.`Tak`
99
+
100
+ -- @card leden-per-geslacht
101
+ -- title: Aantal leden per geslacht
102
+ -- display: pie
103
+ -- size: half
104
+ -- dimensions: Geslacht
105
+ -- metrics: Aantal leden
106
+ -- @include facts
107
+ -- @include leden
108
+ SELECT `Geslacht`, COUNT(DISTINCT member_id) AS `Aantal leden`
109
+ FROM leden
110
+ GROUP BY `Geslacht`
111
+ ORDER BY `Aantal leden` DESC
112
+
113
+ -- @card leden-per-postcode
114
+ -- title: Aantal leden per postcode
115
+ -- display: map
116
+ -- latitude: Breedtegraad
117
+ -- longitude: Lengtegraad
118
+ -- size: full
119
+ -- dimensions: Postcode
120
+ -- metrics: Aantal leden
121
+ -- description: Een punt per postcode. Een postcode zonder coordinaat in `postal_codes` telt wel mee, maar staat niet op de kaart.
122
+ -- @include facts
123
+ -- @include leden
124
+ -- @include postcode-coordinaten
125
+ SELECT
126
+ f.postcode AS `Postcode`,
127
+ c.latitude AS `Breedtegraad`,
128
+ c.longitude AS `Lengtegraad`,
129
+ COUNT(DISTINCT f.member_id) AS `Aantal leden`
130
+ FROM leden f
131
+ LEFT JOIN postcode_coordinaten c ON c.postalCode = f.postcode
132
+ GROUP BY f.postcode, c.latitude, c.longitude
133
+ ORDER BY `Aantal leden` DESC
134
+
135
+ -- @card leden-per-geboortejaar
136
+ -- title: Aantal leden per geboortejaar
137
+ -- display: bar
138
+ -- size: half
139
+ -- dimensions: Geboortejaar
140
+ -- metrics: Aantal kinderen, Aantal leiding, Aantal volwassenen
141
+ -- @include facts
142
+ -- @include leden
143
+ SELECT
144
+ YEAR(birth_date) AS `Geboortejaar`,
145
+ COUNT(DISTINCT CASE WHEN effective_category = 'child' THEN member_id END) AS `Aantal kinderen`,
146
+ COUNT(DISTINCT CASE WHEN effective_category = 'leader' THEN member_id END) AS `Aantal leiding`,
147
+ COUNT(DISTINCT CASE WHEN effective_category = 'adult' THEN member_id END) AS `Aantal volwassenen`
148
+ FROM leden
149
+ WHERE birth_date IS NOT NULL
150
+ GROUP BY YEAR(birth_date)
151
+ ORDER BY `Geboortejaar`
152
+
153
+ -- @card leden-per-type-lidgeld
154
+ -- title: Aantal leden per type lidgeld
155
+ -- display: pie
156
+ -- size: half
157
+ -- dimensions: Type lidgeld
158
+ -- metrics: Aantal leden
159
+ -- @include facts
160
+ -- @include leden
161
+ SELECT
162
+ -- @include tarief
163
+ AS `Type lidgeld`,
164
+ COUNT(DISTINCT mpm.memberId) AS `Aantal leden`
165
+ FROM member_platform_memberships mpm
166
+ -- Enkel nog om op de aansluiting te kunnen filteren: waar de taart op splitst is het tarief, en dat
167
+ -- staat op het lidgeld zelf.
168
+ JOIN platform_membership_types mt ON mt.id = mpm.membershipTypeId AND mt.periodId = mpm.periodId
169
+ WHERE mpm.deletedAt IS NULL
170
+ AND mpm.periodId IN (SELECT DISTINCT period_id FROM leden)
171
+ AND mpm.memberId IN (SELECT DISTINCT member_id FROM leden)
172
+ -- Geen lidmaatschap bij de koepel zelf: `facts` laat die organisatie weg, en wie naast een eenheid
173
+ -- ook in een nationale ploeg zit zou het tarief daarvan anders in deze grafiek zetten.
174
+ AND NOT EXISTS (SELECT 1 FROM platform pf WHERE pf.membershipOrganizationId = mpm.organizationId)
175
+ -- Alleen de gekozen aansluitingen: `facts` houdt de leden over die er een van hebben, en zonder
176
+ -- dit zou de taart daarnaast ook de andere aansluitingen van net die leden tonen.
177
+ [[AND mt.name IN ({{aansluiting}})]]
178
+ GROUP BY mpm.reducedPrice
179
+ ORDER BY `Aantal leden` DESC
180
+
181
+ -- @card leden-per-scoutsjaar
182
+ -- title: Aantal leden per scoutsjaar
183
+ -- display: line
184
+ -- size: full
185
+ -- dimensions: Scoutsjaar
186
+ -- metrics: Totaal leden, Aantal kinderen, Aantal leiding, Aantal volwassenen
187
+ -- @include facts-alle-jaren
188
+ -- @include leden
189
+ SELECT
190
+ `Scoutsjaar`,
191
+ COUNT(DISTINCT member_id) AS `Totaal leden`,
192
+ COUNT(DISTINCT CASE WHEN effective_category = 'child' THEN member_id END) AS `Aantal kinderen`,
193
+ COUNT(DISTINCT CASE WHEN effective_category = 'leader' THEN member_id END) AS `Aantal leiding`,
194
+ COUNT(DISTINCT CASE WHEN effective_category = 'adult' THEN member_id END) AS `Aantal volwassenen`
195
+ FROM leden
196
+ GROUP BY `Scoutsjaar`
197
+ ORDER BY MIN(period_start)
198
+
199
+ -- @card percentage-blijvers-per-eenheid
200
+ -- title: Overzicht percentage blijvers
201
+ -- display: bar
202
+ -- size: full
203
+ -- dimensions: Eenheid
204
+ -- metrics: Percentage blijvers
205
+ -- xlabels: rotate-90
206
+ -- description: Van de leden in het gekozen scoutsjaar, het percentage dat het scoutsjaar erna nog lid is, per eenheid waar ze in het gekozen jaar zaten. Links = laagste ledenbehoud. Het laatste scoutsjaar staat er niet bij: het jaar erna moet eerst bestaan.
207
+ -- Rechtop, om dezelfde reden als bij de grafiek met het aantal leden per eenheid.
208
+ -- @include facts-alle-jaren
209
+ -- @include leden
210
+ -- @include leden-per-jaar
211
+ -- @include jaren
212
+ , gekozen AS (
213
+ SELECT name, volgend FROM jaren
214
+ WHERE volgend IS NOT NULL [[AND name = {{scoutsjaar}}]]
215
+ ORDER BY startDate DESC
216
+ LIMIT 1
217
+ )
218
+ -- Een blijver is lid in het gekozen jaar en nog steeds lid het jaar erna, waar ook op het platform:
219
+ -- wie naar een andere eenheid verhuist telt mee, zoals de klant het ook rekent.
220
+ SELECT
221
+ huidig.`Eenheid`,
222
+ ROUND(100 * COUNT(DISTINCT gebleven.member_id) / COUNT(DISTINCT huidig.member_id), 1) AS `Percentage blijvers`
223
+ FROM gekozen g
224
+ JOIN leden huidig ON huidig.`Scoutsjaar` = g.name
225
+ LEFT JOIN leden_per_jaar gebleven
226
+ ON gebleven.`Scoutsjaar` = g.volgend
227
+ AND gebleven.member_id = huidig.member_id
228
+ GROUP BY huidig.`Eenheid`
229
+ ORDER BY `Percentage blijvers`
@@ -0,0 +1,70 @@
1
+ -- @tab netwerk
2
+ -- title: Netwerk
3
+ -- description: Leden en eenheden per netwerk voor het gekozen scoutsjaar.
4
+ -- filters: scoutsjaar, aansluiting, ingeschreven_voor
5
+ --
6
+ -- Het netwerk van een eenheid is een tag op de organisatie, bijgehouden per periode: een afgesloten
7
+ -- jaar houdt het netwerk waarmee het toen geregistreerd stond.
8
+
9
+ -- @card leden-per-netwerk
10
+ -- title: Aantal leden per netwerk
11
+ -- display: bar
12
+ -- size: half
13
+ -- height: 10
14
+ -- dimensions: Netwerk
15
+ -- metrics: Aantal kinderen, Aantal leiding, Aantal volwassenen
16
+ -- stacked: stacked
17
+ -- @include facts
18
+ -- @include leden
19
+ SELECT
20
+ t.name AS `Netwerk`,
21
+ COUNT(DISTINCT CASE WHEN f.effective_category = 'child' THEN f.member_id END) AS `Aantal kinderen`,
22
+ COUNT(DISTINCT CASE WHEN f.effective_category = 'leader' THEN f.member_id END) AS `Aantal leiding`,
23
+ COUNT(DISTINCT CASE WHEN f.effective_category = 'adult' THEN f.member_id END) AS `Aantal volwassenen`
24
+ FROM leden f
25
+ JOIN _organizations_organization_tags link
26
+ ON link.organizationsId = f.organization_id AND link.periodId = f.period_id
27
+ JOIN organization_tags t ON t.id = link.organizationTagsId AND t.periodId = link.periodId
28
+ GROUP BY t.name
29
+ ORDER BY t.name
30
+
31
+ -- @card locatie-eenheden
32
+ -- title: Locatie eenheden
33
+ -- display: map
34
+ -- latitude: Breedtegraad
35
+ -- longitude: Lengtegraad
36
+ -- size: half
37
+ -- span: 2
38
+ -- dimensions: Postcode
39
+ -- metrics: Aantal eenheden
40
+ -- description: Een punt per postcode waar eenheden zitten. Het originele rapport zet een stip per eenheid; zonder coordinaat per eenheid is de postcode het dichtstbij.
41
+ -- @include facts
42
+ -- @include leden
43
+ -- @include postcode-coordinaten
44
+ SELECT
45
+ f.eenheid_postcode AS `Postcode`,
46
+ c.latitude AS `Breedtegraad`,
47
+ c.longitude AS `Lengtegraad`,
48
+ COUNT(DISTINCT f.organization_id) AS `Aantal eenheden`
49
+ FROM leden f
50
+ LEFT JOIN postcode_coordinaten c ON c.postalCode = f.eenheid_postcode
51
+ GROUP BY f.eenheid_postcode, c.latitude, c.longitude
52
+ ORDER BY `Aantal eenheden` DESC
53
+
54
+ -- @card eenheden-per-netwerk
55
+ -- title: Aantal eenheden per netwerk
56
+ -- display: pie
57
+ -- size: half
58
+ -- dimensions: Netwerk
59
+ -- metrics: Aantal eenheden
60
+ -- @include facts
61
+ -- @include leden
62
+ SELECT
63
+ t.name AS `Netwerk`,
64
+ COUNT(DISTINCT f.organization_id) AS `Aantal eenheden`
65
+ FROM leden f
66
+ JOIN _organizations_organization_tags link
67
+ ON link.organizationsId = f.organization_id AND link.periodId = f.period_id
68
+ JOIN organization_tags t ON t.id = link.organizationTagsId AND t.periodId = link.periodId
69
+ GROUP BY t.name
70
+ ORDER BY t.name
@@ -0,0 +1,35 @@
1
+ -- @tab varia
2
+ -- title: Varia
3
+ -- description: Kinderen en leiding per eenheid, uitgesplitst naar geslacht.
4
+ -- filters: scoutsjaar, aansluiting, ingeschreven_voor
5
+
6
+ -- @card uldk
7
+ -- title: ULDK
8
+ -- display: table
9
+ -- size: full
10
+ -- @include facts
11
+ -- @include leden
12
+ -- @include uldk
13
+ SELECT * FROM uldk ORDER BY `Name`
14
+
15
+ -- @card uldk-totaal
16
+ -- title: ULDK (totaal)
17
+ -- display: table
18
+ -- size: full
19
+ -- height: 4
20
+ -- description: De som van de kolommen in de tabel hierboven. Staat in een eigen kaart omdat een tabel in Metabase enkel rijen bovenaan kan vastzetten: als laatste rij van de tabel zou het totaal pas na het doorscrollen van alle eenheden te zien zijn.
21
+ -- @include facts
22
+ -- @include leden
23
+ -- @include uldk
24
+ SELECT
25
+ 'Totaal' AS `Name`,
26
+ '' AS `City`,
27
+ COALESCE(SUM(`Aantal kinderen/Man`), 0) AS `Aantal kinderen/Man`,
28
+ COALESCE(SUM(`Aantal kinderen/Vrouw`), 0) AS `Aantal kinderen/Vrouw`,
29
+ COALESCE(SUM(`Aantal kinderen/Andere`), 0) AS `Aantal kinderen/Andere`,
30
+ COALESCE(SUM(`Aantal kinderen/Onbekend`), 0) AS `Aantal kinderen/Onbekend`,
31
+ COALESCE(SUM(`Aantal leiding/Man`), 0) AS `Aantal leiding/Man`,
32
+ COALESCE(SUM(`Aantal leiding/Vrouw`), 0) AS `Aantal leiding/Vrouw`,
33
+ COALESCE(SUM(`Aantal leiding/Andere`), 0) AS `Aantal leiding/Andere`,
34
+ COALESCE(SUM(`Aantal leiding/Onbekend`), 0) AS `Aantal leiding/Onbekend`
35
+ FROM uldk