Skip to content

Commit eeecca1

Browse files
committed
ADD example of an api call
1 parent 5b94d56 commit eeecca1

74 files changed

Lines changed: 60 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,66 @@ def all_data_from_wisconet_query(
206206
raise HTTPException(status_code=500, detail=f"Internal server error: {e}")
207207

208208

209+
@app.get("/ag_models_wrappers/wisconet_g")
210+
def wisconet_geojson_grouped(
211+
forecasting_date: str,
212+
risk_days: int = 1,
213+
station_id: str = None
214+
):
215+
try:
216+
df = retrieve(
217+
input_date=forecasting_date,
218+
input_station_id=station_id,
219+
days=risk_days
220+
)
221+
222+
if df is None or len(df) == 0:
223+
return {"type": "FeatureCollection", "features": []}
224+
225+
df = df.replace([np.inf, -np.inf, np.nan], None)
226+
227+
features = []
228+
229+
for station, group in df.groupby("station_id"):
230+
231+
first_row = group.iloc[0]
232+
233+
lat = first_row["latitude"]
234+
lon = first_row["longitude"]
235+
236+
# Build time series list
237+
time_series = group.drop(
238+
columns=["latitude", "longitude"]
239+
).to_dict(orient="records")
240+
241+
feature = {
242+
"type": "Feature",
243+
"geometry": {
244+
"type": "Point",
245+
"coordinates": [lon, lat]
246+
},
247+
"properties": {
248+
"station_id": station,
249+
"station_name": first_row["station_name"],
250+
"city": first_row["city"],
251+
"county": first_row["county"],
252+
"region": first_row["region"],
253+
"state": first_row["state"],
254+
"time_series": time_series
255+
}
256+
}
257+
258+
features.append(feature)
259+
260+
return {
261+
"type": "FeatureCollection",
262+
"features": features
263+
}
264+
265+
except Exception as e:
266+
raise HTTPException(status_code=500, detail=str(e))
267+
268+
209269
@app.get("/")
210270
def read_root():
211271
return {"message": "Welcome to the Wisconsin Weather API"}
1.36 KB
Binary file not shown.
1.36 KB
Binary file not shown.
1.36 KB
Binary file not shown.
1.36 KB
Binary file not shown.
1.36 KB
Binary file not shown.
1.36 KB
Binary file not shown.
1.36 KB
Binary file not shown.
1.36 KB
Binary file not shown.
1.36 KB
Binary file not shown.

0 commit comments

Comments
 (0)