-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Added check for unprocessed points
- Loading branch information
1 parent
b96ddd4
commit 92d37d2
Showing
6 changed files
with
49 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
...eanair/databases/tables/road_point_map.py → ...eanair/databases/tables/point_road_map.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 25 additions & 9 deletions
34
containers/cleanair/cleanair/features/point_road_mapper.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,36 @@ | ||
from Typing import Optional, List, Datetime | ||
from datetime import datetime | ||
from typing import Optional, List | ||
|
||
from sqlalchemy import func | ||
|
||
from ..databases import DBWriter | ||
from ..databases.tables import MetaPoint, RoadPointMap | ||
from ..databases.tables import MetaPoint, PointRoadMap | ||
from ..decorators import db_query | ||
from ..types.enum_types import Source | ||
|
||
|
||
class PointRoadMapper(DBWriter): | ||
|
||
@db_query() | ||
def unprocessed_ids(self, sources: List[Source], datetime: Optional[Datetime]): | ||
def unprocessed_ids(self, sources=None, time=None): | ||
with self.dbcnxn.open_session() as session: | ||
processed_ids_query = session.query(RoadPointMap.point_id) | ||
if datetime: | ||
processed_ids_query = processed_ids_query.filter(RoadPointMap.map_datetime >= datetime) | ||
processed_ids_query = session.query(PointRoadMap.point_id) | ||
if time: | ||
processed_ids_query = processed_ids_query.filter(PointRoadMap.map_datetime >= time) | ||
|
||
return (session.query(MetaPoint.id) | ||
.filter(MetaPoint.id.notin_(processed_ids_query)) | ||
unprocessed_ids_query = session.query(MetaPoint.id) \ | ||
.filter(MetaPoint.id.notin_(processed_ids_query)) | ||
if sources: | ||
unprocessed_ids_query = unprocessed_ids_query \ | ||
.filter(MetaPoint.source in sources) | ||
) | ||
|
||
return unprocessed_ids_query | ||
|
||
@db_query() | ||
def unprocessed_counts(self): | ||
|
||
ids = self.unprocessed_ids().all() | ||
|
||
with self.dbcnxn.open_session() as session: | ||
return session.query(MetaPoint.source, func.count(MetaPoint.id).label("unprocessed")).group_by(MetaPoint.source) | ||
|
3 changes: 2 additions & 1 deletion
3
containers/cleanair/cleanair/parsers/urbanair_parser/processors/main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
"""Processors parser""" | ||
import typer | ||
from . import scoot_forecast_cli | ||
from . import point_road_map_cli | ||
|
||
app = typer.Typer(help="Process urbanair input data into a different format") | ||
app.add_typer(scoot_forecast_cli.app, name="scoot") | ||
app.add_typer(point_road_map_cli.app, name="map") | ||
app.add_typer(point_road_map_cli.app, name="mapping") | ||
|
||
if __name__ == "__main__": | ||
app() |
20 changes: 12 additions & 8 deletions
20
containers/cleanair/cleanair/parsers/urbanair_parser/processors/point_road_map_cli.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
import typer | ||
|
||
from typing import List | ||
|
||
import typer | ||
from cleanair.features import PointRoadMapper | ||
|
||
from ..shared_args import ValidSources, Sources | ||
from ..state import state | ||
|
||
app = typer.Typer() | ||
|
||
|
||
|
||
|
||
|
||
@app.command | ||
@app.command() | ||
def points(source: List[ValidSources] = Sources): | ||
pass | ||
|
||
|
||
# get unprocessed ids | ||
@app.command() | ||
def check() -> None: | ||
map = PointRoadMapper(secretfile=state["secretfile"]) | ||
unprocesed_ids = map.unprocessed_counts(output_type="tabulate") | ||
|
||
# Do intercestion thing | ||
typer.echo(unprocesed_ids) |