Spaces:
Sleeping
Sleeping
Edited database stats
Browse files- src/api/main.py +16 -12
src/api/main.py
CHANGED
|
@@ -267,22 +267,20 @@ def get_database_stats():
|
|
| 267 |
unique_blogs = session.query(func.count(func.distinct(Whole_Blogs.blog_url))).scalar()
|
| 268 |
unique_authors = session.query(func.count(func.distinct(Whole_Blogs.page_author))).scalar()
|
| 269 |
|
| 270 |
-
# Top 20 locations
|
| 271 |
-
top_locations = session.query(
|
| 272 |
-
Whole_Blogs.location_name,
|
| 273 |
-
func.count(Whole_Blogs.id).label('count')
|
| 274 |
-
).group_by(Whole_Blogs.location_name)\
|
| 275 |
-
.order_by(func.count(Whole_Blogs.id).desc())\
|
| 276 |
-
.limit(20).all()
|
| 277 |
-
|
| 278 |
# Sample coordinates (limit to 1000 for performance)
|
| 279 |
coordinates = session.query(
|
|
|
|
| 280 |
Whole_Blogs.latitude,
|
| 281 |
-
Whole_Blogs.longitude
|
|
|
|
| 282 |
).filter(
|
| 283 |
Whole_Blogs.latitude.isnot(None),
|
| 284 |
Whole_Blogs.longitude.isnot(None)
|
| 285 |
-
).
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
|
| 287 |
logger.info(f"Stats requested: {total_posts} posts, {unique_locations} locations")
|
| 288 |
|
|
@@ -291,8 +289,14 @@ def get_database_stats():
|
|
| 291 |
"unique_locations": unique_locations,
|
| 292 |
"unique_blogs": unique_blogs,
|
| 293 |
"unique_authors": unique_authors,
|
| 294 |
-
"
|
| 295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
}
|
| 297 |
except Exception as e:
|
| 298 |
logger.error(f"Database stats error: {e}")
|
|
|
|
| 267 |
unique_blogs = session.query(func.count(func.distinct(Whole_Blogs.blog_url))).scalar()
|
| 268 |
unique_authors = session.query(func.count(func.distinct(Whole_Blogs.page_author))).scalar()
|
| 269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
# Sample coordinates (limit to 1000 for performance)
|
| 271 |
coordinates = session.query(
|
| 272 |
+
Whole_Blogs.location_name,
|
| 273 |
Whole_Blogs.latitude,
|
| 274 |
+
Whole_Blogs.longitude,
|
| 275 |
+
func.count(Whole_Blogs.id).label('cnt')
|
| 276 |
).filter(
|
| 277 |
Whole_Blogs.latitude.isnot(None),
|
| 278 |
Whole_Blogs.longitude.isnot(None)
|
| 279 |
+
).group_by(
|
| 280 |
+
Whole_Blogs.location_name,
|
| 281 |
+
Whole_Blogs.latitude,
|
| 282 |
+
Whole_Blogs.longitude
|
| 283 |
+
).all()
|
| 284 |
|
| 285 |
logger.info(f"Stats requested: {total_posts} posts, {unique_locations} locations")
|
| 286 |
|
|
|
|
| 289 |
"unique_locations": unique_locations,
|
| 290 |
"unique_blogs": unique_blogs,
|
| 291 |
"unique_authors": unique_authors,
|
| 292 |
+
"coordinates": [
|
| 293 |
+
{
|
| 294 |
+
"location": loc,
|
| 295 |
+
"lat": float(lat),
|
| 296 |
+
"lon": float(lon),
|
| 297 |
+
"count": cnt
|
| 298 |
+
} for loc, lat, lon, cnt in coordinates
|
| 299 |
+
]
|
| 300 |
}
|
| 301 |
except Exception as e:
|
| 302 |
logger.error(f"Database stats error: {e}")
|