Skip to content

Commit

Permalink
Restrict access to purpleair until we can remove data
Browse files Browse the repository at this point in the history
  • Loading branch information
caparker committed Mar 10, 2024
1 parent 5059136 commit 13b8359
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 179 deletions.
32 changes: 17 additions & 15 deletions openaq_api/openaq_api/routers/cities.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,31 +105,32 @@ async def cities_get(
elif cities.order_by == "locations":
order_by = "locations"
q = f"""
SELECT
SELECT
count(*) over () as citiescount,
c.iso AS country
, sn.city AS city
, SUM(sr.value_count) AS "count"
, COUNT(DISTINCT sn.sensor_nodes_id) AS locations
, MIN(sr.datetime_first)::TEXT AS first_updated
, MAX(sr.datetime_last)::TEXT AS last_updated
, array_agg(DISTINCT m.measurand) AS parameters
, MIN(sr.datetime_first)::TEXT AS first_updated
, MAX(sr.datetime_last)::TEXT AS last_updated
, array_agg(DISTINCT m.measurand) AS parameters
, COUNT(1) OVER() as found
FROM
FROM
sensors_rollup sr
JOIN
JOIN
sensors s USING (sensors_id)
JOIN
sensor_systems ss USING (sensor_systems_id)
JOIN
sensor_nodes sn USING (sensor_nodes_id)
JOIN
JOIN
countries c USING (countries_id)
JOIN
measurands m USING (measurands_id)
JOIN
measurands m USING (measurands_id)
WHERE
{cities.where()}
and city is not null
AND city is not null
AND s.is_public
GROUP BY c.iso, sn.city
ORDER BY {order_by} {cities.sort}
OFFSET :offset
Expand Down Expand Up @@ -161,27 +162,28 @@ async def cities_getv1(
elif cities.order_by == "locations":
order_by = "locations"
q = f"""
SELECT
SELECT
count(*) over () as citiescount
, c.iso AS country
, sn.city AS "name"
, sn.city AS city
, SUM(sr.value_count) AS "count"
, COUNT(DISTINCT sn.sensor_nodes_id) AS locations
, COUNT(1) OVER() as found
FROM
FROM
sensors_rollup sr
JOIN
JOIN
sensors s USING (sensors_id)
JOIN
sensor_systems ss USING (sensor_systems_id)
JOIN
sensor_nodes sn USING (sensor_nodes_id)
JOIN
JOIN
countries c USING (countries_id)
WHERE
{cities.where()}
and city is not null
AND city is not null
AND s.is_public
GROUP BY c.iso, sn.city
ORDER BY {order_by} {cities.sort}
OFFSET :offset
Expand Down
6 changes: 5 additions & 1 deletion openaq_api/openaq_api/routers/countries.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ async def countries_by_path(
WHERE
c.iso IS NOT NULL
AND c.countries_id = :country_id
AND sn.is_public
GROUP BY code, c.name, c.countries_id
OFFSET :offset
LIMIT :limit
Expand Down Expand Up @@ -215,6 +216,7 @@ async def countries_get(
WHERE
{countries.where()}
AND c.iso IS NOT NULL
AND sn.is_public
GROUP BY code, c.name
ORDER BY {order_by} {countries.sort}
OFFSET :offset
Expand Down Expand Up @@ -270,7 +272,9 @@ async def countries_getv1(
WHERE
{countries.where()}
AND
c.iso IS NOT NULL
c.iso IS NOT NULL
AND
sn.is_public
GROUP BY code, c.name
ORDER BY {order_by} {countries.sort}
OFFSET :offset
Expand Down
1 change: 1 addition & 0 deletions openaq_api/openaq_api/routers/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ async def sources_get(
--LEFT JOIN groups_view USING (groups_id, measurands_id)
--WHERE rollup='total' AND groups_view.type='node'
WHERE {sources.where()}
AND sensors.is_public
GROUP BY
1,2,3,4,5
ORDER BY "{sources.order_by}" {sources.sort}
Expand Down
13 changes: 6 additions & 7 deletions openaq_api/openaq_api/v3/routers/manufacturers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,21 @@ async def manufacturers_get(

async def fetch_manufacturers(query, db):
query_builder = QueryBuilder(query)
sql = f"""
SELECT
sql = f"""
SELECT
e.entities_id AS id
, e.full_name AS name
, ARRAY_AGG(DISTINCT (jsonb_build_object('id', i.instruments_id, 'name', i.label))) AS instruments
, COUNT(1) OVER() AS found
FROM
FROM
sensor_nodes sn
JOIN
JOIN
sensor_systems ss ON sn.sensor_nodes_id = ss.sensor_nodes_id
JOIN
JOIN
instruments i ON i.instruments_id = ss.instruments_id
JOIN
JOIN
entities e ON e.entities_id = i.manufacturer_entities_id
{query_builder.where()}
GROUP BY id, name
{query_builder.pagination()};
Expand Down
1 change: 1 addition & 0 deletions openaq_api/openaq_api/v3/routers/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ async def fetch_measurements(q, db):
JOIN sensor_nodes sn ON (sy.sensor_nodes_id = sn.sensor_nodes_id)
JOIN timezones ts ON (sn.timezones_id = ts.gid)
{query.where()}
AND sn.is_public AND s.is_public
GROUP BY 1, 2, 3, 4)
SELECT t.sensor_nodes_id
, json_build_object(
Expand Down
1 change: 1 addition & 0 deletions openaq_api/openaq_api/v3/routers/owners.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ async def fetch_owners(query, db):
FROM entities e
JOIN sensor_nodes sn ON e.entities_id = sn.owner_entities_id
{query_builder.where()}
AND sn.is_public
GROUP BY e.entities_id, name
ORDER BY e.entities_id
{query_builder.pagination()};
Expand Down
Loading

0 comments on commit 13b8359

Please sign in to comment.