1#!/usr/bin/env python3
  2
  3#SK 05/05/2023: created
  4"""Convert SAT-MASS-REPORT raw entries to SAT-MASS-REPORT 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 = 'MASS-REPORT-EVENTS'
 16
 17# LOG event class and tablese
 18TABLE_SAT_MASS_REPORT = 'SAT_MASS_REPORT'
 19
 20
 21def raise_events(sid, sensing_start, sensing_stop, eventraiser):
 22    """Raise events."""
 23    logger.info('Scanning for SAT-MASS-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         xs,
 29         ys,
 30         zs,
 31         total_mass,
 32         fuel_mass,
 33         inertia_xx,
 34         inertia_yy,
 35         inertia_zz,
 36         inertia_xy,
 37         inertia_yz,
 38         inertia_zx
 39         ) in ts.select(
 40            table=TABLE_SAT_MASS_REPORT,
 41            sid=sid,
 42            sensing_start=sensing_start,
 43            sensing_stop=sensing_stop,
 44            fields=('SENSING_TIME',
 45                    'xs',
 46                    'ys',
 47                    'zs',
 48                    'total_mass',
 49                    'fuel_mass',
 50                    'inertia_xx',
 51                    'inertia_yy',
 52                    'inertia_zz',
 53                    'inertia_xy',
 54                    'inertia_yz',
 55                    'inertia_zx')
 56                    ):
 57        eventraiser.add(Event(event_classname=EVENT_CLASS,
 58                              sid=sid,
 59                              start_time=sensing_time,
 60                              #stop_time=stop_time,
 61                              instance_properties={
 62                                  'xs': xs,
 63                                  'ys': ys,
 64                                  'zs': zs,
 65                                  'total_mass': total_mass,
 66                                  'fuel_mass': fuel_mass,
 67                                  'inertia_xx': inertia_xx,
 68                                  'inertia_yy': inertia_yy,
 69                                  'inertia_zz': inertia_zz,
 70                                  'inertia_xy': inertia_xy,
 71                                  'inertia_yz': inertia_yz,
 72                                  'inertia_zx': inertia_zx,
 73                              }))
 74
 75
 76def dispatch(wo, resultfile, eventraiser):
 77    """We are being run by the dispatcher tool."""
 78    logging.info('Starting {ec} Events'.format(ec=EVENT_CLASS))
 79    for job in wo.read_jobs():
 80        logging.info('Begin event from {start} to {stop}'.
 81                     format(start=job['sensing_start'],
 82                            stop=job['sensing_stop']))
 83
 84        raise_events(job.sid,
 85                         job.sensing_start,
 86                         job.sensing_stop,
 87                         eventraiser)
 88
 89        resultfile.add_job(job, JobStatus.COMPLETED)
 90
 91    eventraiser.log_report()
 92    logging.info('All done')
 93
 94
 95def main():
 96    """Command line entry point.\
 97    This program can either be called via `dispatcher` or standalone."""
 98    dispatch(*init_algorithm())
 99
100
101if __name__ == '__main__':
102    main()