Skip to content

Commit

Permalink
update agency presence data/processing
Browse files Browse the repository at this point in the history
  • Loading branch information
graphographer committed Apr 4, 2024
1 parent 122a3ef commit ecc388e
Show file tree
Hide file tree
Showing 7 changed files with 1,266 additions and 1,258 deletions.
14 changes: 10 additions & 4 deletions src/components/tabs/BeMapAgencyPresence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ export class BeMapAgencyPresence extends StateProvider {
'Primary',
'Secondary',
'Workforce Development',
'Education Systems Strengthening'
'Education Systems Strengthening',
'Education Level Not Specified'
];

render() {
if (this.state.agencyEducationSupportForSelectedCountry) {
console.log('WHY HERE?', this.state.selectedCountry);
return html`
<table>
<caption>
Expand All @@ -74,7 +76,7 @@ export class BeMapAgencyPresence extends StateProvider {
${BeMapAgencyPresence.agencies.map(([_short, long]) => {
return html`
<td>
${this.state.agencyEducationSupportForSelectedCountry[
${this.state.agencyEducationSupportForSelectedCountry![
long
]?.includes(level)
? html`<div class="checked">
Expand All @@ -91,11 +93,15 @@ export class BeMapAgencyPresence extends StateProvider {
<p>
<b>Supporting Agencies:</b>
${this.state.agenciesInSelectedCountry.join(', ')}
${this.state.agenciesInSelectedCountry!.join(', ')}
</p>
`;
} else {
return html`<em>No data available.</em>`;
return html`<h4>
USG BE Support by Education Level(s) and Agency for Fiscal Year
${this.state.latestFY}
</h4>
<em>No data available.</em>`;
}
}
}
4 changes: 3 additions & 1 deletion src/components/tabs/BeMapOutputIndicators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ export class BeMapOutputIndicators extends StateProvider {

render() {
if (!this.state.selectedCountryHasOutputIndicators) {
return html`<em>No data available.</em>`;
return html`<h4>Results for Fiscal Year ${this.state.latestFY}</h4>
<em>No data available.</em>`;
}

return html`
<h4>Results for Fiscal Year ${this.state.latestFY}</h4>
<p><em>Disaggregated data is provided where/when available.</em></p>
${this.learnersReached} ${this.learnerInputs} ${this.learnerOutcomes}
`;
Expand Down
2,404 changes: 1,202 additions & 1,202 deletions src/data/agency_presence.csv

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions src/data/helpers/agencyPresenceProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import dsv from '@rollup/plugin-dsv';
import { nameToThreeAlphas } from '../countryNameTo3Alpha';

export const agencyPresenceProcessor = dsv({
include: 'src/data/agency_presence.csv',
processRow(row: any) {
for (const key in row) {
const val = row[key];
if (val === 'TRUE') {
row[key] = true;
continue;

if (key === 'Country') {
row.Country = nameToThreeAlphas.get(val) || row.Country;
}
if (val === 'FALSE') {
row[key] = false;

if (val === 'TRUE' || val === 'FALSE') {
row[key] = val === 'TRUE';
continue;
}

Expand Down
71 changes: 33 additions & 38 deletions src/state/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ import {
sortBy
} from 'lodash-es';
import { makeAutoObservable, observable, reaction } from 'mobx';
import {
nameToThreeAlphas,
threeAlphasToName
} from '../data/countryNameTo3Alpha';
import { threeAlphasToName } from '../data/countryNameTo3Alpha';
import { countryNameFormatter } from '../data/helpers/countryNameFormatter';
import { TEducationLevel } from '../types/EEducationLevel';
import { EDUCATION_LEVELS, TEducationLevel } from '../types/EEducationLevel';
import { TAgency } from '../types/TAgency';
import { TAgencyActivity } from '../types/TAgencyActivity';
import { TAgencyPresence } from '../types/TAgencyPresence';
Expand Down Expand Up @@ -139,36 +136,34 @@ export class State {
return interventions;
}

get agencyEducationSupportByCountry(): Record<
string,
Record<TAgency, TEducationLevel[]>
> {
get agencyEducationSupportByCountry():
| Record<string, Record<TAgency, TEducationLevel[]>>
| undefined {
if (!this.agenciesInSelectedCountry.length) return;

return mapValues(
groupBy(this.data.agency_activity, 'Country'),
activities => {
const activitiesByAgency: Record<TAgency, TEducationLevel[]> =
mapValues(
groupBy(activities, 'Agency') as Record<TAgency, TAgencyActivity[]>,
agencyActivities => {
return [
...agencyActivities.reduce<Set<TEducationLevel>>(
(acc, activity) => {
activity.educationLevels.forEach(level => acc.add(level));
return acc;
},
new Set()
)
];
}
);

return activitiesByAgency;
groupBy(this.data.agency_presence, 'Country'),
presences => {
const levelPresenceByAgency = Object.fromEntries(
presences.map(presence => {
const levels = pickBy(
presence,
(supported, key) =>
supported && EDUCATION_LEVELS.includes(key as TEducationLevel)
);
return [presence.Agency, Object.keys(levels)];
})
) as Record<TAgency, TEducationLevel[]>;

return levelPresenceByAgency;
}
);
}

get agencyEducationSupportForSelectedCountry() {
return this.agencyEducationSupportByCountry[this.selectedCountry];
get agencyEducationSupportForSelectedCountry():
| Record<TAgency, TEducationLevel[]>
| undefined {
return this.agencyEducationSupportByCountry?.[this.selectedCountry];
}

get latestFY() {
Expand Down Expand Up @@ -235,15 +230,15 @@ export class State {
return this.data.agency_presence.reduce((acc, presence) => {
const { Country, Agency, 'Agency Support': support } = presence;

if (!support) return acc;

const country3Alpha = nameToThreeAlphas.get(Country) || Country;
if (!acc[Country]) {
acc[Country] = [];
}

if (!acc[country3Alpha]) {
acc[country3Alpha] = [];
if (!support) {
return acc;
}

acc[country3Alpha].push(Agency);
acc[Country].push(Agency);

return acc;
}, {} as { [k: string]: TAgency[] });
Expand All @@ -268,7 +263,7 @@ export class State {
});
}

get agenciesInSelectedCountry() {
get agenciesInSelectedCountry(): TAgency[] {
return this.agenciesInCountry[this.selectedCountry];
}

Expand Down Expand Up @@ -348,7 +343,7 @@ export class State {
);
}

selectedCountry: string = '';
selectedCountry: string = 'KHM';

get selectedCountryFormatted() {
return countryNameFormatter(this.selectedCountry);
Expand Down
6 changes: 4 additions & 2 deletions src/types/EEducationLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ export type TEducationLevel =
| 'Primary'
| 'Secondary'
| 'Workforce Development'
| 'Education Systems Strengthening';
| 'Education Systems Strengthening'
| 'Education Level Not Specified';

export const EDUCATION_LEVELS: TEducationLevel[] = [
'Pre-Primary',
'Primary',
'Secondary',
'Workforce Development',
'Education Systems Strengthening'
'Education Systems Strengthening',
'Education Level Not Specified'
];
13 changes: 7 additions & 6 deletions src/types/TAgencyPresence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ export type TAgencyPresence = {
Country: ECountry;
'Agency Support': number;
'Number of Supporting Agencies': number;
'Coordination Possible': number;
'Pre-Primary Education Support': number;
'Primary Education Support': number;
'Secondary Education Support': number;
'WFD Support': number;
'Systems Strengthening Support': number;
// 'Coordination Possible': number;
'Pre-Primary': number;
Primary: number;
Secondary: number;
'Workforce Development': number;
'Education Systems Strengthening': number;
'Education Level Not Specified': boolean;
};

0 comments on commit ecc388e

Please sign in to comment.