Skip to content

Commit

Permalink
4123 - Fix FRA 2020 SDG table columns (#4125)
Browse files Browse the repository at this point in the history
  • Loading branch information
minotogna authored Nov 18, 2024
1 parent 7ca93f6 commit 9a61394
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 363 deletions.
2 changes: 2 additions & 0 deletions src/meta/assessment/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export enum TableNames {
growingStockTotal = 'growingStockTotal',
primaryDesignatedManagementObjective = 'primaryDesignatedManagementObjective',
specificForestCategories = 'specificForestCategories',
sustainableDevelopment15_2_1_1 = 'sustainableDevelopment15_2_1_1',
sustainableDevelopment15_2_1_2 = 'sustainableDevelopment15_2_1_2',
sustainableDevelopment15_2_1_5 = 'sustainableDevelopment15_2_1_5',
totalAreaWithDesignatedManagementObjective = 'totalAreaWithDesignatedManagementObjective',
// Used to append ODP data to tableData
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { AssessmentNames, TableNames } from 'meta/assessment'

import { AssessmentController } from 'server/controller/assessment'
import { BaseProtocol, Schemas } from 'server/db'

import { updateDependencies } from 'test/migrations/steps/utils/updateDependencies'

const assessmentName = AssessmentNames.fra
const cycleName = '2020'

export default async (client: BaseProtocol) => {
const { assessment, cycle } = await AssessmentController.getOneWithCycle({ assessmentName, cycleName }, client)

const { uuid: cycleUuid } = cycle
const schemaAssessment = Schemas.getName(assessment)

await client.query(`
with src as
(select c.id
from ${schemaAssessment}.col c
left join ${schemaAssessment}.row r on r.id = c.row_id
left join ${schemaAssessment}."table" t on t.id = r.table_id
where t.props ->> 'name' = '${TableNames.sustainableDevelopment15_2_1_1}'
and c.props ->> 'colType' = 'header'
and r.props ->> 'index' = 'header_1'
and c.props ->> 'index' = '10')
update ${schemaAssessment}.col c
set props = c.props #- '{style,${cycleUuid}}'
#- '{labels,${cycleUuid}}'
|| jsonb_build_object('cycles', (c.props -> 'cycles') - '${cycleUuid}')
from src
where c.id = src.id;
with src as
(select c.id
from ${schemaAssessment}.col c
left join ${schemaAssessment}.row r on r.id = c.row_id
left join ${schemaAssessment}."table" t on t.id = r.table_id
where t.props ->> 'name' = '${TableNames.sustainableDevelopment15_2_1_2}'
and c.props ->> 'colName' = '2020'
order by c.props -> 'index')
update ${schemaAssessment}.col c
set props = jsonb_set(
jsonb_set(
c.props, '{style,${cycleUuid}}', '{}'::jsonb
),
'{calculateFn,${cycleUuid}}',
'"biomassStock.forest_above_ground"'
)
||
jsonb_build_object('cycles', (c.props -> 'cycles') || '["${cycleUuid}"]')
from src
where c.id = src.id;
`)

await AssessmentController.generateMetadataCache({ assessment }, client)

const update = await AssessmentController.getOneWithCycle({ assessmentName, cycleName, metaCache: true }, client)
await updateDependencies(
{
...update,
includeSourceNodes: true,
nodes: [
{
tableName: TableNames.sustainableDevelopment15_2_1_2,
variableName: 'aboveGroundBiomassStockForests',
colName: '2020',
value: { raw: undefined },
},
],
},
client
)
}
108 changes: 0 additions & 108 deletions src/test/migrations/steps/utils/calculateRow.ts

This file was deleted.

55 changes: 0 additions & 55 deletions src/test/migrations/steps/utils/getRow.ts

This file was deleted.

64 changes: 0 additions & 64 deletions src/test/migrations/steps/utils/runCalculations.ts

This file was deleted.

Loading

0 comments on commit 9a61394

Please sign in to comment.