Skip to content

Commit

Permalink
Human redable formatting for polygon stats summary
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijrajsharma committed Dec 27, 2023
1 parent 9b406db commit 9e8f7e0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ def get_building_pattern_statement(
osm_building_count,
ai_building_count,
avg_timestamp,
last_edit_timestamp,
osm_building_count_6_months,
):
"""
Expand All @@ -961,20 +962,22 @@ def get_building_pattern_statement(
Args:
osm_building_count (int): Count of buildings from OpenStreetMap.
ai_building_count (int): Count of buildings from AI estimates.
avg_timestamp (str): Average timestamp of data.
avg_timestamp (timestamp): Average timestamp of data.
last_edit_timestamp(timestamp): Last edit timestamp of an area
osm_building_count_6_months (int): Count of buildings updated in the last 6 months.
Returns:
str: Human-readable building statement.
"""
building_statement = f"OpenStreetMap contains roughly {humanize.intword(osm_building_count)} buildings in this region. Based on AI-mapped estimates, this is approximately {round((osm_building_count/ai_building_count)*100)}% of the total buildings. The average age of data for this region is {avg_timestamp} and {round((osm_building_count_6_months/ai_building_count)*100)}% buildings were added or updated in the last 6 months."
building_statement = f"OpenStreetMap contains roughly {humanize.intword(osm_building_count)} buildings in this region. Based on AI-mapped estimates, this is approximately {round((osm_building_count/ai_building_count)*100)}% of the total buildings. The average age of data for this region is {humanize.naturaldate(avg_timestamp)} ( Last edited on {humanize.naturaldate(last_edit_timestamp)} ) and {round((osm_building_count_6_months/ai_building_count)*100)}% buildings were added or updated in the last 6 months."
return building_statement

@staticmethod
def get_road_pattern_statement(
osm_highway_length,
ai_highway_length,
avg_timestamp,
last_edit_timestamp,
osm_highway_length_6_months,
):
"""
Expand All @@ -989,7 +992,7 @@ def get_road_pattern_statement(
Returns:
str: Human-readable road statement.
"""
road_statement = f"OpenStreetMap contains roughly {humanize.intword(osm_highway_length)} km of roads in this region. Based on AI-mapped estimates, this is approximately {round(osm_highway_length/ai_highway_length*100)} % of the total road length in the dataset region. The average age of data for the region is {avg_timestamp}, and {round((osm_highway_length_6_months/osm_highway_length)*100)}% of roads were added or updated in the last 6 months."
road_statement = f"OpenStreetMap contains roughly {humanize.intword(osm_highway_length)} km of roads in this region. Based on AI-mapped estimates, this is approximately {round(osm_highway_length/ai_highway_length*100)} % of the total road length in the dataset region. The average age of data for the region is {humanize.naturaldate(avg_timestamp)} ( Last edited on {humanize.naturaldate(last_edit_timestamp)} ) and {round((osm_highway_length_6_months/osm_highway_length)*100)}% of roads were added or updated in the last 6 months."
return road_statement

def get_osm_analytics_meta_stats(self):
Expand Down Expand Up @@ -1069,13 +1072,15 @@ def get_summary_stats(self):
combined_data["osmBuildingsCount"],
combined_data["aiBuildingsCountEstimation"],
combined_data["averageEditTime"],
combined_data["lastEditTime"],
combined_data["building_count_6_months"],
)

road_summary = self.get_road_pattern_statement(
combined_data["highway_length"],
combined_data["aiRoadCountEstimation"],
combined_data["averageEditTime"],
combined_data["lastEditTime"],
combined_data["highway_length_6_months"],
)

Expand Down

0 comments on commit 9e8f7e0

Please sign in to comment.