Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(chore) cost surface data migration script #1501

Closed
wants to merge 1 commit into from

Conversation

alexeh
Copy link
Collaborator

@alexeh alexeh commented Sep 18, 2023

Script for handling the data migration for existing projects and scenarios.

NOTE: Since this will be run most likely from NOT the host, I haven't add any requirements.txt.

Overview

API:
For each scenario, create a cost surface within the project, and set it as the scenarios cost surface. We use the scenario name as cost surface name

For each project, create a new cost surface using 'Default' as name, and set it as default cost surface for the project.

GEO & API
for each scenario in api, get its cost surface and compute min and max from scenario_pu_cost_data.
update api.cost_surface with said min,max

for each project, get its default cost surface and insert it's default cost in cost_surface_pu_data
update the the api.cost_surface computing the min and max from the new cost

Error handling
There might be scenarios in API that has no cost in GEO. I have assumed this should not happen, so I am deleting the scenario and its cost_surface in API

I don't know if the same could happen for projects

Testing instructions

Basically the above should happen

Feature relevant tickets

Link to the related task manager tickets


Checklist before submitting

  • Meaningful commits and code rebased on develop.
  • If this PR adds feature that should be tested for regressions when
    deploying to staging/production, please add brief testing instructions
    to the deploy checklist (docs/deployment-checklist.md)
  • Update CHANGELOG file

@vercel
Copy link

vercel bot commented Sep 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
marxan ✅ Ready (Inspect) Visit Preview Sep 18, 2023 1:59am

min_val, max_val = min_max if min_max else (None, None)

# If min and max are null, remove scenario and cost_surface from api_db
if min_val is None or max_val is None:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please give extra love to this part

INNER JOIN planning_units_geom pug ON pug.id = ppu.geom_id
WHERE ppu.project_id = '{project_id}';
""")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: insert for each scenario in apiDB

print(len(all_projects), "projects")
except Exception as e:
print(e)
cur_api_db.execute("ROLLBACK;")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: All ops in one single transaction: one commit, one rollback

@hotzevzl
Copy link
Member

closing as we included this, with some tweaks, in #1494

@hotzevzl hotzevzl closed this Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants