Spaces:
Build error
Build error
Ronio Jerico Roque commited on
Commit ·
2541290
1
Parent(s): e77d7d8
Add clear_collection function and integrate delete button in DigitalFootprintDashboard
Browse files- helper/telemetry.py +20 -0
- pages/home.py +9 -1
helper/telemetry.py
CHANGED
|
@@ -39,3 +39,23 @@ def collect_telemetry(data):
|
|
| 39 |
print(f"Error sending data to MongoDB: {e}")
|
| 40 |
finally:
|
| 41 |
client.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
print(f"Error sending data to MongoDB: {e}")
|
| 40 |
finally:
|
| 41 |
client.close()
|
| 42 |
+
|
| 43 |
+
def clear_collection(data):
|
| 44 |
+
"""
|
| 45 |
+
Deletes all documents from a specified MongoDB collection.
|
| 46 |
+
"""
|
| 47 |
+
mongodb_uri = os.getenv("MONGODB_URI")
|
| 48 |
+
if not mongodb_uri:
|
| 49 |
+
print("Deletion skipped: No database configured.")
|
| 50 |
+
return
|
| 51 |
+
|
| 52 |
+
try:
|
| 53 |
+
client = MongoClient(mongodb_uri)
|
| 54 |
+
db = client.get_default_database()
|
| 55 |
+
collection = db[f"{data}"] # Replace with your collection name
|
| 56 |
+
result = collection.delete_many({})
|
| 57 |
+
print(f"Deleted {result.deleted_count} documents from the collection.")
|
| 58 |
+
except Exception as e:
|
| 59 |
+
print(f"Error deleting documents: {e}")
|
| 60 |
+
finally:
|
| 61 |
+
client.close()
|
pages/home.py
CHANGED
|
@@ -21,6 +21,7 @@ from classes.amazon import Amazon
|
|
| 21 |
from classes.ebay import eBay
|
| 22 |
import asyncio
|
| 23 |
from helper.upload_button import hide_button, unhide_button
|
|
|
|
| 24 |
import time
|
| 25 |
|
| 26 |
class DigitalFootprintDashboard:
|
|
@@ -131,6 +132,12 @@ class DigitalFootprintDashboard:
|
|
| 131 |
self.content = Content(os.getenv('Model_Content'))
|
| 132 |
return col1, col2, col3, col4
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
async def run_analysis(self):
|
| 135 |
result = await asyncio.gather(
|
| 136 |
self.gtmetrix.process(),
|
|
@@ -144,11 +151,12 @@ class DigitalFootprintDashboard:
|
|
| 144 |
self.tiktok.process(),
|
| 145 |
)
|
| 146 |
st.session_state.analyze = False
|
| 147 |
-
|
| 148 |
async def main(self):
|
| 149 |
"""Main method to run the dashboard"""
|
| 150 |
await self.create_row1()
|
| 151 |
await self.create_row2()
|
|
|
|
| 152 |
#self.run_analysis()
|
| 153 |
|
| 154 |
# Main execution
|
|
|
|
| 21 |
from classes.ebay import eBay
|
| 22 |
import asyncio
|
| 23 |
from helper.upload_button import hide_button, unhide_button
|
| 24 |
+
from helper.telemetry import clear_collection
|
| 25 |
import time
|
| 26 |
|
| 27 |
class DigitalFootprintDashboard:
|
|
|
|
| 132 |
self.content = Content(os.getenv('Model_Content'))
|
| 133 |
return col1, col2, col3, col4
|
| 134 |
|
| 135 |
+
async def delete_button(self):
|
| 136 |
+
reset_button = st.button("RESET ALL",icon="🗑️", use_container_width=True)
|
| 137 |
+
|
| 138 |
+
if reset_button:
|
| 139 |
+
clear_collection("telemetry")
|
| 140 |
+
|
| 141 |
async def run_analysis(self):
|
| 142 |
result = await asyncio.gather(
|
| 143 |
self.gtmetrix.process(),
|
|
|
|
| 151 |
self.tiktok.process(),
|
| 152 |
)
|
| 153 |
st.session_state.analyze = False
|
| 154 |
+
|
| 155 |
async def main(self):
|
| 156 |
"""Main method to run the dashboard"""
|
| 157 |
await self.create_row1()
|
| 158 |
await self.create_row2()
|
| 159 |
+
await self.delete_button()
|
| 160 |
#self.run_analysis()
|
| 161 |
|
| 162 |
# Main execution
|