From 7cddc651a8d1569797314b68203ecaec5a5abb49 Mon Sep 17 00:00:00 2001 From: popenc Date: Thu, 5 Sep 2024 11:48:14 -0400 Subject: [PATCH] removed unnecessary logging --- celery_tasks.py | 1 - flaskr/db.py | 33 --------------------------------- flaskr/geometry.py | 32 -------------------------------- 3 files changed, 66 deletions(-) diff --git a/celery_tasks.py b/celery_tasks.py index f9b6992..3ce42ee 100644 --- a/celery_tasks.py +++ b/celery_tasks.py @@ -131,7 +131,6 @@ def __init__(self): # self.cyano_request_timeout = 30 # seconds def test_celery(self): - logging.warning("CALLING CELERY TASK") celery_job = test_celery.apply_async(queue="celery") return {"status": "test celery called"} diff --git a/flaskr/db.py b/flaskr/db.py index 7ff6ba9..48f6200 100644 --- a/flaskr/db.py +++ b/flaskr/db.py @@ -180,10 +180,8 @@ def get_waterbody_fid(objectid: int): conn = sqlite3.connect(DB_FILE) cur = conn.cursor() query = "SELECT FID FROM WaterbodyBounds WHERE OBJECTID==?" - # logging.warning("Running query: {}".format(query)) cur.execute(query, (int(objectid),)) fid = cur.fetchall() - # logging.warning("fid: {}".format(fid)) if len(fid) == 0: return None return fid[0][0] @@ -191,28 +189,18 @@ def get_waterbody_fid(objectid: int): def get_waterbody_bypoint(lat: float, lng: float, return_fid: bool=False): - logging.warning("get_waterbody_bypoint() called") - conn = sqlite3.connect(DB_FILE) cur = conn.cursor() query = "SELECT OBJECTID, FID FROM WaterbodyBounds WHERE y_max>=? AND x_min<=? AND y_min<=? AND x_max>=?" values = (lat, lng, lat, lng,) - logging.warning("Executing query: {}".format(query)) - cur.execute(query, values) lakes = cur.fetchall() - logging.warning("LAKES: {}".format(lakes)) - crs = None if len(lakes) > 0: features = [] for lake in lakes: - - logging.warning("Lake: {}".format(lake)) - - # w = get_waterbody(int(lake[0])) w = get_waterbody_by_fids(fid=lake[1]) features.append(w[0][0]) crs = w[1] @@ -222,54 +210,33 @@ def get_waterbody_bypoint(lat: float, lng: float, return_fid: bool=False): objectid = None gnis_name = None - logging.warning("Getting point with geopandas. lng: {}, lat: {}, wb[1]: {}".format(lng, lat, wb[1])) out_proj = Proj(wb[1]) - logging.warning("out_proj: {}".format(out_proj)) _lng, _lat = out_proj(lng, lat) - logging.warning("_lat: {}, _lng: {}".format(_lat, _lng)) point = gpd.GeoSeries(Point(_lng, _lat), crs=wb[1]) - logging.warning("point: {}".format(point)) for features in wb[0]: - logging.warning("Looping features: {}".format(features)) - if features["geometry"]["type"] == "MultiPolygon": poly_geos = [] - logging.warning("Geometry type is MultiPolygon") - for p in features["geometry"]["coordinates"]: - logging.warning("~~~ p: {}".format(p)) poly_geos.append(Polygon(p[0])) - logging.warning("Setting poly") poly = gpd.GeoSeries(MultiPolygon(poly_geos), crs=wb[1]) - logging.warning("Poly: {}".format(poly)) else: - logging.warning("Geometry type is not MultiPolygon") poly = gpd.GeoSeries(Polygon(features["geometry"]["coordinates"][0]), crs=wb[1]) - logging.warning("Poly: {}".format(poly)) in_wb = poly.contains(point) - logging.warning("in_wb: {}".format(in_wb)) if in_wb.loc[0]: objectid = features["properties"]["OBJECTID"] gnis_name = features["properties"]["GNIS_NAME"] - - logging.warning("ObjectID: {}, gnis_name: {}".format(objectid, gnis_name)) - break conn.close() - logging.warning("Db connection closed.") - if return_fid and objectid is not None: - logging.warning("Returning objectid and running get_waterbody_fid()") return objectid, get_waterbody_fid(objectid), gnis_name else: - logging.warning("Returning objectid, None, gnis_name") return objectid, None, gnis_name diff --git a/flaskr/geometry.py b/flaskr/geometry.py index 156d5a7..4d29cf1 100644 --- a/flaskr/geometry.py +++ b/flaskr/geometry.py @@ -11,7 +11,6 @@ import numpy as np from shapely.geometry import Polygon, MultiPolygon, Point from pyproj import Proj, transform -import logging import time @@ -39,33 +38,20 @@ def get_waterbody_by_fids(fid: int = None, fids: list = None, tojson: bool = Fal features = [] names = {} - # logging.warning("get_waterbody_by_fids() called") - if fid is None and fids is None: - logging.warning("fid is None and fids is None, returning features: {}".format(features)) return features if tojson: - # logging.warning("Opening WATERBODY_DBF") with fiona.open(WATERBODY_DBF) as waterbodies: - logging.warning("waterbodies: {}".format(waterbodies)) crs = waterbodies.crs - # logging.warning("crs: {}".format(crs)) if fid is not None: - # logging.warning("getting fid") f = waterbodies.get(fid) - # logging.warning("f: {}".format(f)) features.append(f) if fids is not None: - # logging.warning("getting fids") for _fid in fids: - # logging.warning("fid: {}".format(_fid)) f = waterbodies.get(_fid) - # logging.warning("f: {}".format(f)) features.append(f) - # logging.warning("features: {}".format(features)) geojson = [] for feature in features: - # logging.warning("Looping feature: {}".format(feature)) if feature["geometry"]["type"] == "MultiPolygon": poly_geos = [] for p in feature["geometry"]["coordinates"]: @@ -76,29 +62,20 @@ def get_waterbody_by_fids(fid: int = None, fids: list = None, tojson: bool = Fal geojson.append(poly.to_json()) return geojson else: - # logging.warning("geometry.py get_waterbody_by_fids else") with fiona.open(WATERBODY_DBF) as waterbodies: - # logging.warning("Opened WATERBODY_DBF as waterbodies, fid: {}".format(fid)) crs = waterbodies.crs if fid is not None: - # logging.warning("Getting waterbody with fid: {}".format(fid)) f = waterbodies.get(fid) - # logging.warning("Found waterbody with fid: {}".format(f)) features.append(f) names[int(f["properties"]["OBJECTID"])] = f["properties"]["GNIS_NAME"] if fids is not None: - # logging.warning("Getting waterbody with FIDS") for _fid in fids: - # logging.warning("Getting WB with _fid: {}".format(_fid)) f = waterbodies.get(_fid) - # logging.warning("Found: {}".format(f)) features.append(f) names[int(f["properties"]["OBJECTID"])] = f["properties"]["GNIS_NAME"] if name_only: - # logging.warning("Returning name only") return names - # logging.warning("Returning features: {}\ncrs: {}".format(features, crs)) return features, crs @@ -176,16 +153,13 @@ def get_waterbody_byname(gnis_name: str): def get_waterbody_byID(id: int, fid: int = None): - logging.warning("inside get_waterbody_byID, id: {}, fid: {}".format(id, fid)) if id is None and fid is None: return {} waterbody = [] t0 = time.time() if not fid: - logging.warning("No fid Opening WATERBODY_DBF") with fiona.open(WATERBODY_DBF) as waterbodies: for f in waterbodies: - logging.warning("Waterbody: {}".format(f)) if id == int(f["properties"]["OBJECTID"]): wb = { "name": f["properties"]["GNIS_NAME"], @@ -198,12 +172,8 @@ def get_waterbody_byID(id: int, fid: int = None): waterbody = [wb] break else: - logging.warning("with fid Opening WATERBODY_DBF") with fiona.open(WATERBODY_DBF) as waterbodies: f = waterbodies.get(fid) - logging.warning("waterbodies: {}".format(f)) - logging.warning("Id: {}".format(id)) - logging.warning('f["properties"]["OBJECTID"]: {}'.format(f["properties"]["OBJECTID"])) if int(f["properties"]["OBJECTID"]) == id: wb = { "name": f["properties"]["GNIS_NAME"], @@ -213,10 +183,8 @@ def get_waterbody_byID(id: int, fid: int = None): "areasqkm": float(f["properties"]["AREASQKM"]), "state_abbr": f["properties"]["STATE_ABBR"] } - logging.warning("Found wb: {}".format(wb)) waterbody = [wb] else: - logging.warning("Trying to run get_waterbody_byID again.") return get_waterbody_byID(id=id) t1 = time.time() print(f"Search runtime: {round(t1 - t0, 3)} sec")