Skip to content

Commit 9b505ff

Browse files
committed
add comments to sql query to calculate project progress
1 parent 99ca63f commit 9b505ff

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

mapswipe_workers/mapswipe_workers/firebase_to_postgres/update_data.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,22 @@ def set_progress_in_firebase(project_id: str):
131131

132132
pg_db = auth.postgresDB()
133133
query = """
134+
-- Calculate overall project progress as
135+
-- the average progress for all groups.
136+
-- This is not hundred percent exact, since groups can have a different number of tasks
137+
-- but it is still "good enough" and gives almost correct progress.
138+
-- But it is easier to compute
139+
-- than considering the actual number of tasks per group.
134140
select
135141
project_id
136142
,avg(group_progress)::integer as progress
137143
from
138-
(
144+
(
145+
-- Get all groups for this project and
146+
-- add progress for groups that have been worked on already.
147+
-- Set progress to 0 if no user has worked on this group.
148+
-- For groups that no users worked on
149+
-- there are no entries in the results table.
139150
select
140151
g.group_id
141152
,g.project_id
@@ -146,12 +157,16 @@ def set_progress_in_firebase(project_id: str):
146157
from groups g
147158
left join
148159
(
160+
-- here we get the progress for all groups
161+
-- for which results have been submitted already
162+
-- progress for a group can be max 100
163+
-- even if more users than required submitted results
149164
select
150165
r.group_id
151166
,r.project_id
152167
,case
153168
when count(distinct user_id) >= p.verification_number then 100
154-
else 100* count(distinct user_id) / p.verification_number
169+
else 100 * count(distinct user_id) / p.verification_number
155170
end as group_progress
156171
from results r, projects p
157172
where r.project_id = p.project_id

0 commit comments

Comments
 (0)