Last active
March 2, 2023 10:04
-
-
Save tomas-quix/818e07ae8df843aadbe72e1e64c5cb66 to your computer and use it in GitHub Desktop.
OSS Announcement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Callback triggered for each new data frame. | |
def on_data_frame_handler(topic, stream: StreamConsumer, df: pd.DataFrame): | |
# We filter rows where the driver was speeding. | |
above_speed_limit = df[df["speed"] > 130] | |
# If there is a record of speeding, we sent a ticket. | |
if df.shape[0] > O: | |
# We find the moment with the highest speed. | |
max_speed_moment = df['speed'].idxmax() | |
speed = df.loc[max_speed_moment] | |
time = df.loc[max_speed_moment]["time"] | |
# We create a document that will be consumed by the ticket service. | |
speeding_ticket = { | |
'vehicle': stream.stream_id, | |
'time': time, | |
'speed': speed, | |
'fine': (speed - 130) * 100, | |
'photo_proof': df.loc[max_speed_moment]["camera_frame"] | |
} | |
topic_producer.get_or_create_stream(stream.stream_id) \ | |
.events \ | |
.add_timestamp_in_nanoseconds(time) \ | |
.add_value("ticket", json.dumps(speeding_ticket)) \ | |
.publish() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment