-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
65 lines (57 loc) · 1.92 KB
/
app.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
import os
import h5py
import json
from flask import Flask
from flask import render_template
app = Flask(__name__)
@app.route('/')
def load_page():
return render_template('index.html')
@app.route('/files')
def get_files():
with open('static/data/fileList.json') as f:
fileList = f.read()
return fileList
@app.route('/data/<filename>')
def load_file(filename):
with open('static/data/' + filename) as f:
data = f.read()
return data
@app.route('/data/<filename>/event/<event_index>')
def load_event(filename, event_index):
event_index = int(event_index)
with h5py.File('static/data/' + filename, 'r') as f:
events = f['events']
event = events[event_index]
hits = f['hits']
event_hits = hits[event['hit_ref']]
t0 = min(event_hits['ts'])
list_to_json = []
for row in event_hits[['px', 'py', 'ts', 'q', 'channelid',
'chipid']]:
x, y, t, q, channel, chip = [int(a) for a in row]
t = int(t-t0)
list_to_json.append([channel, chip, 0, x, y, 0, 0, 0, t, 0, q, 0])
return json.dumps(list_to_json)
@app.route('/data/<filename>/tracks/<event_index>')
def load_tracks(filename, event_index):
event_index = int(event_index)
with h5py.File('static/data/' + filename, 'r') as f:
events = f['events']
event = events[event_index]
tracks = f['tracks']
has_tracks = bool(event['track_ref'])
track_list = []
if has_tracks:
for track in tracks[event['track_ref']]:
track_list.append({
'start': track['start'].tolist(),
'end': track['end'].tolist()
})
return json.dumps(track_list)
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--port', type=int, default=5000)
args = parser.parse_args()
app.run(port=args.port)