1#!/usr/bin/env python3
2
3# SK 23/06/2023: Created
4
5import logging
6from chart.db import ts
7from chart.events.event import Event, include_event_check
8from chart.products.events.multitable_utils import process_ordering_sensing_time
9from chart.products.pus.packetdef import PacketDef
10from chart.db.model.table import TableInfo
11from chart.common.traits import is_listlike
12from chart.web.user import User
13
14DECODER_ID = 'MASS-REPORT-EVENTS'
15TABLE = 'SAT_MASS_REPORT'
16EVENT_CLASSNAME = 'MASS-REPORT-EVENTS'
17
18logger = logging.getLogger()
19
20def find_events(sid,
21 start_time,
22 start_time_eq,
23 stop_time,
24 event_classes,
25 ordering,
26 from_to,
27 properties,
28 count,
29 single,
30 filtering,
31 multitable_extra_params,
32 user: User = None):
33
34 if from_to is not None:
35 page_start, page_stop = from_to
36
37 limit = 1 if single and start_time_eq is None else None
38
39 events = []
40 event_count = 0
41
42 # Reset ordering for sensing_time
43 order_clauses = process_ordering_sensing_time(ordering)
44
45 table_info = TableInfo(TABLE, sid=sid, fast_load=True)
46
47 if not single and count:
48 # just return count of events
49 event_count = ts.count(
50 table=table_info.storage_table,
51 field='SENSING_TIME',
52 method='ap',
53 sid=sid,
54 sensing_start=start_time,
55 sensing_stop=stop_time)
56
57 return event_count, events
58
59
60 fields = ('SENSING_TIME', 'PRODUCT', 'XS', 'YS', 'ZS', 'TOTAL_MASS', 'FUEL_MASS', 'INERTIA_XX', 'INERTIA_YY', 'INERTIA_ZZ', 'INERTIA_XY', 'INERTIA_YZ', 'INERTIA_ZX')
61
62 for row in ts.select(sid=sid, sensing_start=start_time, sensing_stop=stop_time, sensing_time=start_time_eq, table=table_info.storage_table, fields=fields, ordering=order_clauses, limit=limit):
63 sensing_time, product, xs, ys, zs, total_mass, fuel_mass, inertia_xx, inertia_yy, inertia_zz, inertia_xy, inertia_yz, inertia_zx = row
64 inst_properties = {
65 'SID_NUM': sid.sid_num,
66 'PRODUCT': product,
67 'XS': xs,
68 'YS': ys,
69 'ZS': zs,
70 'TOTAL_MASS': total_mass,
71 'FUEL_MASS': fuel_mass,
72 'INERTIA_XX': inertia_xx,
73 'INERTIA_YY': inertia_yy,
74 'INERTIA_ZZ': inertia_zz,
75 'INERTIA_XY': inertia_xy,
76 'INERTIA_YZ': inertia_yz,
77 'INERTIA_ZX': inertia_zx
78 }
79
80 if not include_event_check(properties, inst_properties):
81 continue
82
83 event_count += 1
84
85 if not count and (from_to is None or (page_start <= event_count and event_count <= page_stop)):
86 events.append(Event(sid=sid,
87 event_classname=EVENT_CLASSNAME,
88 start_time=sensing_time,
89 instance_properties=inst_properties))
90 if single:
91 break
92
93 return event_count, events