def __init__(self,
              instantList,
              lower_inc=None,
              upper_inc=None,
              interp=None):
     assert (isinstance(
         lower_inc, (bool, type(None)))), "ERROR: Invalid lower bound flag"
     assert (isinstance(
         upper_inc, (bool, type(None)))), "ERROR: Invalid upper bound flag"
     assert (isinstance(interp,
                        (str, type(None)))), "ERROR: Invalid interpolation"
     if isinstance(interp, str):
         assert (interp == 'Linear'
                 or interp == 'Stepwise'), "ERROR: Invalid interpolation"
     self._instantList = []
     # Constructor with a first argument of type string and optional arguments for the bounds and interpolation
     if isinstance(instantList, str):
         elements = parse_temporalseq(instantList, 0)
         for inst in elements[2][0]:
             self._instantList.append(self.ComponentClass(inst[0], inst[1]))
         self._lower_inc = elements[2][1]
         self._upper_inc = elements[2][2]
         # Set interpolation with the argument or the flag from the string if given
         if interp is not None:
             self._interp = interp
         else:
             if self.BaseClassDiscrete:
                 self._interp = 'Stepwise'
             else:
                 self._interp = elements[2][3] if elements[2][
                     3] is not None else 'Linear'
     # Constructor with a first argument of type list and optional arguments for the bounds and interpolation
     elif isinstance(instantList, list):
         # List of strings representing instant values
         if all(isinstance(arg, str) for arg in instantList):
             for arg in instantList:
                 self._instantList.append(self.ComponentClass(arg))
         # List of instant values
         elif all(
                 isinstance(arg, self.ComponentClass)
                 for arg in instantList):
             for arg in instantList:
                 self._instantList.append(arg)
         else:
             raise Exception(
                 "ERROR: Could not parse temporal sequence value")
         self._lower_inc = lower_inc if lower_inc is not None else True
         self._upper_inc = upper_inc if upper_inc is not None else False
         # Set the interpolation
         if interp is not None:
             self._interp = interp
         else:
             self._interp = 'Stepwise' if self.BaseClassDiscrete else 'Linear'
     else:
         raise Exception("ERROR: Could not parse temporal sequence value")
     # Verify validity of the resulting instance
     self._valid()
Exemple #2
0
 def __init__(self, instantList, lower_inc=None, upper_inc=None, interp=None, srid=None):
     assert (isinstance(lower_inc, (bool, type(None)))), "ERROR: Invalid lower bound flag"
     assert (isinstance(upper_inc, (bool, type(None)))), "ERROR: Invalid upper bound flag"
     assert (isinstance(interp, (str, type(None)))), "ERROR: Invalid interpolation"
     if isinstance(interp, str):
         assert (interp == 'Linear' or interp == 'Stepwise'), "ERROR: Invalid interpolation"
     self._instantList = []
     # Constructor with a first argument of type string and optional arguments for the bounds and interpolation
     if isinstance(instantList, str):
         # If srid is given
         if re.match(r'^(SRID|srid)\s*=\s*\d+\s*(;|,)\s*', instantList):
             # Get the srid and remove the "srid=xxx;" prefix
             srid_str = int(re.search(r'(\d+)', instantList).group())
             if srid is not None and srid_str != srid:
                 raise Exception(f"ERROR: SRID mismatch: {srid_str} vs {srid}")
             srid = srid_str
             instantList = re.sub(r'^(SRID|srid)\s*=\s*\d+\s*(;|,)\s*', '', instantList)
         # Parse without the eventual "srid=xxx;" prefix
         elements = parse_temporalseq(instantList, 0)
         for inst in elements[2][0]:
             self._instantList.append(self.ComponentClass(inst[0], inst[1], srid=srid))
         self._lower_inc = elements[2][1]
         self._upper_inc = elements[2][2]
         # Set interpolation with the argument or the flag from the string if given
         if interp is not None:
             self._interp = interp
         else:
             if self.BaseClassDiscrete:
                 self._interp = 'Stepwise'
             else:
                 self._interp = elements[2][3] if elements[2][3] is not None else 'Linear'
     # Constructor with a first argument of type list and optional arguments for the bounds and interpolation
     elif isinstance(instantList, list):
         # List of strings representing instant values
         if all(isinstance(arg, str) for arg in instantList):
             for arg in instantList:
                 self._instantList.append(self.ComponentClass(arg, srid=srid))
         # List of instant values
         elif all(isinstance(arg, self.ComponentClass) for arg in instantList):
             for arg in instantList:
                 self._instantList.append(arg)
         else:
             raise Exception("ERROR: Could not parse temporal sequence value")
         self._lower_inc = lower_inc if lower_inc is not None else True
         self._upper_inc = upper_inc if upper_inc is not None else False
         # Set the interpolation
         if interp is not None:
             self._interp = interp
         else:
             self._interp = 'Stepwise' if self.BaseClassDiscrete else 'Linear'
     else:
         raise Exception("ERROR: Could not parse temporal sequence value")
     # Verify validity of the resulting instance
     self._valid()