this is slightly wrong, because it runs with each loop iteration, but the other `sum_*` variables are only inside the loop because they are summing up. the query however only needs to run one single time. in other words: move this line out of the loop and merge it with the `= 0` initialization above.

also `if page == 'pilot'` we don't need to run this query and just set it to 0 or 1 then.