up emoji on demo map
This commit is contained in:
parent
65956ff6be
commit
dea71fc6b3
7 changed files with 565 additions and 35 deletions
|
|
@ -66,7 +66,7 @@ class DemoResource:
|
|||
template = self.jinja_env.get_template('edit.html')
|
||||
html = template.render(
|
||||
id=id,
|
||||
event_data=json.dumps(event_data)
|
||||
event_data=event_data
|
||||
)
|
||||
|
||||
# Set the response body and status
|
||||
|
|
@ -404,5 +404,64 @@ class DemoResource:
|
|||
resp.status = falcon.HTTP_500
|
||||
resp.text = f"Error: {str(e)}"
|
||||
|
||||
def on_get_property_stats(self, req, resp):
|
||||
"""
|
||||
Handle GET requests to the /demo/property-stats endpoint.
|
||||
Returns an HTML page with statistics about property occurrences in the last 200 events.
|
||||
|
||||
Args:
|
||||
req: The request object.
|
||||
resp: The response object.
|
||||
"""
|
||||
logger.info("Processing GET request to /demo/property-stats")
|
||||
|
||||
try:
|
||||
# Set content type to HTML
|
||||
resp.content_type = 'text/html'
|
||||
|
||||
# Fetch the last 200 events from the API
|
||||
try:
|
||||
response = requests.get('https://api.openeventdatabase.org/event?limit=200')
|
||||
if response.status_code == 200 and response.text:
|
||||
events_data = response.json()
|
||||
else:
|
||||
logger.error(f"Error fetching events: Status code {response.status_code}")
|
||||
events_data = {"features": []}
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching events: {e}")
|
||||
events_data = {"features": []}
|
||||
|
||||
# Count property occurrences
|
||||
property_counts = {}
|
||||
total_events = len(events_data.get('features', []))
|
||||
|
||||
for feature in events_data.get('features', []):
|
||||
properties = feature.get('properties', {})
|
||||
for prop_name in properties.keys():
|
||||
if prop_name in property_counts:
|
||||
property_counts[prop_name] += 1
|
||||
else:
|
||||
property_counts[prop_name] = 1
|
||||
|
||||
# Sort properties by occurrence count (descending order)
|
||||
sorted_properties = sorted(property_counts.items(), key=lambda x: x[1], reverse=True)
|
||||
|
||||
# Render the template
|
||||
template = self.jinja_env.get_template('property_stats.html')
|
||||
html = template.render(
|
||||
property_stats=sorted_properties,
|
||||
total_events=total_events,
|
||||
unique_properties=len(sorted_properties)
|
||||
)
|
||||
|
||||
# Set the response body and status
|
||||
resp.text = html
|
||||
resp.status = falcon.HTTP_200
|
||||
logger.success("Successfully processed GET request to /demo/property-stats")
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing GET request to /demo/property-stats: {e}")
|
||||
resp.status = falcon.HTTP_500
|
||||
resp.text = f"Error: {str(e)}"
|
||||
|
||||
# Create a global instance of DemoResource
|
||||
demo = DemoResource()
|
||||
Loading…
Add table
Add a link
Reference in a new issue