Spaces:
Sleeping
Sleeping
Commit
·
150c5ae
1
Parent(s):
1f47835
feat: add fauna statistics
Browse files- src/app.py +7 -1
- src/{statistics.py → park_statistics.py} +12 -0
src/app.py
CHANGED
|
@@ -7,7 +7,7 @@ import streamlit as st
|
|
| 7 |
from image_preprocessing import get_image_caption, get_images, resize_image
|
| 8 |
import plotly.express as px
|
| 9 |
|
| 10 |
-
from
|
| 11 |
from data_models.sql_connection import get_db_connection
|
| 12 |
from data_models.park_manager import ParkManager
|
| 13 |
from data_models.image_manager import ImageManager
|
|
@@ -94,6 +94,12 @@ def display_stats() -> None:
|
|
| 94 |
df = pd.DataFrame(predictions)
|
| 95 |
st.markdown("## Most common elements")
|
| 96 |
st.plotly_chart(get_plot_from_most_common_elements(df, "built_elements", "elements"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
st.markdown("## Vegetation detection")
|
| 98 |
st.plotly_chart(get_plot_from_most_common_elements(df, "vegetation_detection", "vegetation"))
|
| 99 |
|
|
|
|
| 7 |
from image_preprocessing import get_image_caption, get_images, resize_image
|
| 8 |
import plotly.express as px
|
| 9 |
|
| 10 |
+
from park_statistics import get_plot_from_most_common_elements, aggregate_fauna_elements
|
| 11 |
from data_models.sql_connection import get_db_connection
|
| 12 |
from data_models.park_manager import ParkManager
|
| 13 |
from data_models.image_manager import ImageManager
|
|
|
|
| 94 |
df = pd.DataFrame(predictions)
|
| 95 |
st.markdown("## Most common elements")
|
| 96 |
st.plotly_chart(get_plot_from_most_common_elements(df, "built_elements", "elements"))
|
| 97 |
+
|
| 98 |
+
st.markdown("## Fauna identification")
|
| 99 |
+
fauna_elements = aggregate_fauna_elements(df)
|
| 100 |
+
fauna_elements = pd.DataFrame(fauna_elements.items(), columns=["fauna", "count"])
|
| 101 |
+
st.plotly_chart(px.pie(fauna_elements, names="fauna", values="count", labels={"count": "# Animals", "fauna": "Fauna"}))
|
| 102 |
+
|
| 103 |
st.markdown("## Vegetation detection")
|
| 104 |
st.plotly_chart(get_plot_from_most_common_elements(df, "vegetation_detection", "vegetation"))
|
| 105 |
|
src/{statistics.py → park_statistics.py}
RENAMED
|
@@ -36,3 +36,15 @@ def get_plot_from_most_common_elements(df: pd.DataFrame, column: str, key: str =
|
|
| 36 |
y="count",
|
| 37 |
labels={"count": "# Objects", column: "Built Elements"},
|
| 38 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
y="count",
|
| 37 |
labels={"count": "# Objects", column: "Built Elements"},
|
| 38 |
)
|
| 39 |
+
|
| 40 |
+
def aggregate_fauna_elements(df: pd.DataFrame) -> dict:
|
| 41 |
+
fauna_elements = {}
|
| 42 |
+
fauna = df["fauna_identification"].apply(lambda x: ast.literal_eval(x)["fauna"])
|
| 43 |
+
|
| 44 |
+
for i in range(len(fauna)):
|
| 45 |
+
for element in fauna[i]:
|
| 46 |
+
if element["type"] in fauna_elements:
|
| 47 |
+
fauna_elements[element["type"]] += element["count"]
|
| 48 |
+
else:
|
| 49 |
+
fauna_elements[element["type"]] = element["count"]
|
| 50 |
+
return fauna_elements
|