-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #305 from Vizzuality/chore/api/output-entities-def…
…inition output entities migration ready + fake data for outputs
- Loading branch information
Showing
33 changed files
with
914 additions
and
321 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
api/apps/api/src/migrations/api/1624890503611-marxanOutputEntities.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class marxanOutputEntities1624890503611 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
-- Rename output summary table to be more verbose - maps output_sum | ||
-- Also connectivity_in, edge, out and fraction should be under metadata | ||
ALTER TABLE output_results | ||
RENAME TO output_scenarios_summaries; | ||
ALTER TABLE output_scenarios_summaries | ||
RENAME COLUMN scenarios_id TO scenario_id; | ||
ALTER TABLE output_scenarios_summaries | ||
ADD COLUMN best bool, | ||
ADD COLUMN distinct_five bool; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
-- Rename output summary table to is past | ||
ALTER TABLE output_scenarios_summaries | ||
RENAME TO output_results; | ||
ALTER TABLE output_results | ||
RENAME COLUMN scenario_id TO scenarios_id, | ||
DROP COLUMN best, | ||
DROP COLUMN distinct_five; | ||
`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,10 +52,32 @@ VALUES | |
((SELECT id FROM users WHERE lower(email) = '[email protected]'), (SELECT id FROM projects WHERE name = 'Example Project 2 Org 2'), 'project_user'); | ||
|
||
INSERT INTO scenarios | ||
(name, project_id, type, wdpa_threshold, created_by) | ||
(name, project_id, type, wdpa_threshold, number_of_runs, blm, created_by) | ||
VALUES | ||
('Example scenario 1 Project 1 Org 1', (select id from projects where name = 'Example Project 1 Org 1'), 'marxan', 30, (SELECT id FROM users WHERE email = '[email protected]') ), | ||
('Example scenario 2 Project 1 Org 1', (select id from projects where name = 'Example Project 1 Org 1'), 'marxan', 50, (SELECT id FROM users WHERE email = '[email protected]') ), | ||
('Example scenario 1 Project 2 Org 2', (select id from projects where name = 'Example Project 2 Org 2'), 'marxan', 30, (SELECT id FROM users WHERE email = '[email protected]') ), | ||
('Example scenario 2 Project 2 Org 2', (select id from projects where name = 'Example Project 2 Org 2'), 'marxan', 50, (SELECT id FROM users WHERE email = '[email protected]') ); | ||
('Example scenario 1 Project 1 Org 1', (select id from projects where name = 'Example Project 1 Org 1'), 'marxan', 30, 100, 1, (SELECT id FROM users WHERE email = '[email protected]') ), | ||
('Example scenario 2 Project 1 Org 1', (select id from projects where name = 'Example Project 1 Org 1'), 'marxan', 50, 100, 1, (SELECT id FROM users WHERE email = '[email protected]') ), | ||
('Example scenario 1 Project 2 Org 2', (select id from projects where name = 'Example Project 2 Org 2'), 'marxan', 30, 100, 1, (SELECT id FROM users WHERE email = '[email protected]') ), | ||
('Example scenario 2 Project 2 Org 2', (select id from projects where name = 'Example Project 2 Org 2'), 'marxan', 50, 100, 1, (SELECT id FROM users WHERE email = '[email protected]') ); | ||
|
||
-- Fake summary outputs | ||
WITH RECURSIVE nums (n) AS ( | ||
SELECT 1 | ||
UNION ALL | ||
SELECT n+1 FROM nums WHERE n+1 <= 10 | ||
) | ||
INSERT INTO output_scenarios_summaries | ||
(run_id, scenario_id, score, "cost", planning_units, connectivity, connectivity_total, | ||
mpm, penalty, shortfall, missing_values, best, distinct_five) | ||
SELECT n as run_id, oss.id as scenario_id, | ||
round(random()*5359200) score, | ||
round(random()*53592) as "cost", | ||
53000 + round(random()*591) as planning_units, | ||
round(random()*53592000) as connectivity, | ||
53592000 as connectivity_total, 1 as mpm, | ||
round(random()*2000) as penalty, | ||
20449 as shortfall, | ||
round(random()) as missing_values, | ||
false as best, | ||
false as distinct_five | ||
FROM nums, scenarios oss | ||
where oss.id=(select id from scenarios where name = 'Example scenario 1 Project 1 Org 1') |
Oops, something went wrong.