-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream_processing.py
49 lines (34 loc) · 1.19 KB
/
stream_processing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from quixstreams import Application, State
import datetime
def process_weather(msg, state: State):
# time_stamp = msg["current"]["time"]
time_stamp = str(datetime.datetime.now().replace(microsecond=0))
is_day = msg["current"]["is_day"]
wind_speed = msg["current"]["wind_speed_10m"]
cloud_cover_percentage = msg["current"]["cloud_cover"]
celcius = msg["current"]["temperature_2m"]
# if time_stamp.split()[1].split(':')[0] == "24":
# solar_power_w_accumulated = 0
new_msg = {
"time_stamp" : time_stamp,
"celcius" : celcius,
"wind_speed" : wind_speed,
"cloud_cover_percentage" : cloud_cover_percentage,
"is_day" : is_day
}
return new_msg
def main():
app = Application(
broker_address = "localhost:9092",
loglevel = "DEBUG",
auto_offset_reset = "earliest",
consumer_group = "weather_processor",
)
input_topic = app.topic("weather_data")
output_topic = app.topic("weather_processed")
sdf = app.dataframe(input_topic)
sdf = sdf.apply(process_weather, stateful=True)
sdf = sdf.to_topic(output_topic)
app.run(sdf)
if __name__ == "__main__":
main()