Skip to content

Commit

Permalink
daily mean
Browse files Browse the repository at this point in the history
  • Loading branch information
wabinyai committed Nov 26, 2024
1 parent c14792f commit e6544e0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/spatial/models/report_datafetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from configure import Config
import google.generativeai as genai
import logging
from functools import lru_cache


# Configure API keys
Expand All @@ -20,6 +21,7 @@

class DataFetcher:
@staticmethod
@lru_cache(maxsize=128) # Cache up to 128 most recent queries
def fetch_air_quality_data_a(grid_id, start_time, end_time):
token = Config.AIRQO_API_TOKEN
analytics_url = Config.ANALTICS_URL
Expand Down Expand Up @@ -71,8 +73,16 @@ def __init__(self, data):

# Finding the minimum and maximum values
if self.daily_mean_data:
self.daily_min_pm2_5 = min(self.daily_mean_data, key=lambda x: x['pm2_5_calibrated_value'])
self.daily_max_pm2_5 = max(self.daily_mean_data, key=lambda x: x['pm2_5_calibrated_value'])
filtered_data = [
item for item in self.daily_mean_data
if 'pm2_5_calibrated_value' in item and isinstance(item['pm2_5_calibrated_value'], (int, float))
]
if filtered_data:
self.daily_min_pm2_5 = min(filtered_data, key=lambda x: x['pm2_5_calibrated_value'])
self.daily_max_pm2_5 = max(filtered_data, key=lambda x: x['pm2_5_calibrated_value'])
else:
self.daily_min_pm2_5 = None
self.daily_max_pm2_5 = None
else:
self.daily_min_pm2_5 = None
self.daily_max_pm2_5 = None
Expand Down Expand Up @@ -141,6 +151,7 @@ def generate_report_with_gemini(self, audience):
print(f"Error: {e}")
return None
# Generate report with customised prompt
@lru_cache(maxsize=64) # Cache up to 64 most recent reports
def generate_report_with_customised_prompt_gemini(self, custom_prompt):
"""
Generate an air quality report using a customised user-provided prompt.
Expand All @@ -153,6 +164,7 @@ def generate_report_with_customised_prompt_gemini(self, custom_prompt):
f"number of sites or devices or airqo binos: {self.num_sites}. "
f"{self.daily_mean_data}"
f"site mean{self.site_mean_pm}"
f" daily {self.daily_mean_data}"
f"{custom_prompt}"
)
try:
Expand Down

0 comments on commit e6544e0

Please sign in to comment.