Skip to content

Commit

Permalink
refactor: update rootdir refs to variables
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Oct 9, 2023
1 parent 9d39ad5 commit 694961d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
22 changes: 10 additions & 12 deletions osm_fieldwork/filter_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@
from geojson import Feature, FeatureCollection
from osm_rawdata.config import QueryConfig

# Find the other files for this project
import osm_fieldwork as of
# from osm_fieldwork import package_root
# from osm_fieldwork.data_models import data_models_path
from osm_fieldwork.xlsforms import xlsforms_path

rootdir = of.__path__[0]

# Instantiate logger
log = logging.getLogger(__name__)

Expand Down Expand Up @@ -157,27 +155,27 @@ def cleanData(
for feature in indata["features"]:
log.debug(f"FIXME0: {feature}")
properties = dict()
for key, value in feature['properties'].items():
for key, value in feature["properties"].items():
# log.debug(f"{key} = {value}")
# FIXME: this is a hack!
if True:
if key == 'tags':
if key == "tags":
for k, v in value.items():
if k[:4] == "name":
properties["title"] = value[k]
properties["label"] = value[k]
else:
properties[k] = v
else:
if key == 'osm_id':
properties['id'] = value
properties['title'] = value
properties['label'] = value
if key == "osm_id":
properties["id"] = value
properties["title"] = value
properties["label"] = value
else:
properties[key] = value
if key[:4] == "name":
properties['title'] = value
properties['label'] = value
properties["title"] = value
properties["label"] = value
else:
log.debug(f"FIXME2: {key} = {value}")
if key in keep:
Expand Down
15 changes: 6 additions & 9 deletions osm_fieldwork/make_data_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@
from osm_rawdata.postgres import PostgresClient
from shapely.geometry import shape

from osm_fieldwork.data_models import data_models_path
from osm_fieldwork.filter_data import FilterData
from osm_fieldwork.xlsforms import xlsforms_path

# Instantiate logger
log = logging.getLogger(__name__)

# Find the other files for this project
import osm_fieldwork as of

rootdir = of.__path__[0]


def getChoices():
"""Get the categories and associated XLSFiles from the config file.
Expand All @@ -48,8 +45,8 @@ def getChoices():
(list): A list of the XLSForms included in osm-fieldwork
"""
data = dict()
if os.path.exists(f"{rootdir}/data_models/category.yaml"):
file = open(f"{rootdir}/data_models/category.yaml", "r").read()
if os.path.exists(f"{data_models_path}/category.yaml"):
file = open(f"{data_models_path}/category.yaml", "r").read()
contents = yaml.load(file, Loader=yaml.Loader)
for entry in contents:
[[k, v]] = entry.items()
Expand All @@ -76,13 +73,13 @@ def __init__(
Returns:
(MakeExtract): An instance of this object
"""
self.db = PostgresClient(dburi, f"{rootdir}/data_models/{config}")
self.db = PostgresClient(dburi, f"{data_models_path}/{config}")

# Read in the XLSFile
if "/" in xlsfile:
file = open(xlsfile, "rb")
else:
file = open(f"{rootdir}/xlsforms/{xlsfile}", 'rb')
file = open(f"{xlsforms_path}/{xlsfile}", "rb")
self.xls = BytesIO(file.read())

def getFeatures(
Expand Down
8 changes: 2 additions & 6 deletions osm_fieldwork/odk_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,12 @@
from thefuzz import fuzz

from osm_fieldwork.convert import escape
from osm_fieldwork.data_models import data_models_path
from osm_fieldwork.osmfile import OsmFile

# Instantiate logger
log = logging.getLogger(__name__)

# Find the other files for this project
import osm_fieldwork as of

rootdir = of.__path__[0]

# The number of threads is based on the CPU cores
info = get_cpu_info()
cores = info["count"]
Expand Down Expand Up @@ -76,7 +72,7 @@ def __init__(
# self.source = "underpass" is not support yet
# Each thread needs it's own connection to postgres to avoid problems.
for _thread in range(0, cores + 1):
db = PostgresClient(uri, f"{rootdir}/data_models/{config}")
db = PostgresClient(uri, f"{data_models_path}/{config}")
self.postgres.append(db)
if boundary:
self.clip(boundary, db)
Expand Down

0 comments on commit 694961d

Please sign in to comment.