-
Notifications
You must be signed in to change notification settings - Fork 5
/
deploy_localisation_model.py
110 lines (90 loc) · 4.33 KB
/
deploy_localisation_model.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# The MIT License (MIT) # Copyright (c) 2014-2017 University of Bristol
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
# OR OTHER DEALINGS IN THE SOFTWARE.
import logging
from datetime import datetime, timedelta
def run(house, selection, delete_existing_workflows=True, loglevel=logging.INFO):
from hyperstream import HyperStream, StreamId, TimeInterval, UTC
from workflows.display_experiments import create_workflow_list_technicians_walkarounds
from workflows.deploy_localisation_model import create_workflow_localisation_predict
hyperstream = HyperStream(loglevel=loglevel)
M = hyperstream.channel_manager.memory
workflow_id0 = "list_technicians_walkarounds"
if delete_existing_workflows:
hyperstream.workflow_manager.delete_workflow(workflow_id0)
try:
w0 = hyperstream.workflow_manager.workflows[workflow_id0]
except KeyError:
w0 = create_workflow_list_technicians_walkarounds(hyperstream, house=house, safe=False)
hyperstream.workflow_manager.commit_workflow(workflow_id0)
time_interval = TimeInterval.up_to_now()
w0.execute(time_interval)
df = M[StreamId('experiments_dataframe', dict(house=house))].window(TimeInterval.up_to_now()).values()[0]
experiment_ids = set([df['experiment_id'][i - 1] for i in selection])
hyperstream.plate_manager.delete_plate("H.SelectedLocalisationExperiment")
hyperstream.plate_manager.create_plate(
plate_id="H.SelectedLocalisationExperiment",
description="Localisation experiments selected by the technician in SPHERE house",
meta_data_id="localisation-experiment",
values=[],
complement=True,
parent_plate="H"
)
hyperstream.plate_manager.delete_plate("H.W")
hyperstream.plate_manager.create_plate(
plate_id="H.W",
description="All wearables in all houses",
meta_data_id="wearable",
values=[],
complement=True,
parent_plate="H"
)
experiment_ids_str = '_'.join(experiment_ids)
workflow_id = "lda_localisation_model_predict_"+experiment_ids_str
if delete_existing_workflows:
hyperstream.workflow_manager.delete_workflow(workflow_id)
try:
w = hyperstream.workflow_manager.workflows[workflow_id]
except KeyError:
w = create_workflow_localisation_predict(hyperstream, house=house,experiment_ids=experiment_ids, safe=False)
hyperstream.workflow_manager.commit_workflow(workflow_id)
time_interval = TimeInterval.up_to_now()
w.execute(time_interval)
print('number of non_empty_streams: {}'.format(
len(hyperstream.channel_manager.memory.non_empty_streams)))
# for wearable in 'ABCD':
# sid = StreamId('predicted_locations_broadcasted', dict(house=house, wearable=wearable))
# print sid
# print len(list(hyperstream.channel_manager.memory[sid].window(time_interval)))
# print '\n\n'
if __name__ == '__main__':
import sys
from os import path
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
if len(sys.argv) < 3:
print("Expected at least two integer ids")
exit(0)
try:
technicians_selection = map(int, sys.argv[1:])
except ValueError:
print("Expected at least two integer ids")
technicians_selection = None # just to keep lint happy
exit(0)
house = 1
run(house, technicians_selection)