Skip to content

Commit

Permalink
+ Black code linting
Browse files Browse the repository at this point in the history
  • Loading branch information
emi420 committed Nov 4, 2024
1 parent 5ed27a6 commit 5eaee14
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 36 deletions.
8 changes: 7 additions & 1 deletion API/api_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ def create_readme_content(default_readme, polygon_stats):


def zip_binding(
working_dir, exportname_parts, geom_dump, polygon_stats, geojson_stats, default_readme
working_dir,
exportname_parts,
geom_dump,
polygon_stats,
geojson_stats,
default_readme,
):
logging.debug("Zip Binding Started!")
upload_file_path = os.path.join(
Expand Down Expand Up @@ -168,6 +173,7 @@ def on_failure(self, exc, task_id, args, kwargs, einfo):
if os.path.exists(clean_dir):
shutil.rmtree(clean_dir)


@celery.task(
bind=True,
name="process_raw_data",
Expand Down
11 changes: 8 additions & 3 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ def ogr_export(query, outputtype, working_dir, dump_temp_path, params):
os.remove(query_path)

@staticmethod
def query2geojson(con, extraction_query, dump_temp_file_path, plugin_fn = None):
def query2geojson(con, extraction_query, dump_temp_file_path, plugin_fn=None):
"""Function written from scratch without being dependent on any library, Provides better performance for geojson binding"""
# creating geojson file
pre_geojson = """{"type": "FeatureCollection","features": ["""
Expand Down Expand Up @@ -714,7 +714,7 @@ def get_grid_id(geom, cur):
country_export,
)

def extract_current_data(self, exportname, plugin_fn = None):
def extract_current_data(self, exportname, plugin_fn=None):
"""Responsible for Extracting rawdata current snapshot, Initially it creates a geojson file , Generates query , run it with 1000 chunk size and writes it directly to the geojson file and closes the file after dump
Args:
exportname: takes filename as argument to create geojson file passed from routers
Expand Down Expand Up @@ -780,7 +780,7 @@ def extract_current_data(self, exportname, plugin_fn = None):
country_export=country_export,
),
dump_temp_file_path,
plugin_fn
plugin_fn,
) # uses own conversion class
if output_type == RawDataOutputType.SHAPEFILE.value:
(
Expand Down Expand Up @@ -2260,6 +2260,7 @@ def get_summary_stats(self, start_date, end_date, group_by):
self.d_b.close_conn()
return [dict(item) for item in result]


class GeoJSONStats(Stats):
"""Used for collecting stats while processing GeoJSON files line by line"""

Expand Down Expand Up @@ -2305,6 +2306,10 @@ def check_filter(self, tags, tag):
if tags.line.join_and and tag in tags.line.join_and:
return True

"""
Process a GeoJSON line (for getting stats) and return that line
"""

def raw_data_line_stats(self, line: str):
self.process_file_line(line)
return line
64 changes: 32 additions & 32 deletions src/validation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,22 +303,22 @@ class StatsRequestParams(BaseModel, GeometryValidatorMixin):
max_length=3,
example="NPL",
)
geometry: Optional[
Union[Polygon, MultiPolygon, Feature, FeatureCollection]
] = Field(
default=None,
example={
"type": "Polygon",
"coordinates": [
[
[83.96919250488281, 28.194446860487773],
[83.99751663208006, 28.194446860487773],
[83.99751663208006, 28.214869548073377],
[83.96919250488281, 28.214869548073377],
[83.96919250488281, 28.194446860487773],
]
],
},
geometry: Optional[Union[Polygon, MultiPolygon, Feature, FeatureCollection]] = (
Field(
default=None,
example={
"type": "Polygon",
"coordinates": [
[
[83.96919250488281, 28.194446860487773],
[83.99751663208006, 28.194446860487773],
[83.99751663208006, 28.214869548073377],
[83.96919250488281, 28.214869548073377],
[83.96919250488281, 28.194446860487773],
]
],
},
)
)

@validator("geometry", pre=True, always=True)
Expand Down Expand Up @@ -624,22 +624,22 @@ class DynamicCategoriesModel(CategoriesBase, GeometryValidatorMixin):
max_length=3,
example="USA",
)
geometry: Optional[
Union[Polygon, MultiPolygon, Feature, FeatureCollection]
] = Field(
default=None,
example={
"type": "Polygon",
"coordinates": [
[
[83.96919250488281, 28.194446860487773],
[83.99751663208006, 28.194446860487773],
[83.99751663208006, 28.214869548073377],
[83.96919250488281, 28.214869548073377],
[83.96919250488281, 28.194446860487773],
]
],
},
geometry: Optional[Union[Polygon, MultiPolygon, Feature, FeatureCollection]] = (
Field(
default=None,
example={
"type": "Polygon",
"coordinates": [
[
[83.96919250488281, 28.194446860487773],
[83.99751663208006, 28.194446860487773],
[83.99751663208006, 28.214869548073377],
[83.96919250488281, 28.214869548073377],
[83.96919250488281, 28.194446860487773],
]
],
},
)
)

@validator("geometry", pre=True, always=True)
Expand Down

0 comments on commit 5eaee14

Please sign in to comment.