Commit 44b2d097 authored by Marius Kriegerowski's avatar Marius Kriegerowski
Browse files

Added optional verbose logging mode

parent 47d8fab8
Pipeline #25353 passed with stage
in 1 minute and 37 seconds
......@@ -19,6 +19,7 @@
import logging
import sys
import asyncio
import argparse
from rabotnik import Rabotnik
from rabotnik.bus import MessageBus
......@@ -32,9 +33,8 @@ rabotnik_logger = logging.getLogger("rabotnik")
rabotnik_logger.setLevel(logging.DEBUG)
rabotnik_logger.addHandler(logging.StreamHandler(sys.stdout))
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler(sys.stdout))
logger = logging.getLogger("rabotnikobm")
# Initiate the rabotnik
rabotnik = Rabotnik("rabotnik-obm")
......@@ -70,6 +70,25 @@ async def main():
await message_bus.subscribe("building", rule.evaluate)
loop = asyncio.get_event_loop()
loop.create_task(main())
loop.run_forever()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", help="verbose mode", action="store_true")
args = parser.parse_args()
if args.verbose:
log_level = logging.DEBUG
else:
log_level = logging.INFO
logger.setLevel(log_level)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)
loop = asyncio.get_event_loop()
loop.create_task(main())
loop.run_forever()
......@@ -20,7 +20,7 @@ import logging
from rabotnik import Rule
logger = logging.getLogger()
logger = logging.getLogger(__name__)
class GetBuilding(Rule):
......@@ -32,8 +32,7 @@ class GetBuilding(Rule):
async def evaluate(self, payload: dict):
building_id = payload["building_id"]
logger.debug("Processing building: %s", building_id)
logger.debug("evaluating %s", building_id)
table_from = "osm_building_polygons"
table_to = "obm_buildings"
......
......@@ -15,12 +15,15 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
import logging
from typing import Tuple, Iterator
from rabotnik import Rule
logger = logging.getLogger(__name__)
class GetBuildingLandUse(Rule):
"""A rule to get the land use of a building."""
......@@ -29,6 +32,7 @@ class GetBuildingLandUse(Rule):
async def evaluate(self, payload: dict) -> Iterator[Tuple[int]]:
building_id = payload["building_id"]
logger.debug("evaluating %s", building_id)
async for land_use in self.storage.iter_results(
f"""SELECT land.class
......
......@@ -4,7 +4,7 @@ import logging
from rabotnik.storages.base import StorageBase as RabotnikStorage
from rabotnik import Rule # pylint: disable=import-error
logger = logging.getLogger()
logger = logging.getLogger(__name__)
class GetFloorspace(Rule):
......@@ -20,6 +20,7 @@ class GetFloorspace(Rule):
async def evaluate(self, payload: dict) -> None:
building_id = payload["building_id"]
logger.debug("evaluating %s", building_id)
query_data = f"""
SELECT ST_Area(ST_Transform(geometry, 4326)) *
......
......@@ -15,11 +15,13 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
import logging
from typing import Tuple, Iterator
from rabotnik import Rule
logger = logging.getLogger(__name__)
class GetPointsInBuilding(Rule):
"""A rule to get the number of points within a building."""
......@@ -29,6 +31,7 @@ class GetPointsInBuilding(Rule):
async def evaluate(self, payload: dict) -> Iterator[Tuple[int]]:
building_id = payload["building_id"]
logger.debug("evaluating %s", building_id)
async for n_points, _ in self.storage.iter_results(
f"""SELECT COUNT(ST_NPOINTS(spots.geometry)), buildings.osm_id
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment