From 4b3ef11d4c7c0998811ae56ea7f1beca6ca87800 Mon Sep 17 00:00:00 2001 From: Eric Boucher Date: Mon, 24 Apr 2023 16:45:30 +0200 Subject: [PATCH 1/4] feat(dedup): dedup typing example --- .../flood/generateFloodDetailedReport.ts | 19 +- packages/interfaces/src/kobo/mapping/flood.ts | 389 ++++++------------ 2 files changed, 140 insertions(+), 268 deletions(-) diff --git a/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts b/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts index ac9b36c7..ef09af66 100644 --- a/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts +++ b/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts @@ -1,4 +1,4 @@ -import { FloodSpecific, KoboCommonKeys } from '@wfp-dmp/interfaces'; +import { floodSpecificKeysArray, FloodSpecificType, KoboCommonKeys } from '@wfp-dmp/interfaces'; import { omit } from 'lodash'; import { aggregate } from '../aggregate'; @@ -7,16 +7,17 @@ import { filterNFlood } from '../filterNFlood'; const firstKeys = [KoboCommonKeys.province, KoboCommonKeys.district]; const sumKeys = Object.values( - omit(FloodSpecific, [ - FloodSpecific.floodN, - FloodSpecific.RicePrice, - FloodSpecific.threat, - FloodSpecific.other, + omit(floodSpecificKeysArray, [ + 'floodN', + 'RicePrice', + 'threat', + 'other', ]), ); -const countCategoriesKeys = [FloodSpecific.RicePrice]; -const countMultipleChoicesKeys = [FloodSpecific.threat]; + +const countCategoriesKeys: FloodSpecificType[] = ['RicePrice']; +const countMultipleChoicesKeys: FloodSpecificType[] = ['threat']; export const generateFloodDetailedReport = ( data: Record[], @@ -25,7 +26,7 @@ export const generateFloodDetailedReport = ( data, KoboCommonKeys.commune, KoboCommonKeys.disasterDate, - FloodSpecific.floodN, + 'floodN', ); return aggregate({ diff --git a/packages/interfaces/src/kobo/mapping/flood.ts b/packages/interfaces/src/kobo/mapping/flood.ts index cbd82f2f..5c0abcb4 100644 --- a/packages/interfaces/src/kobo/mapping/flood.ts +++ b/packages/interfaces/src/kobo/mapping/flood.ts @@ -1,265 +1,136 @@ /* eslint-disable max-lines */ -export enum FloodSpecific { - floodN = 'floodN', - NumVillAff = 'NumVillAff', - NumFamAff = 'NumFamAff', - NumPeoAff = 'NumPeoAff', - NumFeAff = 'NumFeAff', - NumTDeath = 'NumTDeath', - NumMeDeath = 'NumMeDeath', - NumFeDeath = 'NumFeDeath', - NumKidDeath = 'NumKidDeath', - NumOldDeath = 'NumOldDeath', - NumDisDeath = 'NumDisDeath', - NumTMissing = 'NumTMissing', - NumMeMissing = 'NumMeMissing', - NumFeMissing = 'NumFeMissing', - NumKidMissing = 'NumKidMissing', - NumOldMissing = 'NumOldMissing', - NumDisMissing = 'NumDisMissing', - NumTInjure = 'NumTInjure', - NumMeInjure = 'NumMeInjure', - NumFeInjure = 'NumFeInjure', - NumKidInjure = 'NumKidInjure', - NumOldInjure = 'NumOldInjure', - NumDisInjure = 'NumDisInjure', - NumFamEva = 'NumFamEva', - NumPeoEva = 'NumPeoEva', - NumMeEva = 'NumMeEva', - NumFeEva = 'NumFeEva', - NumKidEva = 'NumKidEva', - NumOldEva = 'NumOldEva', - NumDisEva = 'NumDisEva', - NumFamRe = 'NumFamRe', - NumPeoRe = 'NumPeoRe', - NumMeRe = 'NumMeRe', - NumFeRe = 'NumFeRe', - NumKidRe = 'NumKidRe', - NumOldRe = 'NumOldRe', - NumDisRe = 'NumDisRe', - NumSafePla = 'NumSafePla', - NumPeoSEC = 'NumPeoSEC', - NumHouAff = 'NumHouAff', - NumHouDam = 'NumHouDam', - NumSchoAff = 'NumSchoAff', - NumSchoDam = 'NumSchoDam', - NumAffHeal = 'NumAffHeal', - NumDamHeal = 'NumDamHeal', - NumPagoAff = 'NumPagoAff', - NumPagoDam = 'NumPagoDam', - NumBuilAff = 'NumBuilAff', - NumBuilDam = 'NumBuilDam', - NumShopAff = 'NumShopAff', - NumShopDam = 'NumShopDam', - NumWareHAff = 'NumWareHAff', - NumWareHDam = 'NumWareHDam', - NumCraftAff = 'NumCraftAff', - NumCraftDam = 'NumCraftDam', - FarmAff = 'FarmAff', - FarmDam = 'FarmDam', - SamNabAff = 'SamNabAff', - SamNabDam = 'SamNabDam', - PaddyAff = 'PaddyAff', - PaddyDam = 'PaddyDam', - CowEva = 'CowEva', - CowDeath = 'CowDeath', - CowMissing = 'CowMissing', - PigEva = 'PigEva', - PigDeath = 'PigDeath', - PigMissing = 'PigMissing', - BirdEva = 'BirdEva', - BirdDeath = 'BirdDeath', - BirdMissing = 'BirdMissing', - RubberRoAff = 'RubberRoAff', - RubberRoDam = 'RubberRoDam', - ConcretAff = 'ConcretAff', - ConcretDam = 'ConcretDam', - RuralRoAff = 'RuralRoAff', - RuralRoDam = 'RuralRoDam', - BridgeAff = 'BridgeAff', - BridgeDam = 'BridgeDam', - BeleBridAff = 'BeleBridAff', - BeleBridDam = 'BeleBridDam', - DrainageAff = 'DrainageAff', - DrainageDam = 'DrainageDam', - DamAff = 'DamAff', - DamDamaged = 'DamDamaged', - WatGateAff = 'WatGateAff', - WatGateDam = 'WatGateDam', - PlumWelAff = 'PlumWelAff', - PlumWelDam = 'PlumWelDam', - DigWellAff = 'DigWellAff', - DigWellDam = 'DigWellDam', - PondAff = 'PondAff', - PondDam = 'PondDam', - LatrineAff = 'LatrineAff', - LatrineDam = 'LatrineDam', - RiverBreak = 'RiverBreak', - RiverBreakLo = 'RiverBreakLo', - BrolayAff = 'BrolayAff', - BrolayDam = 'BrolayDam', - NumFamTent = 'NumFamTent', - NumPeoTent = 'NumPeoTent', - NumFamBuil = 'NumFamBuil', - NumPeoBuil = 'NumPeoBuil', - NumFamRela = 'NumFamRela', - NumPeoRela = 'NumPeoRela', - NumTemSch = 'NumTemSch', - StuAcTemSch = 'StuAcTemSch', - SchUseSafe = 'SchUseSafe', - NumStu = 'NumStu', - NumSchStop = 'NumSchStop', - NumStuNoCla = 'NumStuNoCla', - NumFamNoWa = 'NumFamNoWa', - NumPeoNoWa = 'NumPeoNoWa', - TimeAceWa = 'TimeAceWa', - NuFamNoWaEq = 'NuFamNoWaEq', - NuFamNoLat = 'NuFamNoLat', - NonActingH = 'NonActingH', - PeoCanAceH = 'PeoCanAceH', - NumDoctor = 'NumDoctor', - NumNurse = 'NumNurse', - NumStaff = 'NumStaff', - NumFamNoFod = 'NumFamNoFod', - NumPeoNoFod = 'NumPeoNoFod', - FamNoFod7d = 'FamNoFod7d', - NumActShop = 'NumActShop', - NumNoActShop = 'NumNoActShop', - RicePrice = 'RicePrice', - threat = 'threat', - other = 'other', -} - export const floodSpecificKeys = { - [FloodSpecific.floodN]: 'g2/flood_n', - [FloodSpecific.NumVillAff]: 'g3/g3_1/NumVillAff', - [FloodSpecific.NumFamAff]: 'g3/g3_1/g3_2/NumFamAff', - [FloodSpecific.NumPeoAff]: 'g3/g3_1/g3_2/NumPeoAff', - [FloodSpecific.NumFeAff]: 'g3/g3_1/g3_2/NumFeAff', - [FloodSpecific.NumTDeath]: 'g3/g4/TNumDeath', - [FloodSpecific.NumMeDeath]: 'g3/g4/NumMeDeath', - [FloodSpecific.NumFeDeath]: 'g3/g4/NumFeDeath', - [FloodSpecific.NumKidDeath]: 'g3/g4/NumKidDeath', - [FloodSpecific.NumOldDeath]: 'g3/g4/NumOldDeath', - [FloodSpecific.NumDisDeath]: 'g3/g4/NumDisDeath', - [FloodSpecific.NumTMissing]: 'g3/g5/NumTMising', - [FloodSpecific.NumMeMissing]: 'g3/g5/NumMeMising', - [FloodSpecific.NumFeMissing]: 'g3/g5/NumFeMising', - [FloodSpecific.NumKidMissing]: 'g3/g5/NumKidMising', - [FloodSpecific.NumOldMissing]: 'g3/g5/NumOldMising', - [FloodSpecific.NumDisMissing]: 'g3/g5/NumDisMising', - [FloodSpecific.NumTInjure]: 'g3/g6/NumTInjure', - [FloodSpecific.NumMeInjure]: 'g3/g6/NumMeInjure', - [FloodSpecific.NumFeInjure]: 'g3/g6/NumFeInjure', - [FloodSpecific.NumKidInjure]: 'g3/g6/NumKidInjure', - [FloodSpecific.NumOldInjure]: 'g3/g6/NumOldInjure', - [FloodSpecific.NumDisInjure]: 'g3/g6/NumDisInjure', - [FloodSpecific.NumFamEva]: 'g3/g7/NumFamEva', - [FloodSpecific.NumPeoEva]: 'g3/g7/NumPeoEva', - [FloodSpecific.NumMeEva]: 'g3/g7/NumMeEva', - [FloodSpecific.NumFeEva]: 'g3/g7/NumFeEva', - [FloodSpecific.NumKidEva]: 'g3/g7/NumKidEva', - [FloodSpecific.NumOldEva]: 'g3/g7/NumOldEva', - [FloodSpecific.NumDisEva]: 'g3/g7/NumDisEva', - [FloodSpecific.NumFamRe]: 'g3/g8/NumFamRe', - [FloodSpecific.NumPeoRe]: 'g3/g8/NumPeoRe', - [FloodSpecific.NumMeRe]: 'g3/g8/NumMeRe', - [FloodSpecific.NumFeRe]: 'g3/g8/NumFeRe', - [FloodSpecific.NumKidRe]: 'g3/g8/NumKidRe', - [FloodSpecific.NumOldRe]: 'g3/g8/NumOldRe', - [FloodSpecific.NumDisRe]: 'g3/g8/NumDisRe', - [FloodSpecific.NumSafePla]: 'g3/g9/NumSafePla', - [FloodSpecific.NumPeoSEC]: 'g3/g9/NumPeoSEC', - [FloodSpecific.NumHouAff]: 'g10/g10_1/NumHouAff', - [FloodSpecific.NumHouDam]: 'g10/g10_1/NumHouDam', - [FloodSpecific.NumSchoAff]: 'g10/g10_2/NumSchoAff', - [FloodSpecific.NumSchoDam]: 'g10/g10_2/NumSchoDam', - [FloodSpecific.NumAffHeal]: 'g10/g10_3/NumAffHeal', - [FloodSpecific.NumDamHeal]: 'g10/g10_3/NumDamHeal', - [FloodSpecific.NumPagoAff]: 'g10/g10_4/NumPagoAff', - [FloodSpecific.NumPagoDam]: 'g10/g10_4/NumPagoDam', - [FloodSpecific.NumBuilAff]: 'g10/g10_5/NumBuilAff', - [FloodSpecific.NumBuilDam]: 'g10/g10_5/NumBuilDam', - [FloodSpecific.NumShopAff]: 'g10/g10_6/NumShopAff', - [FloodSpecific.NumShopDam]: 'g10/g10_6/NumShopDam', - [FloodSpecific.NumWareHAff]: 'g10/g10_7/NumWareHAff', - [FloodSpecific.NumWareHDam]: 'g10/g10_7/NumWareHDam', - [FloodSpecific.NumCraftAff]: 'g10/g10_8/NumCraftAff', - [FloodSpecific.NumCraftDam]: 'g10/g10_8/NumCraftDam', - [FloodSpecific.FarmAff]: 'g11/g11_1/FarmAff', - [FloodSpecific.FarmDam]: 'g11/g11_1/FarmDam', - [FloodSpecific.SamNabAff]: 'g11/g11_2/SamNabAff', - [FloodSpecific.SamNabDam]: 'g11/g11_2/SamNabDam', - [FloodSpecific.PaddyAff]: 'g11/g11_3/PaddyAff', - [FloodSpecific.PaddyDam]: 'g11/g11_3/PaddyDam', - [FloodSpecific.CowEva]: 'g11/g11_4/CowEva', - [FloodSpecific.CowDeath]: 'g11/g11_4/CowDeath', - [FloodSpecific.CowMissing]: 'g11/g11_4/CowMissing', - [FloodSpecific.PigEva]: 'g11/g11_5/PigEva', - [FloodSpecific.PigDeath]: 'g11/g11_5/PigDeath', - [FloodSpecific.PigMissing]: 'g11/g11_5/PigMissing', - [FloodSpecific.BirdEva]: 'g11/g11_6/BirdEva', - [FloodSpecific.BirdDeath]: 'g11/g11_6/BirdDeath', - [FloodSpecific.BirdMissing]: 'g11/g11_6/BirdMissing', - [FloodSpecific.RubberRoAff]: 'g12/g12_1/RubberRoAff', - [FloodSpecific.RubberRoDam]: 'g12/g12_1/RubberRoDam', - [FloodSpecific.ConcretAff]: 'g12/g12_2/ConcretAff', - [FloodSpecific.ConcretDam]: 'g12/g12_2/ConcretDam', - [FloodSpecific.RuralRoAff]: 'g12/g12_3/RuralRoAff', - [FloodSpecific.RuralRoDam]: 'g12/g12_3/RuralRoDam', - [FloodSpecific.BridgeAff]: 'g12/g12_4/BridgeAff', - [FloodSpecific.BridgeDam]: 'g12/g12_4/BridgeDam', - [FloodSpecific.BeleBridAff]: 'g12/g12_5/BeleBridAff', - [FloodSpecific.BeleBridDam]: 'g12/g12_5/BeleBridDam', - [FloodSpecific.DrainageAff]: 'g12/g12_6/DrainageAff', - [FloodSpecific.DrainageDam]: 'g12/g12_6/DrainageDam', - [FloodSpecific.DamAff]: 'g13/g13_1/DamAff', - [FloodSpecific.DamDamaged]: 'g13/g13_1/DamDamaged', - [FloodSpecific.WatGateAff]: 'g13/g13_2/WatGateAff', - [FloodSpecific.WatGateDam]: 'g13/g13_2/WatGateDam', - [FloodSpecific.PlumWelAff]: 'g13/g13_3/PlumWelAff', - [FloodSpecific.PlumWelDam]: 'g13/g13_3/PlumWelDam', - [FloodSpecific.DigWellAff]: 'g13/g13_4/DigWellAff', - [FloodSpecific.DigWellDam]: 'g13/g13_4/DigWellDam', - [FloodSpecific.PondAff]: 'g13/g13_5/PondAff', - [FloodSpecific.PondDam]: 'g13/g13_5/PondDam', - [FloodSpecific.LatrineAff]: 'g13/g13_6/LatrineAff', - [FloodSpecific.LatrineDam]: 'g13/g13_6/LatrineDam', - [FloodSpecific.RiverBreak]: 'g13/g13_7/RiverBreak', - [FloodSpecific.RiverBreakLo]: 'g13/g13_7/RiverBreakLo', - [FloodSpecific.BrolayAff]: 'g13/BrolayAff', - [FloodSpecific.BrolayDam]: 'g13/BrolayDam', - [FloodSpecific.NumFamTent]: 'g14/g14_1/NumFamTent', - [FloodSpecific.NumPeoTent]: 'g14/g14_1/NumPeoTent', - [FloodSpecific.NumFamBuil]: 'g14/g14_2/NumFamBuil', - [FloodSpecific.NumPeoBuil]: 'g14/g14_2/NumPeoBuil', - [FloodSpecific.NumFamRela]: 'g14/g14_3/NumFamRela', - [FloodSpecific.NumPeoRela]: 'g14/g14_3/NumPeoRela', - [FloodSpecific.NumTemSch]: 'g15/g15_1/NumTemSch', - [FloodSpecific.StuAcTemSch]: 'g15/g15_1/StuAcTemSch', - [FloodSpecific.SchUseSafe]: 'g15/g15_2/SchUseSafe', - [FloodSpecific.NumStu]: 'g15/g15_2/NumStu', - [FloodSpecific.NumSchStop]: 'g15/g15_3/NumSchStop', - [FloodSpecific.NumStuNoCla]: 'g15/g15_3/NumStuNoCla', - [FloodSpecific.NumFamNoWa]: 'g16_1/g16_1_001/NumFamNoWa', - [FloodSpecific.NumPeoNoWa]: 'g16_1/g16_1_001/NumPeoNoWa', - [FloodSpecific.TimeAceWa]: 'g16_1/g16_1_001/TimeAceWa', - [FloodSpecific.NuFamNoWaEq]: 'g16_1/g16_1_001/NuFamNoWaEq', - [FloodSpecific.NuFamNoLat]: 'g16_1/g16_1_001/NuFamNoLat', - [FloodSpecific.NonActingH]: 'g17/g17_1/NonActingH', - [FloodSpecific.PeoCanAceH]: 'g17/g17_1/PeoCanAceH', - [FloodSpecific.NumDoctor]: 'g17/g17_1/NumDoctor', - [FloodSpecific.NumNurse]: 'g17/g17_1/NumNurse', - [FloodSpecific.NumStaff]: 'g17/g17_1/NumStaff', - [FloodSpecific.NumFamNoFod]: 'g18/g18_1/NumFamNoFod', - [FloodSpecific.NumPeoNoFod]: 'g18/g18_1/NumPeoNoFod', - [FloodSpecific.FamNoFod7d]: 'g18/FamNoFod7d', - [FloodSpecific.NumActShop]: 'g18/g18_2/NumActShop', - [FloodSpecific.NumNoActShop]: 'g18/g18_2/NumNoActShop', - [FloodSpecific.RicePrice]: 'g18/RicePrice', - [FloodSpecific.threat]: 'g19/threat', - [FloodSpecific.other]: 'g19/other', + 'floodN': 'g2/flood_n', + 'NumVillAff': 'g3/g3_1/NumVillAff', + 'NumFamAff': 'g3/g3_1/g3_2/NumFamAff', + 'NumPeoAff': 'g3/g3_1/g3_2/NumPeoAff', + 'NumFeAff': 'g3/g3_1/g3_2/NumFeAff', + 'NumTDeath': 'g3/g4/TNumDeath', + 'NumMeDeath': 'g3/g4/NumMeDeath', + 'NumFeDeath': 'g3/g4/NumFeDeath', + 'NumKidDeath': 'g3/g4/NumKidDeath', + 'NumOldDeath': 'g3/g4/NumOldDeath', + 'NumDisDeath': 'g3/g4/NumDisDeath', + 'NumTMissing': 'g3/g5/NumTMising', + 'NumMeMissing': 'g3/g5/NumMeMising', + 'NumFeMissing': 'g3/g5/NumFeMising', + 'NumKidMissing': 'g3/g5/NumKidMising', + 'NumOldMissing': 'g3/g5/NumOldMising', + 'NumDisMissing': 'g3/g5/NumDisMising', + 'NumTInjure': 'g3/g6/NumTInjure', + 'NumMeInjure': 'g3/g6/NumMeInjure', + 'NumFeInjure': 'g3/g6/NumFeInjure', + 'NumKidInjure': 'g3/g6/NumKidInjure', + 'NumOldInjure': 'g3/g6/NumOldInjure', + 'NumDisInjure': 'g3/g6/NumDisInjure', + 'NumFamEva': 'g3/g7/NumFamEva', + 'NumPeoEva': 'g3/g7/NumPeoEva', + 'NumMeEva': 'g3/g7/NumMeEva', + 'NumFeEva': 'g3/g7/NumFeEva', + 'NumKidEva': 'g3/g7/NumKidEva', + 'NumOldEva': 'g3/g7/NumOldEva', + 'NumDisEva': 'g3/g7/NumDisEva', + 'NumFamRe': 'g3/g8/NumFamRe', + 'NumPeoRe': 'g3/g8/NumPeoRe', + 'NumMeRe': 'g3/g8/NumMeRe', + 'NumFeRe': 'g3/g8/NumFeRe', + 'NumKidRe': 'g3/g8/NumKidRe', + 'NumOldRe': 'g3/g8/NumOldRe', + 'NumDisRe': 'g3/g8/NumDisRe', + 'NumSafePla': 'g3/g9/NumSafePla', + 'NumPeoSEC': 'g3/g9/NumPeoSEC', + 'NumHouAff': 'g10/g10_1/NumHouAff', + 'NumHouDam': 'g10/g10_1/NumHouDam', + 'NumSchoAff': 'g10/g10_2/NumSchoAff', + 'NumSchoDam': 'g10/g10_2/NumSchoDam', + 'NumAffHeal': 'g10/g10_3/NumAffHeal', + 'NumDamHeal': 'g10/g10_3/NumDamHeal', + 'NumPagoAff': 'g10/g10_4/NumPagoAff', + 'NumPagoDam': 'g10/g10_4/NumPagoDam', + 'NumBuilAff': 'g10/g10_5/NumBuilAff', + 'NumBuilDam': 'g10/g10_5/NumBuilDam', + 'NumShopAff': 'g10/g10_6/NumShopAff', + 'NumShopDam': 'g10/g10_6/NumShopDam', + 'NumWareHAff': 'g10/g10_7/NumWareHAff', + 'NumWareHDam': 'g10/g10_7/NumWareHDam', + 'NumCraftAff': 'g10/g10_8/NumCraftAff', + 'NumCraftDam': 'g10/g10_8/NumCraftDam', + 'FarmAff': 'g11/g11_1/FarmAff', + 'FarmDam': 'g11/g11_1/FarmDam', + 'SamNabAff': 'g11/g11_2/SamNabAff', + 'SamNabDam': 'g11/g11_2/SamNabDam', + 'PaddyAff': 'g11/g11_3/PaddyAff', + 'PaddyDam': 'g11/g11_3/PaddyDam', + 'CowEva': 'g11/g11_4/CowEva', + 'CowDeath': 'g11/g11_4/CowDeath', + 'CowMissing': 'g11/g11_4/CowMissing', + 'PigEva': 'g11/g11_5/PigEva', + 'PigDeath': 'g11/g11_5/PigDeath', + 'PigMissing': 'g11/g11_5/PigMissing', + 'BirdEva': 'g11/g11_6/BirdEva', + 'BirdDeath': 'g11/g11_6/BirdDeath', + 'BirdMissing': 'g11/g11_6/BirdMissing', + 'RubberRoAff': 'g12/g12_1/RubberRoAff', + 'RubberRoDam': 'g12/g12_1/RubberRoDam', + 'ConcretAff': 'g12/g12_2/ConcretAff', + 'ConcretDam': 'g12/g12_2/ConcretDam', + 'RuralRoAff': 'g12/g12_3/RuralRoAff', + 'RuralRoDam': 'g12/g12_3/RuralRoDam', + 'BridgeAff': 'g12/g12_4/BridgeAff', + 'BridgeDam': 'g12/g12_4/BridgeDam', + 'BeleBridAff': 'g12/g12_5/BeleBridAff', + 'BeleBridDam': 'g12/g12_5/BeleBridDam', + 'DrainageAff': 'g12/g12_6/DrainageAff', + 'DrainageDam': 'g12/g12_6/DrainageDam', + 'DamAff': 'g13/g13_1/DamAff', + 'DamDamaged': 'g13/g13_1/DamDamaged', + 'WatGateAff': 'g13/g13_2/WatGateAff', + 'WatGateDam': 'g13/g13_2/WatGateDam', + 'PlumWelAff': 'g13/g13_3/PlumWelAff', + 'PlumWelDam': 'g13/g13_3/PlumWelDam', + 'DigWellAff': 'g13/g13_4/DigWellAff', + 'DigWellDam': 'g13/g13_4/DigWellDam', + 'PondAff': 'g13/g13_5/PondAff', + 'PondDam': 'g13/g13_5/PondDam', + 'LatrineAff': 'g13/g13_6/LatrineAff', + 'LatrineDam': 'g13/g13_6/LatrineDam', + 'RiverBreak': 'g13/g13_7/RiverBreak', + 'RiverBreakLo': 'g13/g13_7/RiverBreakLo', + 'BrolayAff': 'g13/BrolayAff', + 'BrolayDam': 'g13/BrolayDam', + 'NumFamTent': 'g14/g14_1/NumFamTent', + 'NumPeoTent': 'g14/g14_1/NumPeoTent', + 'NumFamBuil': 'g14/g14_2/NumFamBuil', + 'NumPeoBuil': 'g14/g14_2/NumPeoBuil', + 'NumFamRela': 'g14/g14_3/NumFamRela', + 'NumPeoRela': 'g14/g14_3/NumPeoRela', + 'NumTemSch': 'g15/g15_1/NumTemSch', + 'StuAcTemSch': 'g15/g15_1/StuAcTemSch', + 'SchUseSafe': 'g15/g15_2/SchUseSafe', + 'NumStu': 'g15/g15_2/NumStu', + 'NumSchStop': 'g15/g15_3/NumSchStop', + 'NumStuNoCla': 'g15/g15_3/NumStuNoCla', + 'NumFamNoWa': 'g16_1/g16_1_001/NumFamNoWa', + 'NumPeoNoWa': 'g16_1/g16_1_001/NumPeoNoWa', + 'TimeAceWa': 'g16_1/g16_1_001/TimeAceWa', + 'NuFamNoWaEq': 'g16_1/g16_1_001/NuFamNoWaEq', + 'NuFamNoLat': 'g16_1/g16_1_001/NuFamNoLat', + 'NonActingH': 'g17/g17_1/NonActingH', + 'PeoCanAceH': 'g17/g17_1/PeoCanAceH', + 'NumDoctor': 'g17/g17_1/NumDoctor', + 'NumNurse': 'g17/g17_1/NumNurse', + 'NumStaff': 'g17/g17_1/NumStaff', + 'NumFamNoFod': 'g18/g18_1/NumFamNoFod', + 'NumPeoNoFod': 'g18/g18_1/NumPeoNoFod', + 'FamNoFod7d': 'g18/FamNoFod7d', + 'NumActShop': 'g18/g18_2/NumActShop', + 'NumNoActShop': 'g18/g18_2/NumNoActShop', + 'RicePrice': 'g18/RicePrice', + 'threat': 'g19/threat', + 'other': 'g19/other', } as const; +export const floodSpecificKeysArray = Object.keys(floodSpecificKeys) +export type FloodSpecific = keyof typeof floodSpecificKeys; export type FloodSpecificType = Record; From bcf7c819b9ed58d50d53360ecf91ebfd250364fd Mon Sep 17 00:00:00 2001 From: Eric Boucher Date: Mon, 24 Apr 2023 17:06:27 +0200 Subject: [PATCH 2/4] feat(dedup): linting --- .../tablesConfig/NumAffected-1.tsx | 101 +++---- .../flood/generateFloodDetailedReport.ts | 14 +- packages/interfaces/src/kobo/mapping/flood.ts | 258 +++++++++--------- 3 files changed, 188 insertions(+), 185 deletions(-) diff --git a/apps/frontend/components/FormValidation/FloodFormValidation/tablesConfig/NumAffected-1.tsx b/apps/frontend/components/FormValidation/FloodFormValidation/tablesConfig/NumAffected-1.tsx index c840ce50..0082bcfb 100644 --- a/apps/frontend/components/FormValidation/FloodFormValidation/tablesConfig/NumAffected-1.tsx +++ b/apps/frontend/components/FormValidation/FloodFormValidation/tablesConfig/NumAffected-1.tsx @@ -1,77 +1,82 @@ import { GridColDef, GridColumnGroupingModel } from '@mui/x-data-grid'; -import { FLOOD, FloodSpecific } from '@wfp-dmp/interfaces'; +import { FLOOD, FloodSpecificType } from '@wfp-dmp/interfaces'; import { getColumnSetup, getGroupSetup } from 'utils/tableFormatting'; -export const NumAffected1Columns: GridColDef[] = [ - getColumnSetup(FloodSpecific.NumVillAff, FLOOD), - getColumnSetup(FloodSpecific.NumPeoAff, FLOOD), - getColumnSetup(FloodSpecific.NumFamAff, FLOOD), - getColumnSetup(FloodSpecific.NumFeAff, FLOOD), - getColumnSetup(FloodSpecific.NumTDeath, FLOOD), - getColumnSetup(FloodSpecific.NumMeDeath, FLOOD), - getColumnSetup(FloodSpecific.NumFeDeath, FLOOD), - getColumnSetup(FloodSpecific.NumKidDeath, FLOOD), - getColumnSetup(FloodSpecific.NumOldDeath, FLOOD), - getColumnSetup(FloodSpecific.NumDisDeath, FLOOD), - getColumnSetup(FloodSpecific.NumTMissing, FLOOD), - getColumnSetup(FloodSpecific.NumMeMissing, FLOOD), - getColumnSetup(FloodSpecific.NumFeMissing, FLOOD), - getColumnSetup(FloodSpecific.NumKidMissing, FLOOD), - getColumnSetup(FloodSpecific.NumOldMissing, FLOOD), - getColumnSetup(FloodSpecific.NumDisMissing, FLOOD), - getColumnSetup(FloodSpecific.NumTInjure, FLOOD), - getColumnSetup(FloodSpecific.NumMeInjure, FLOOD), - getColumnSetup(FloodSpecific.NumFeInjure, FLOOD), - getColumnSetup(FloodSpecific.NumKidInjure, FLOOD), - getColumnSetup(FloodSpecific.NumOldInjure, FLOOD), - getColumnSetup(FloodSpecific.NumDisInjure, FLOOD), +// TODO - Finish reorganizing this file for typing +const NumAffected1ColumnsKeys: FloodSpecificType[] = [ + 'NumVillAff', + 'NumPeoAff', + 'NumFamAff', + 'NumFeAff', + 'NumFeAff', + 'NumTDeath', + 'NumMeDeath', + 'NumFeDeath', + 'NumKidDeath', + 'NumOldDeath', + 'NumDisDeath', + 'NumTMissing', + 'NumMeMissing', + 'NumFeMissing', + 'NumKidMissing', + 'NumOldMissing', + 'NumDisMissing', + 'NumTInjure', + 'NumMeInjure', + 'NumFeInjure', + 'NumKidInjure', + 'NumOldInjure', + 'NumDisInjure', ]; +export const NumAffected1Columns: GridColDef[] = NumAffected1ColumnsKeys.map( + key => getColumnSetup(key, FLOOD), +); + +const keyAsField = (key: FloodSpecificType) => ({ field: key }); +const keysAsChildren = (keys: FloodSpecificType[]) => keys.map(keyAsField); + export const NumAffected1ColumnGroup: GridColumnGroupingModel = [ { ...getGroupSetup('victimsAffected', FLOOD), children: [ - { field: FloodSpecific.NumVillAff }, + keyAsField('NumVillAff'), { ...getGroupSetup('totalAffected', FLOOD), - children: [ - { field: FloodSpecific.NumPeoAff }, - { field: FloodSpecific.NumFamAff }, - { field: FloodSpecific.NumFeAff }, - ], + children: keysAsChildren(['NumPeoAff', 'NumFamAff', 'NumFeAff']), }, { ...getGroupSetup('deathToll', FLOOD), children: [ - { field: FloodSpecific.NumTDeath }, - { field: FloodSpecific.NumMeDeath }, - { field: FloodSpecific.NumFeDeath }, - { field: FloodSpecific.NumKidDeath }, - { field: FloodSpecific.NumOldDeath }, - { field: FloodSpecific.NumDisDeath }, + { field: 'NumTDeath' }, + { field: 'NumMeDeath' }, + { field: 'NumFeDeath' }, + { field: 'NumKidDeath' }, + { field: 'NumOldDeath' }, + { field: 'NumDisDeath' }, ], }, { ...getGroupSetup('missing', FLOOD), children: [ - { field: FloodSpecific.NumTMissing }, - { field: FloodSpecific.NumMeMissing }, - { field: FloodSpecific.NumFeMissing }, - { field: FloodSpecific.NumKidMissing }, - { field: FloodSpecific.NumOldMissing }, - { field: FloodSpecific.NumDisMissing }, + { field: 'NumTMissing' }, + { field: 'NumMeMissing' }, + { field: 'NumFeMissing' }, + { field: 'NumKidMissing' }, + { field: 'NumOldMissing' }, + { field: 'NumDisMissing' }, ], }, { ...getGroupSetup('injured', FLOOD), children: [ - { field: FloodSpecific.NumTInjure }, - { field: FloodSpecific.NumMeInjure }, - { field: FloodSpecific.NumFeInjure }, - { field: FloodSpecific.NumKidInjure }, - { field: FloodSpecific.NumOldInjure }, - { field: FloodSpecific.NumDisInjure }, + { field: 'NumTInjure' }, + { field: 'NumMeInjure' }, + { field: 'NumFeInjure' }, + { field: 'NumKidInjure' }, + { field: 'NumOldInjure' }, + { field: 'NumDisInjure' }, ], }, ], diff --git a/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts b/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts index ef09af66..6d43f075 100644 --- a/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts +++ b/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts @@ -1,4 +1,8 @@ -import { floodSpecificKeysArray, FloodSpecificType, KoboCommonKeys } from '@wfp-dmp/interfaces'; +import { + floodSpecificKeysArray, + FloodSpecificType, + KoboCommonKeys, +} from '@wfp-dmp/interfaces'; import { omit } from 'lodash'; import { aggregate } from '../aggregate'; @@ -7,15 +11,9 @@ import { filterNFlood } from '../filterNFlood'; const firstKeys = [KoboCommonKeys.province, KoboCommonKeys.district]; const sumKeys = Object.values( - omit(floodSpecificKeysArray, [ - 'floodN', - 'RicePrice', - 'threat', - 'other', - ]), + omit(floodSpecificKeysArray, ['floodN', 'RicePrice', 'threat', 'other']), ); - const countCategoriesKeys: FloodSpecificType[] = ['RicePrice']; const countMultipleChoicesKeys: FloodSpecificType[] = ['threat']; diff --git a/packages/interfaces/src/kobo/mapping/flood.ts b/packages/interfaces/src/kobo/mapping/flood.ts index 5c0abcb4..2e348f52 100644 --- a/packages/interfaces/src/kobo/mapping/flood.ts +++ b/packages/interfaces/src/kobo/mapping/flood.ts @@ -1,136 +1,136 @@ /* eslint-disable max-lines */ export const floodSpecificKeys = { - 'floodN': 'g2/flood_n', - 'NumVillAff': 'g3/g3_1/NumVillAff', - 'NumFamAff': 'g3/g3_1/g3_2/NumFamAff', - 'NumPeoAff': 'g3/g3_1/g3_2/NumPeoAff', - 'NumFeAff': 'g3/g3_1/g3_2/NumFeAff', - 'NumTDeath': 'g3/g4/TNumDeath', - 'NumMeDeath': 'g3/g4/NumMeDeath', - 'NumFeDeath': 'g3/g4/NumFeDeath', - 'NumKidDeath': 'g3/g4/NumKidDeath', - 'NumOldDeath': 'g3/g4/NumOldDeath', - 'NumDisDeath': 'g3/g4/NumDisDeath', - 'NumTMissing': 'g3/g5/NumTMising', - 'NumMeMissing': 'g3/g5/NumMeMising', - 'NumFeMissing': 'g3/g5/NumFeMising', - 'NumKidMissing': 'g3/g5/NumKidMising', - 'NumOldMissing': 'g3/g5/NumOldMising', - 'NumDisMissing': 'g3/g5/NumDisMising', - 'NumTInjure': 'g3/g6/NumTInjure', - 'NumMeInjure': 'g3/g6/NumMeInjure', - 'NumFeInjure': 'g3/g6/NumFeInjure', - 'NumKidInjure': 'g3/g6/NumKidInjure', - 'NumOldInjure': 'g3/g6/NumOldInjure', - 'NumDisInjure': 'g3/g6/NumDisInjure', - 'NumFamEva': 'g3/g7/NumFamEva', - 'NumPeoEva': 'g3/g7/NumPeoEva', - 'NumMeEva': 'g3/g7/NumMeEva', - 'NumFeEva': 'g3/g7/NumFeEva', - 'NumKidEva': 'g3/g7/NumKidEva', - 'NumOldEva': 'g3/g7/NumOldEva', - 'NumDisEva': 'g3/g7/NumDisEva', - 'NumFamRe': 'g3/g8/NumFamRe', - 'NumPeoRe': 'g3/g8/NumPeoRe', - 'NumMeRe': 'g3/g8/NumMeRe', - 'NumFeRe': 'g3/g8/NumFeRe', - 'NumKidRe': 'g3/g8/NumKidRe', - 'NumOldRe': 'g3/g8/NumOldRe', - 'NumDisRe': 'g3/g8/NumDisRe', - 'NumSafePla': 'g3/g9/NumSafePla', - 'NumPeoSEC': 'g3/g9/NumPeoSEC', - 'NumHouAff': 'g10/g10_1/NumHouAff', - 'NumHouDam': 'g10/g10_1/NumHouDam', - 'NumSchoAff': 'g10/g10_2/NumSchoAff', - 'NumSchoDam': 'g10/g10_2/NumSchoDam', - 'NumAffHeal': 'g10/g10_3/NumAffHeal', - 'NumDamHeal': 'g10/g10_3/NumDamHeal', - 'NumPagoAff': 'g10/g10_4/NumPagoAff', - 'NumPagoDam': 'g10/g10_4/NumPagoDam', - 'NumBuilAff': 'g10/g10_5/NumBuilAff', - 'NumBuilDam': 'g10/g10_5/NumBuilDam', - 'NumShopAff': 'g10/g10_6/NumShopAff', - 'NumShopDam': 'g10/g10_6/NumShopDam', - 'NumWareHAff': 'g10/g10_7/NumWareHAff', - 'NumWareHDam': 'g10/g10_7/NumWareHDam', - 'NumCraftAff': 'g10/g10_8/NumCraftAff', - 'NumCraftDam': 'g10/g10_8/NumCraftDam', - 'FarmAff': 'g11/g11_1/FarmAff', - 'FarmDam': 'g11/g11_1/FarmDam', - 'SamNabAff': 'g11/g11_2/SamNabAff', - 'SamNabDam': 'g11/g11_2/SamNabDam', - 'PaddyAff': 'g11/g11_3/PaddyAff', - 'PaddyDam': 'g11/g11_3/PaddyDam', - 'CowEva': 'g11/g11_4/CowEva', - 'CowDeath': 'g11/g11_4/CowDeath', - 'CowMissing': 'g11/g11_4/CowMissing', - 'PigEva': 'g11/g11_5/PigEva', - 'PigDeath': 'g11/g11_5/PigDeath', - 'PigMissing': 'g11/g11_5/PigMissing', - 'BirdEva': 'g11/g11_6/BirdEva', - 'BirdDeath': 'g11/g11_6/BirdDeath', - 'BirdMissing': 'g11/g11_6/BirdMissing', - 'RubberRoAff': 'g12/g12_1/RubberRoAff', - 'RubberRoDam': 'g12/g12_1/RubberRoDam', - 'ConcretAff': 'g12/g12_2/ConcretAff', - 'ConcretDam': 'g12/g12_2/ConcretDam', - 'RuralRoAff': 'g12/g12_3/RuralRoAff', - 'RuralRoDam': 'g12/g12_3/RuralRoDam', - 'BridgeAff': 'g12/g12_4/BridgeAff', - 'BridgeDam': 'g12/g12_4/BridgeDam', - 'BeleBridAff': 'g12/g12_5/BeleBridAff', - 'BeleBridDam': 'g12/g12_5/BeleBridDam', - 'DrainageAff': 'g12/g12_6/DrainageAff', - 'DrainageDam': 'g12/g12_6/DrainageDam', - 'DamAff': 'g13/g13_1/DamAff', - 'DamDamaged': 'g13/g13_1/DamDamaged', - 'WatGateAff': 'g13/g13_2/WatGateAff', - 'WatGateDam': 'g13/g13_2/WatGateDam', - 'PlumWelAff': 'g13/g13_3/PlumWelAff', - 'PlumWelDam': 'g13/g13_3/PlumWelDam', - 'DigWellAff': 'g13/g13_4/DigWellAff', - 'DigWellDam': 'g13/g13_4/DigWellDam', - 'PondAff': 'g13/g13_5/PondAff', - 'PondDam': 'g13/g13_5/PondDam', - 'LatrineAff': 'g13/g13_6/LatrineAff', - 'LatrineDam': 'g13/g13_6/LatrineDam', - 'RiverBreak': 'g13/g13_7/RiverBreak', - 'RiverBreakLo': 'g13/g13_7/RiverBreakLo', - 'BrolayAff': 'g13/BrolayAff', - 'BrolayDam': 'g13/BrolayDam', - 'NumFamTent': 'g14/g14_1/NumFamTent', - 'NumPeoTent': 'g14/g14_1/NumPeoTent', - 'NumFamBuil': 'g14/g14_2/NumFamBuil', - 'NumPeoBuil': 'g14/g14_2/NumPeoBuil', - 'NumFamRela': 'g14/g14_3/NumFamRela', - 'NumPeoRela': 'g14/g14_3/NumPeoRela', - 'NumTemSch': 'g15/g15_1/NumTemSch', - 'StuAcTemSch': 'g15/g15_1/StuAcTemSch', - 'SchUseSafe': 'g15/g15_2/SchUseSafe', - 'NumStu': 'g15/g15_2/NumStu', - 'NumSchStop': 'g15/g15_3/NumSchStop', - 'NumStuNoCla': 'g15/g15_3/NumStuNoCla', - 'NumFamNoWa': 'g16_1/g16_1_001/NumFamNoWa', - 'NumPeoNoWa': 'g16_1/g16_1_001/NumPeoNoWa', - 'TimeAceWa': 'g16_1/g16_1_001/TimeAceWa', - 'NuFamNoWaEq': 'g16_1/g16_1_001/NuFamNoWaEq', - 'NuFamNoLat': 'g16_1/g16_1_001/NuFamNoLat', - 'NonActingH': 'g17/g17_1/NonActingH', - 'PeoCanAceH': 'g17/g17_1/PeoCanAceH', - 'NumDoctor': 'g17/g17_1/NumDoctor', - 'NumNurse': 'g17/g17_1/NumNurse', - 'NumStaff': 'g17/g17_1/NumStaff', - 'NumFamNoFod': 'g18/g18_1/NumFamNoFod', - 'NumPeoNoFod': 'g18/g18_1/NumPeoNoFod', - 'FamNoFod7d': 'g18/FamNoFod7d', - 'NumActShop': 'g18/g18_2/NumActShop', - 'NumNoActShop': 'g18/g18_2/NumNoActShop', - 'RicePrice': 'g18/RicePrice', - 'threat': 'g19/threat', - 'other': 'g19/other', + floodN: 'g2/flood_n', + NumVillAff: 'g3/g3_1/NumVillAff', + NumFamAff: 'g3/g3_1/g3_2/NumFamAff', + NumPeoAff: 'g3/g3_1/g3_2/NumPeoAff', + NumFeAff: 'g3/g3_1/g3_2/NumFeAff', + NumTDeath: 'g3/g4/TNumDeath', + NumMeDeath: 'g3/g4/NumMeDeath', + NumFeDeath: 'g3/g4/NumFeDeath', + NumKidDeath: 'g3/g4/NumKidDeath', + NumOldDeath: 'g3/g4/NumOldDeath', + NumDisDeath: 'g3/g4/NumDisDeath', + NumTMissing: 'g3/g5/NumTMising', + NumMeMissing: 'g3/g5/NumMeMising', + NumFeMissing: 'g3/g5/NumFeMising', + NumKidMissing: 'g3/g5/NumKidMising', + NumOldMissing: 'g3/g5/NumOldMising', + NumDisMissing: 'g3/g5/NumDisMising', + NumTInjure: 'g3/g6/NumTInjure', + NumMeInjure: 'g3/g6/NumMeInjure', + NumFeInjure: 'g3/g6/NumFeInjure', + NumKidInjure: 'g3/g6/NumKidInjure', + NumOldInjure: 'g3/g6/NumOldInjure', + NumDisInjure: 'g3/g6/NumDisInjure', + NumFamEva: 'g3/g7/NumFamEva', + NumPeoEva: 'g3/g7/NumPeoEva', + NumMeEva: 'g3/g7/NumMeEva', + NumFeEva: 'g3/g7/NumFeEva', + NumKidEva: 'g3/g7/NumKidEva', + NumOldEva: 'g3/g7/NumOldEva', + NumDisEva: 'g3/g7/NumDisEva', + NumFamRe: 'g3/g8/NumFamRe', + NumPeoRe: 'g3/g8/NumPeoRe', + NumMeRe: 'g3/g8/NumMeRe', + NumFeRe: 'g3/g8/NumFeRe', + NumKidRe: 'g3/g8/NumKidRe', + NumOldRe: 'g3/g8/NumOldRe', + NumDisRe: 'g3/g8/NumDisRe', + NumSafePla: 'g3/g9/NumSafePla', + NumPeoSEC: 'g3/g9/NumPeoSEC', + NumHouAff: 'g10/g10_1/NumHouAff', + NumHouDam: 'g10/g10_1/NumHouDam', + NumSchoAff: 'g10/g10_2/NumSchoAff', + NumSchoDam: 'g10/g10_2/NumSchoDam', + NumAffHeal: 'g10/g10_3/NumAffHeal', + NumDamHeal: 'g10/g10_3/NumDamHeal', + NumPagoAff: 'g10/g10_4/NumPagoAff', + NumPagoDam: 'g10/g10_4/NumPagoDam', + NumBuilAff: 'g10/g10_5/NumBuilAff', + NumBuilDam: 'g10/g10_5/NumBuilDam', + NumShopAff: 'g10/g10_6/NumShopAff', + NumShopDam: 'g10/g10_6/NumShopDam', + NumWareHAff: 'g10/g10_7/NumWareHAff', + NumWareHDam: 'g10/g10_7/NumWareHDam', + NumCraftAff: 'g10/g10_8/NumCraftAff', + NumCraftDam: 'g10/g10_8/NumCraftDam', + FarmAff: 'g11/g11_1/FarmAff', + FarmDam: 'g11/g11_1/FarmDam', + SamNabAff: 'g11/g11_2/SamNabAff', + SamNabDam: 'g11/g11_2/SamNabDam', + PaddyAff: 'g11/g11_3/PaddyAff', + PaddyDam: 'g11/g11_3/PaddyDam', + CowEva: 'g11/g11_4/CowEva', + CowDeath: 'g11/g11_4/CowDeath', + CowMissing: 'g11/g11_4/CowMissing', + PigEva: 'g11/g11_5/PigEva', + PigDeath: 'g11/g11_5/PigDeath', + PigMissing: 'g11/g11_5/PigMissing', + BirdEva: 'g11/g11_6/BirdEva', + BirdDeath: 'g11/g11_6/BirdDeath', + BirdMissing: 'g11/g11_6/BirdMissing', + RubberRoAff: 'g12/g12_1/RubberRoAff', + RubberRoDam: 'g12/g12_1/RubberRoDam', + ConcretAff: 'g12/g12_2/ConcretAff', + ConcretDam: 'g12/g12_2/ConcretDam', + RuralRoAff: 'g12/g12_3/RuralRoAff', + RuralRoDam: 'g12/g12_3/RuralRoDam', + BridgeAff: 'g12/g12_4/BridgeAff', + BridgeDam: 'g12/g12_4/BridgeDam', + BeleBridAff: 'g12/g12_5/BeleBridAff', + BeleBridDam: 'g12/g12_5/BeleBridDam', + DrainageAff: 'g12/g12_6/DrainageAff', + DrainageDam: 'g12/g12_6/DrainageDam', + DamAff: 'g13/g13_1/DamAff', + DamDamaged: 'g13/g13_1/DamDamaged', + WatGateAff: 'g13/g13_2/WatGateAff', + WatGateDam: 'g13/g13_2/WatGateDam', + PlumWelAff: 'g13/g13_3/PlumWelAff', + PlumWelDam: 'g13/g13_3/PlumWelDam', + DigWellAff: 'g13/g13_4/DigWellAff', + DigWellDam: 'g13/g13_4/DigWellDam', + PondAff: 'g13/g13_5/PondAff', + PondDam: 'g13/g13_5/PondDam', + LatrineAff: 'g13/g13_6/LatrineAff', + LatrineDam: 'g13/g13_6/LatrineDam', + RiverBreak: 'g13/g13_7/RiverBreak', + RiverBreakLo: 'g13/g13_7/RiverBreakLo', + BrolayAff: 'g13/BrolayAff', + BrolayDam: 'g13/BrolayDam', + NumFamTent: 'g14/g14_1/NumFamTent', + NumPeoTent: 'g14/g14_1/NumPeoTent', + NumFamBuil: 'g14/g14_2/NumFamBuil', + NumPeoBuil: 'g14/g14_2/NumPeoBuil', + NumFamRela: 'g14/g14_3/NumFamRela', + NumPeoRela: 'g14/g14_3/NumPeoRela', + NumTemSch: 'g15/g15_1/NumTemSch', + StuAcTemSch: 'g15/g15_1/StuAcTemSch', + SchUseSafe: 'g15/g15_2/SchUseSafe', + NumStu: 'g15/g15_2/NumStu', + NumSchStop: 'g15/g15_3/NumSchStop', + NumStuNoCla: 'g15/g15_3/NumStuNoCla', + NumFamNoWa: 'g16_1/g16_1_001/NumFamNoWa', + NumPeoNoWa: 'g16_1/g16_1_001/NumPeoNoWa', + TimeAceWa: 'g16_1/g16_1_001/TimeAceWa', + NuFamNoWaEq: 'g16_1/g16_1_001/NuFamNoWaEq', + NuFamNoLat: 'g16_1/g16_1_001/NuFamNoLat', + NonActingH: 'g17/g17_1/NonActingH', + PeoCanAceH: 'g17/g17_1/PeoCanAceH', + NumDoctor: 'g17/g17_1/NumDoctor', + NumNurse: 'g17/g17_1/NumNurse', + NumStaff: 'g17/g17_1/NumStaff', + NumFamNoFod: 'g18/g18_1/NumFamNoFod', + NumPeoNoFod: 'g18/g18_1/NumPeoNoFod', + FamNoFod7d: 'g18/FamNoFod7d', + NumActShop: 'g18/g18_2/NumActShop', + NumNoActShop: 'g18/g18_2/NumNoActShop', + RicePrice: 'g18/RicePrice', + threat: 'g19/threat', + other: 'g19/other', } as const; -export const floodSpecificKeysArray = Object.keys(floodSpecificKeys) +export const floodSpecificKeysArray = Object.keys(floodSpecificKeys); export type FloodSpecific = keyof typeof floodSpecificKeys; export type FloodSpecificType = Record; From d1d5191b373e18d48b410e4a2f3d28745eff7434 Mon Sep 17 00:00:00 2001 From: Eric Boucher Date: Mon, 24 Apr 2023 17:09:19 +0200 Subject: [PATCH 3/4] feat(typing): correct type --- .../FloodFormValidation/tablesConfig/NumAffected-1.tsx | 8 ++++---- .../utils/aggregate/flood/generateFloodDetailedReport.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/frontend/components/FormValidation/FloodFormValidation/tablesConfig/NumAffected-1.tsx b/apps/frontend/components/FormValidation/FloodFormValidation/tablesConfig/NumAffected-1.tsx index 0082bcfb..6769dff6 100644 --- a/apps/frontend/components/FormValidation/FloodFormValidation/tablesConfig/NumAffected-1.tsx +++ b/apps/frontend/components/FormValidation/FloodFormValidation/tablesConfig/NumAffected-1.tsx @@ -1,10 +1,10 @@ import { GridColDef, GridColumnGroupingModel } from '@mui/x-data-grid'; -import { FLOOD, FloodSpecificType } from '@wfp-dmp/interfaces'; +import { FLOOD, FloodSpecific } from '@wfp-dmp/interfaces'; import { getColumnSetup, getGroupSetup } from 'utils/tableFormatting'; // TODO - Finish reorganizing this file for typing -const NumAffected1ColumnsKeys: FloodSpecificType[] = [ +const NumAffected1ColumnsKeys: FloodSpecific[] = [ 'NumVillAff', 'NumPeoAff', 'NumFamAff', @@ -34,8 +34,8 @@ export const NumAffected1Columns: GridColDef[] = NumAffected1ColumnsKeys.map( key => getColumnSetup(key, FLOOD), ); -const keyAsField = (key: FloodSpecificType) => ({ field: key }); -const keysAsChildren = (keys: FloodSpecificType[]) => keys.map(keyAsField); +const keyAsField = (key: FloodSpecific) => ({ field: key }); +const keysAsChildren = (keys: FloodSpecific[]) => keys.map(keyAsField); export const NumAffected1ColumnGroup: GridColumnGroupingModel = [ { diff --git a/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts b/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts index 6d43f075..5f104811 100644 --- a/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts +++ b/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts @@ -1,6 +1,6 @@ import { + FloodSpecific, floodSpecificKeysArray, - FloodSpecificType, KoboCommonKeys, } from '@wfp-dmp/interfaces'; import { omit } from 'lodash'; @@ -14,8 +14,8 @@ const sumKeys = Object.values( omit(floodSpecificKeysArray, ['floodN', 'RicePrice', 'threat', 'other']), ); -const countCategoriesKeys: FloodSpecificType[] = ['RicePrice']; -const countMultipleChoicesKeys: FloodSpecificType[] = ['threat']; +const countCategoriesKeys: FloodSpecific[] = ['RicePrice']; +const countMultipleChoicesKeys: FloodSpecific[] = ['threat']; export const generateFloodDetailedReport = ( data: Record[], From 710389fafa5fc5e3e4a4bd91d0af2770ea2ec96d Mon Sep 17 00:00:00 2001 From: Eric Boucher Date: Mon, 24 Apr 2023 17:18:24 +0200 Subject: [PATCH 4/4] feat(typing): fix sumKeys --- .../utils/aggregate/flood/generateFloodDetailedReport.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts b/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts index 5f104811..747ed2e0 100644 --- a/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts +++ b/apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts @@ -3,15 +3,14 @@ import { floodSpecificKeysArray, KoboCommonKeys, } from '@wfp-dmp/interfaces'; -import { omit } from 'lodash'; import { aggregate } from '../aggregate'; import { filterNFlood } from '../filterNFlood'; const firstKeys = [KoboCommonKeys.province, KoboCommonKeys.district]; -const sumKeys = Object.values( - omit(floodSpecificKeysArray, ['floodN', 'RicePrice', 'threat', 'other']), +const sumKeys = floodSpecificKeysArray.filter( + k => !['floodN', 'RicePrice', 'threat', 'other'].includes(k), ); const countCategoriesKeys: FloodSpecific[] = ['RicePrice'];