1#!/usr/bin/env python3
2
3"""Convert MANOEUVRE_PREDICTION raw entries to MANOEUVRE_PREDICTION events."""
4
5import logging
6
7from chart.alg import init_algorithm
8from chart.events.event import Event
9from chart.alg import JobStatus
10from chart.db import ts
11
12logger = logging.getLogger()
13
14# LOG event class and tables
15EVENT_CLASS = 'MANO-PRED-EVENTS'
16TABLE_MANO_PRED = 'MANOEUVRE_PREDICTION'
17
18
19def raise_events(sid, sensing_start, sensing_stop, eventraiser):
20 """Raise events."""
21 logger.info('Scanning for MANOEUVRE_PREDICTION Instances entries for {sid} from {start} to {stop}'.format(
22 sid=sid, start=sensing_start, stop=sensing_stop))
23
24 for (sensing_time,
25 #stop_time,
26 file_gen_time,
27 optim_time,
28 mode,
29 size,
30 pso
31 ) in ts.select(
32 table=TABLE_MANO_PRED,
33 sid=sid,
34 sensing_start=sensing_start,
35 sensing_stop=sensing_stop,
36 fields=('SENSING_TIME',
37 'FILE_GEN_TIME',
38 'OPTIM_TIME',
39 'MODE',
40 'SIZE',
41 'PSO')
42 ):
43 eventraiser.add(Event(event_classname=EVENT_CLASS,
44 sid=sid,
45 start_time=sensing_time,
46 #stop_time=stop_time,
47 instance_properties={
48 'File_Gen_Time': file_gen_time,
49 'Optim_Time': optim_time,
50 'Mode': mode,
51 'Size': size,
52 'PSO': pso,
53 }))
54
55
56def dispatch(wo, resultfile, eventraiser):
57 """We are being run by the dispatcher tool."""
58 logging.info('Starting {ec} Events'.format(ec=EVENT_CLASS))
59 for job in wo.read_jobs():
60 logging.info('Begin event from {start} to {stop}'.
61 format(start=job['sensing_start'],
62 stop=job['sensing_stop']))
63
64 raise_events(job.sid,
65 job.sensing_start,
66 job.sensing_stop,
67 eventraiser)
68
69 resultfile.add_job(job, JobStatus.COMPLETED)
70
71 eventraiser.log_report()
72 logging.info('All done')
73
74
75def main():
76 """Command line entry point.\
77 This program can either be called via `dispatcher` or standalone."""
78 dispatch(*init_algorithm())
79
80
81if __name__ == '__main__':
82 main()