1#!/usr/bin/env python3
2
3#SK 05/05/2023: created
4"""Convert MANO-HIST raw entries to MANO-HIST events."""
5
6import logging
7
8from chart.alg import init_algorithm
9from chart.events.event import Event
10from chart.alg import JobStatus
11from chart.db import ts
12
13logger = logging.getLogger()
14
15EVENT_CLASS = 'MANO-HIST-EVENTS'
16
17# LOG event class and tablese
18TABLE_MANO_HIST = 'MANOEUVRE_HISTORY'
19
20
21def raise_events(sid, sensing_start, sensing_stop, eventraiser):
22 """Raise events."""
23 logger.info('Scanning for MANO-HIST Instances entries for {sid} from {start} to {stop}'.format(
24 sid=sid, start=sensing_start, stop=sensing_stop))
25
26 for (sensing_time,
27 #stop_time,
28 acc_comp_1,
29 acc_comp_2,
30 acc_comp_3,
31 rec_flag
32 ) in ts.select(
33 table=TABLE_MANO_HIST,
34 sid=sid,
35 sensing_start=sensing_start,
36 sensing_stop=sensing_stop,
37 fields=('SENSING_TIME',
38 'acc_comp_1',
39 'acc_comp_2',
40 'acc_comp_3',
41 'rec_flag')
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 'acc_comp_1': acc_comp_1,
49 'acc_comp_2': acc_comp_2,
50 'acc_comp_3': acc_comp_3,
51 'rec_flag': rec_flag,
52 }))
53
54
55def dispatch(wo, resultfile, eventraiser):
56 """We are being run by the dispatcher tool."""
57 logging.info('Starting {ec} Events'.format(ec=EVENT_CLASS))
58 for job in wo.read_jobs():
59 logging.info('Begin event from {start} to {stop}'.
60 format(start=job['sensing_start'],
61 stop=job['sensing_stop']))
62
63 raise_events(job.sid,
64 job.sensing_start,
65 job.sensing_stop,
66 eventraiser)
67
68 resultfile.add_job(job, JobStatus.COMPLETED)
69
70 eventraiser.log_report()
71 logging.info('All done')
72
73
74def main():
75 """Command line entry point.\
76 This program can either be called via `dispatcher` or standalone."""
77 dispatch(*init_algorithm())
78
79
80if __name__ == '__main__':
81 main()