leo-bourrel commited on
Commit
b151c5c
·
1 Parent(s): 4029b73

feat: show park stats

Browse files
src/app.py CHANGED
@@ -80,12 +80,18 @@ def sidebar() -> dict | None:
80
  )
81
 
82
 
 
 
 
 
 
 
83
  def main() -> None:
84
  """Main function to run the app"""
85
  park = sidebar()
86
  if not park:
87
- st.write("Please select a park")
88
- return
89
 
90
  images = get_park_images(park["id"])
91
  predictions = get_image_predictions(images)
 
80
  )
81
 
82
 
83
+ def display_stats() -> None:
84
+ """Display statistics about the images"""
85
+ st.title("Statistics")
86
+ st.write("Number of images: ", image_manager.get_image_count())
87
+ st.write("Number of parks: ", park_manager.get_park_count())
88
+
89
  def main() -> None:
90
  """Main function to run the app"""
91
  park = sidebar()
92
  if not park:
93
+ display_stats()
94
+ st.stop()
95
 
96
  images = get_park_images(park["id"])
97
  predictions = get_image_predictions(images)
src/data_models/image_manager.py CHANGED
@@ -95,3 +95,16 @@ class ImageManager:
95
  def close_connection(self):
96
  """Close the connection."""
97
  self.session.close()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  def close_connection(self):
96
  """Close the connection."""
97
  self.session.close()
98
+
99
+ def get_image_count(self):
100
+ """
101
+ Get the number of images in the `images` table.
102
+ Returns:
103
+ int: Number of images.
104
+ """
105
+ query = text("SELECT COUNT(*) FROM images")
106
+ try:
107
+ result = self.session.execute(query).fetchone()
108
+ return result[0]
109
+ except Exception as e:
110
+ raise Exception(f"An error occurred while getting the image count: {e}")
src/data_models/park_manager.py CHANGED
@@ -75,3 +75,12 @@ class ParkManager:
75
  def close_connection(self):
76
  """Close the connection."""
77
  self.session.close()
 
 
 
 
 
 
 
 
 
 
75
  def close_connection(self):
76
  """Close the connection."""
77
  self.session.close()
78
+
79
+ def get_park_count(self):
80
+ """Get the number of parks in the database."""
81
+ query = text("SELECT COUNT(*) FROM parks")
82
+ try:
83
+ result = self.session.execute(query).fetchone()
84
+ return result[0]
85
+ except Exception as e:
86
+ raise Exception(f"An error occurred while getting the park count: {e}")