1#!/usr/bin/env python3
2
3#SK 09/05/2023: created
4"""Convert PREDICTED ORBIT entries raw entries to PREDICTED ORBIT 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 = 'ORB4ANT-EVENTS'
16
17# LOG event class and tablese
18TABLE_ORB4ANT = 'ORBIT4ANT'
19
20
21def raise_events(sid, sensing_start, sensing_stop, eventraiser):
22 """Raise events."""
23 logger.info('Scanning for ORB4ANT-REPORT 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 x,
29 y,
30 z,
31 x_dot,
32 y_dot,
33 z_dot
34 ) in ts.select(
35 table=TABLE_ORB4ANT,
36 sid=sid,
37 sensing_start=sensing_start,
38 sensing_stop=sensing_stop,
39 fields=('SENSING_TIME',
40 'x',
41 'y',
42 'z',
43 'x_dot',
44 'y_dot',
45 'z_dot')
46 ):
47 eventraiser.add(Event(event_classname=EVENT_CLASS,
48 sid=sid,
49 start_time=sensing_time,
50 #stop_time=stop_time,
51 instance_properties={
52 'X': x,
53 'Y': y,
54 'Z': z,
55 'X_dot': x_dot,
56 'Y_dot': y_dot,
57 'Z_dot': z_dot,
58 }))
59
60
61def dispatch(wo, resultfile, eventraiser):
62 """We are being run by the dispatcher tool."""
63 logging.info('Starting {ec} Events'.format(ec=EVENT_CLASS))
64 for job in wo.read_jobs():
65 logging.info('Begin event from {start} to {stop}'.
66 format(start=job['sensing_start'],
67 stop=job['sensing_stop']))
68
69 raise_events(job.sid,
70 job.sensing_start,
71 job.sensing_stop,
72 eventraiser)
73
74 resultfile.add_job(job, JobStatus.COMPLETED)
75
76 eventraiser.log_report()
77 logging.info('All done')
78
79
80def main():
81 """Command line entry point.\
82 This program can either be called via `dispatcher` or standalone."""
83 dispatch(*init_algorithm())
84
85
86if __name__ == '__main__':
87 main()