Skip to content

Commit 60341ef

Browse files
committed
Assistant checkpoint: Added precipitation metric and refactored code structure
Assistant generated file changes: - metrics/examples/weather/ingest_weather.py: Add precipitation and refactor metrics into a list --- User prompt: Can we add 'precipitation' to the weather example.you can find the weather example in metrics/examples/weather/ingest_weather.py You can just add it to the API call like 'temperature_2m, precipitation' and then extract it accordingly. Maybe we can refactor the metrics themselves into a list perhaps. Replit-Commit-Author: Assistant Replit-Commit-Session-Id: e47bd7cc-758f-4fc4-909b-61816b6a3936
1 parent d0546b3 commit 60341ef

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

metrics/examples/weather/ingest_weather.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import pandas as pd
23

34

@@ -8,19 +9,27 @@ def ingest() -> pd.DataFrame:
89

910
import requests
1011

11-
data = {
12-
city: requests.get(
13-
url=f"://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lng}&current=temperature_2m",
12+
# Define cities and their coordinates
13+
cities = [
14+
("dublin", 53.3441, -6.2675),
15+
("athens", 37.9792, 23.7166),
16+
("london", 51.5002, -0.1262),
17+
("berlin", 52.5235, 13.4115),
18+
("paris", 48.8567, 2.3510),
19+
]
20+
21+
# Define metrics to fetch
22+
metrics = ["temperature_2m", "precipitation"]
23+
24+
data = {}
25+
for city, lat, lng in cities:
26+
response = requests.get(
27+
url=f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lng}&current={','.join(metrics)}",
1428
timeout=10,
15-
).json()["current"]["temperature_2m"]
16-
for (city, lat, lng) in [
17-
("dublin", 53.3441, -6.2675),
18-
("athens", 37.9792, 23.7166),
19-
("london", 51.5002, -0.1262),
20-
("berlin", 52.5235, 13.4115),
21-
("paris", 48.8567, 2.3510),
22-
]
23-
}
29+
).json()["current"]
30+
31+
for metric in metrics:
32+
data[f"{city}_{metric}"] = response[metric]
2433

2534
df = pd.DataFrame.from_dict(data, columns=["metric_value"], orient="index")
2635
df["metric_timestamp"] = pd.Timestamp.utcnow()

0 commit comments

Comments
 (0)