-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
74 lines (65 loc) · 2.68 KB
/
run.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import time
t_start = time.time()
from pathlib import Path
from argparse import ArgumentParser
from PyQt6.QtWidgets import QApplication
from snitchvis import (SnitchvisApp, SnitchVisRecord, parse_events,
parse_snitches, create_users, snitches_from_events, Config)
parser = ArgumentParser()
parser.add_argument("-a", "--all-snitches", help="show all snitches in the "
"visualization, even those which weren't pinged", action="store_true",
default=False)
parser.add_argument("-i", "--input", help="event file input to parse",
required=True)
parser.add_argument("-s", "--snitch-db", help="snitch database (.sqlite) file "
"to parse", required=True)
parser.add_argument("-r", "--record", help="record and output to a file "
"instead of showing an interactive QApplication", default=False,
action="store_true")
parser.add_argument("-p", "--pixels", help="width and height of the generated "
"video, in pixels", default=500, type=int)
parser.add_argument("-f", "--fps", help="frames per second of the generated "
"video", default=30, type=int)
parser.add_argument("-d", "--duration", help="duration of the generated video, "
"in seconds", default=10, type=int)
parser.add_argument("--fade", help="what percentage of the video snitch pings "
"should be visible for", default=10, type=float)
parser.add_argument("-o", "--output", help="filename to output to",
default="out.mp4")
parser.add_argument("-m", "--mode", help="what mode to render in. One of "
"box, line, heatmap. Defaults to box", default="box")
args = parser.parse_args()
event_file = Path(".") / args.input
snitch_db = Path(".") / args.snitch_db
# TODO time format as parameter
events = parse_events(event_file, time="yyyy-MM-dd HH:mm:ss")
snitches = set(parse_snitches(snitch_db))
# in case we have some event hits which aren't in our database
snitches |= set(snitches_from_events(events))
users = create_users(events)
# args
show_all_snitches = args.all_snitches
size = args.pixels
fps = args.fps
# convert seconds to ms
duration = args.duration * 1000
event_fade_percentage = args.fade
output_file = args.output
mode = args.mode
# TODO param for this
heatmap_percentage = 20
t_parse = time.time()
config = Config(snitches=snitches, events=events, users=users,
show_all_snitches=show_all_snitches, mode=mode,
heatmap_percentage=heatmap_percentage)
if args.record:
# https://stackoverflow.com/q/13215120
qapp = QApplication(['-platform', 'minimal'])
vis = SnitchVisRecord(duration, size, fps, event_fade_percentage,
output_file, config)
vis.render()
else:
vis = SnitchvisApp(config,
speeds=[0.25, 0.5, 1, 2.5, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000]
)
vis.exec()