Skip to content

Commit

Permalink
Add another example (event count per dataset)
Browse files Browse the repository at this point in the history
  • Loading branch information
aMarcireau committed Oct 9, 2023
1 parent 5e222b1 commit 0e5977b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions python/examples/map_count_events_per_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import undr


def handle_dvs(file: undr.DvsFile, send_message: undr.SendMessage):
file_total = 0
for packet in file.packets():
file_total += len(packet)
send_message(
{
"dataset_name": file.path_id.parts[0],
"file_total": file_total,
}
)


if __name__ == "__main__":
configuration = undr.configuration_from_path("undr.toml")
dataset_name_to_total = {
dataset_name: 0
for dataset_name in configuration.name_to_dataset_settings.keys()
}
for message in configuration.map(switch=undr.Switch(handle_dvs=handle_dvs)):
dataset_name_to_total[message["dataset_name"]] += message["file_total"]
for dataset_name, total in dataset_name_to_total:
print(f"{dataset_name}: {total}")

0 comments on commit 0e5977b

Please sign in to comment.