Untitled
unknown
python
10 months ago
1.9 kB
16
Indexable
def test_pipeline():
station_code = 30272
temperature_module_id = 5013
humidity_module_id = 5012
wind_module_id = 5011
collection = get_measures_collection(station_code) # type: ignore
pipeline = [
{
"$match": {
"date": {"$gte": datetime(2025, 1, 1), "$lte": datetime(2025, 1, 31)},
},
},
{
"$group": {
"_id": {
"$dateToString": {
"date": "$date",
"format": "%Y-%m-%d",
}
},
f"temp_avg": {"$avg": f"${temperature_module_id}"},
f"temp_min": {"$min": f"${temperature_module_id}"},
f"temp_max": {"$max": f"${temperature_module_id}"},
f"hum_avg": {"$avg": f"${humidity_module_id}"},
f"hum_min": {"$min": f"${humidity_module_id}"},
f"hum_max": {"$max": f"${humidity_module_id}"},
f"wind_avg": {"$avg": f"${wind_module_id}"},
f"wind_min": {"$min": f"${wind_module_id}"},
f"wind_max": {"$max": f"${wind_module_id}"},
}
},
{
"$project": {
"_id": 0,
"date": {
"$dateFromString": {
"dateString": "$_id",
"format": "%Y-%m-%d",
}
},
"temp_avg": 1,
"temp_min": 1,
"temp_max": 1,
"hum_avg": 1,
"hum_min": 1,
"hum_max": 1,
"wind_avg": 1,
"wind_min": 1,
"wind_max": 1,
}
},
]
result = collection.aggregate(pipeline)
for document in result:
day = document["date"]
temperature_average = document["temp_avg"]Editor is loading...
Leave a Comment