Skip to content
New issue

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

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

Already on GitHub? # to your account

Move group aggregated columns calculation logic #852

Open
2 tasks
thenav56 opened this issue Jun 13, 2023 · 0 comments
Open
2 tasks

Move group aggregated columns calculation logic #852

thenav56 opened this issue Jun 13, 2023 · 0 comments
Assignees
Labels

Comments

@thenav56
Copy link
Contributor

thenav56 commented Jun 13, 2023

Related to: #780 (comment)

Currently, we are calculating the group's total area and max time allowed using the aggregated module as it is only used by it introduced in PR#780.
For more consistency, we will have to move this to the project->creation pipeline.

Basic Query needed:

groups_data AS (
  SELECT
    T.project_id,
    T.group_id,
    SUM( -- sqkm
      ST_Area(T.geom::geography(GEOMETRY,4326)) / 1000000
    ) as total_task_group_area,
    (
      CASE
        -- Using 95_percent value of existing data for each project_type
        WHEN P.project_type = {Project.Type.BUILD_AREA.value} THEN 1.4
        WHEN P.project_type = {Project.Type.COMPLETENESS.value} THEN 1.4
        WHEN P.project_type = {Project.Type.CHANGE_DETECTION.value} THEN 11.2
        -- FOOTPRINT: Not calculated right now
        WHEN P.project_type = {Project.Type.FOOTPRINT.value} THEN 6.1
        ELSE 1
      END
    ) * COUNT(*) as time_spent_max_allowed
  FROM tasks T
    INNER JOIN projects P USING (project_id)
  WHERE T.project_id = %(project_id)s
  GROUP BY project_id, P.project_type, group_id
)
UPDATE groups G
SET
  total_area = GD.total_task_group_area,
  time_spent_max_allowed = GD.time_spent_max_allowed
FROM groups_data GD
WHERE
  G.project_id = GD.project_id AND
  G.group_id = GD.group_id;

Tasks

cc: @Hagellach37 @ElJocho

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants