1#!/usr/bin/env python3
  2
  3# """Experimental new super-sid."""
  4
  5# from datetime import datetime
  6
  7# from chart.project import settings
  8
  9# # project.sys_table()
 10# # project.all_sys_tables()
 11
 12# # Source events:
 13# # Launch / Completion
 14# # Start of commisioning
 15# # End of commisioning
 16# # Start of normal operations
 17# # End of normal operations
 18# # Offline
 19
 20# class SuperSIDBase:
 21#     """Base class for SID classes."""
 22
 23#     # _sids = None
 24
 25#     # @staticmethod
 26#     # def init_done():
 27#         # return SIDBase._sids is not None
 28
 29#     # @staticmethod
 30#     # def begin_init():
 31#         # SIDBase._sids = []
 32
 33#     # @staticmethod
 34#     # def register(sid):
 35#         # SIDBase._sids.append(sid)
 36
 37#     # @staticmethod
 38#     # def default_sid():
 39#         # return SIDBase._sids[0]
 40
 41#     # @staticmethod
 42#     # def all_sids():
 43#         # return SIDBase._sids
 44
 45#     # cache all_tables() call
 46#     _all_tables = None
 47#     # cache individual table objects
 48#     _tables = {}
 49
 50#     def __init__(self,
 51#                  short_name=None,
 52#                  sid_num=None,
 53#                  name=None,
 54#                  operational=True,
 55#                  start=None,
 56#                  stop=None,
 57#                  timeline=None,
 58#                  description=None,
 59#                  colour=None,
 60#                  visible=True,
 61#                  default=False,
 62#                  satellite=None):
 63#         """Args:
 64#             `short_id` (str): Minimal string to uniquely identify this source
 65#                 ("MSG1", "M02", "CDA2")
 66#             `default` (bool): This is the default SID, used for either project-wide reports or
 67#                 queries, or when we're not sure which SID is appropriate.
 68#         """
 69#         self.short_name = short_name  # M02
 70#         self.sid_num = sid_num
 71#         self.name = name  # Metop-A
 72#         self.operational = operational  # include this one in normal processing
 73#         self.start = start  # start of normal operations; used types "launch" or "start"
 74#         self.stop = stop  # used types "end" or "last"
 75#         self.timeline = timeline  # list of significant events for the source
 76#         self.description = description
 77#         self.colour = colour  # used for some menus and text labels
 78#         self.visible = visible  # allow to hide from all user interface controls
 79#         self.default = default  # use as the default source if none is given
 80#         self.satellite = satellite
 81
 82#     # def testfunc(self):
 83#         # print('sid base test func')
 84
 85#     def table(self, name):
 86#         """Construct a TableInfo object.
 87
 88#         In future they could be customised for this specific SID instance."""
 89#         if name in SuperSIDBase._tables:
 90#             return SuperSIDBase._tables[name]
 91
 92#         from chart.db.model.table import TableInfo
 93#         result = TableInfo(name)  # , sid=self)
 94#         SuperSIDBase._tables[name] = result
 95#         return result
 96
 97#     def all_tables(self):
 98#         """Yield all timeseries tables."""
 99#         if SuperSIDBase._all_tables is None:
100#             SuperSIDBase._all_tables = []
101#             for filename in sorted(settings.TS_TABLE_DIR.glob('*.xml')):
102#                 SuperSIDBase._all_tables.append(self.table(filename.stem))
103
104#         for table_info in SuperSIDBase._all_tables:
105#             yield table_info
106
107#     def cal_dirname(self):
108#         """Compute a subdirectory to write named calibration files to."""
109#         return self.short_name
110
111#     def cal_calname(self):
112#         """Compute a suitable plSQL function name suffix."""
113#         return self.short_name
114
115#     def matches(self, name):
116#         raise NotImplemented()
117
118#     def sql_where(self, ts=False, table_name=None):
119#         """SQL clause to detect ts rows containing us."""
120#         raise NotImplemented()
121
122#     def sql_where_bind(self, ts=False, table_name=None):
123#         """SQL clause to detect ts rows containing us."""
124#         raise NotImplemented()
125
126#     def sql_where_values(self, ts=False, table_name=None):
127#         """SQL clause to detect ts rows containing us."""
128#         raise NotImplemented()
129
130#     def auto_sampling_options(self):
131#         """Subsampling options that automatic subsampling algorithm can select."""
132#         raise NotImplemented()
133
134#     def to_url_query(self, base=None):
135#         raise NotImplemented()
136
137#     def to_xml(self, elem):
138#         raise NotImplemented()
139
140#     def to_dict(self):
141#         raise NotImplemented()
142
143#     def to_reportname_fragment(self):
144#         raise NotImplemented()
145
146#     # def as_acronym(self):
147#         # raise NotImplemented()
148
149
150# # class SuperSIDScidBase(SuperSIDBase):
151# #     def __init__(self, scid):
152# #         super(self, SuperSIDScidBase).__init__(self)
153# #         self.scid = scid
154
155# #     def matches(self, scid):
156# #         return self.scid.lower() == scid.lower()
157
158
159# # class SuperSIDGsidBase(SuperSIDBase):
160# #     def __init__(self, gsid):
161# #         super(self, SuperSIDGsidBase).__init__(self)
162# #         self.gsid = gsid
163
164# #     def matches(self, scid):
165# #         return self.gsid.lower() == gsid.lower()
166
167
168# # class SuperSIDSidnumBase(SuperSIDBase):
169# #     def __init__(self, sid_num):
170# #         super(self, SuperSIDSidnumBase).__init__(self)
171# #         self.sid_num = sid_num
172
173# #     def matches(self, sid_num=None, name=None):
174# #         return self.sid_num == sid_num or self.short_name
175
176
177# class SuperSIDMTG(SuperSIDBase):
178#     def __init__(self,
179#                  scid,
180#                  sid_num,
181#                  name,
182#                  operational,
183#                  default,
184#                  start):
185#         super(SuperSIDMTG, self).__init__(
186#             short_name=scid,
187#             sid_num=sid_num,
188#             name=name,
189#             operational=operational,
190#             default=default,
191#             start=start)
192
193
194# class SuperSIDManagerBase:
195#     def __init__(self, sid_class, allowed_sids):
196#         self.sid_class = sid_class
197#         self.sid_cache = {}
198#         self.allowed_sids = allowed_sids
199
200#     def sid(self,
201#             name=None,
202#             node=None,
203#             sf=None,
204#             django_request=None,
205#             from_string=None,
206#             reportname_fragment=None,
207#             *args,
208#             **kwargs):
209#         # cargs = frozenset(sorted(kwargs.items())))
210#         # cargs = (args, frozenset(sorted(kwargs.items())))
211#         # result = self.sid_cache.get(cargs, None)
212#         # if result is not None:
213#             # return result
214
215#         # sid_cache[cargs] = None
216#         raise NotImplemented()
217
218#     def all_sids(self, operational=True):
219#         """All SIDs available to the project."""
220#         return [s for s in self.allowed_sids if s.operational==operational]
221
222#     def report_sids(self, activity=None):
223#         """All SIDs which have reports in the reports table."""
224#         raise NotImplemented()
225
226#     def ddl_sys_fields(self):
227#         raise NotImplemented()
228
229#     def from_django_params(self, params, remove=False):
230#         raise NotImplemented()
231
232#     def ddl_fields(self, ts=False, table_name=None):
233#         raise NotImplemented()
234
235#     def rdr_kwargs(self, row):
236#         raise NotImplemented()
237
238#     def rdr_insert(self):
239#         raise NotImplemented()
240
241#     def insert_fields(self):
242#         raise NotImplemented()
243
244#     def bind_insert(self):
245#         raise NotImplemented()
246
247#     def sql_where_bind(self, ts=False, table_name=None):
248#         raise NotImplemented()
249
250#     def sql_select(self, ts=False, table_name=None):
251#         raise NotImplemented()
252
253#     def from_select(self, ts=False, table_name=None):
254#         raise NotImplemented()
255
256#     def sql_insert(self, ts=False, table_name=None):
257#         raise NotImplemented()
258
259#     def sql_update(self, ts=False, table_name=None):
260#         raise NotImplemented()
261
262#     def bind_insert(self, ts=False, table_name=None):
263#         raise NotImplemented()
264
265#     def ddl_cal_clause(self, sids):
266#         raise NotImplemented()
267
268
269# class SuperSIDMTGManager(SuperSIDManagerBase):
270#     def __init__(self, allowed_sids):
271#         super(SuperSIDMTGManager, self).__init__(
272#             sid_class=SuperSIDMTG,
273#             allowed_sids=allowed_sids)
274
275#     def sid(self,
276#             scid=None,
277#             sid_num=1):
278#         return self.allowed_sids[0]
279
280# sid_mtg_manager = SuperSIDMTGManager(allowed_sids=[
281#     SuperSIDMTG(scid='MTGi1',
282#             sid_num=1,
283#             name='MTG Imager 1',
284#             operational=True,
285#             default=True,
286#             start=datetime(2020, 1, 1))
287# ])