def deserialize(context):
    setSize = context.readI32()
    enumClassName = context.readString()
    valList = []
    for i in range(setSize):
        valList.append(context.readString())
    return EnumSet(enumClassName, valList)
Beispiel #2
0
    def __init__(self, refTime=None, fcstTime=None, validPeriod=None):
        self.fcstTime = int(fcstTime) if fcstTime is not None else 0
        self.refTime = refTime if refTime is not None else None
        if validPeriod is not None and type(validPeriod) is not TimeRange:
            ValueError("Invalid validPeriod object specified for DataTime.")
        self.validPeriod = validPeriod if validPeriod is not None else None
        self.utilityFlags = EnumSet(
            'com.raytheon.uf.common.time.DataTime$FLAG')
        self.levelValue = numpy.float64(-1.0)

        if self.refTime is not None:
            if isinstance(self.refTime, datetime.datetime):
                self.refTime = int(
                    calendar.timegm(self.refTime.utctimetuple()) * 1000)
            elif isinstance(self.refTime, time.struct_time):
                self.refTime = int(calendar.timegm(self.refTime) * 1000)
            elif hasattr(self.refTime, 'getTime'):
                # getTime should be returning ms, there is no way to check this
                # This is expected for java Date
                self.refTime = int(self.refTime.getTime())
            else:
                self.refTime = int(refTime)
            self.refTime = Date(self.refTime)

            if self.validPeriod is None:
                validTimeMillis = self.refTime.getTime() + int(
                    self.fcstTime * 1000)
                self.validPeriod = TimeRange()
                self.validPeriod.setStart(validTimeMillis / 1000)
                self.validPeriod.setEnd(validTimeMillis / 1000)

        # figure out utility flags
        if fcstTime:
            self.utilityFlags.add("FCST_USED")
        if self.validPeriod and self.validPeriod.isValid():
            self.utilityFlags.add("PERIOD_USED")
Beispiel #3
0
    def __init__(self, refTime=None, fcstTime=None, validPeriod=None):
        """
        Construct a new DataTime.
        May also be called as DataTime(str) to parse a string and create a
        DataTime from it. Some examples of valid DataTime strings:

             '2016-08-02 01:23:45.0'
             '2016-08-02 01:23:45.123'
             '2016-08-02 01:23:45.0 (17)',
             '2016-08-02 01:23:45.0 (17:34)'
             '2016-08-02 01:23:45.0[2016-08-02_02:34:45.0--2016-08-02_03:45:56.0]'
             '2016-08-02 01:23:45.456_(17:34)[2016-08-02_02:34:45.0--2016-08-02_03:45:56.0]'
        """
        if fcstTime is not None:
            self.fcstTime = int(fcstTime)
        else:
            self.fcstTime = 0
        self.refTime = refTime
        if validPeriod is not None and type(validPeriod) is not TimeRange:
            raise ValueError("Invalid validPeriod object specified for DataTime.")
        self.validPeriod = validPeriod
        self.utilityFlags = EnumSet('com.raytheon.uf.common.time.DataTime$FLAG')
        self.levelValue = numpy.float64(-1.0)

        if self.refTime is not None:
            if isinstance(self.refTime, datetime.datetime):
                self.refTime = long(calendar.timegm(self.refTime.utctimetuple()) * 1000)
            elif isinstance(self.refTime, time.struct_time):
                self.refTime = long(calendar.timegm(self.refTime) * 1000)
            elif hasattr(self.refTime, 'getTime'):
                # getTime should be returning ms, there is no way to check this
                # This is expected for java Date
                self.refTime = long(self.refTime.getTime())
            else:
                try:
                    self.refTime = long(self.refTime)
                except ValueError:
                    # Assume first arg is a string. Attempt to parse.
                    match = STR_PATTERN.match(self.refTime)
                    if match is None:
                        raise ValueError('Could not parse DataTime info from '
                                         + str(refTime))

                    groups = match.groups()
                    rDate = groups[0]
                    rTime = groups[1]
                    rMillis = groups[2] or 0
                    fcstTimeHr = groups[3]
                    fcstTimeMin = groups[4]
                    periodStart = groups[5], groups[6], (groups[7] or 0)
                    periodEnd = groups[8], groups[9], (groups[10] or 0)
                    self.refTime = self._getTimeAsEpochMillis(rDate, rTime, rMillis)

                    if fcstTimeHr is not None:
                        self.fcstTime = long(fcstTimeHr) * 3600
                        if fcstTimeMin is not None:
                            self.fcstTime += long(fcstTimeMin) * 60

                    if periodStart[0] is not None:
                        self.validPeriod = TimeRange()
                        periodStartTime = self._getTimeAsEpochMillis(*periodStart)
                        self.validPeriod.setStart(periodStartTime / 1000)
                        periodEndTime = self._getTimeAsEpochMillis(*periodEnd)
                        self.validPeriod.setEnd(periodEndTime / 1000)

            self.refTime = Date(self.refTime)

            if self.validPeriod is None:
                validTimeMillis = self.refTime.getTime() + long(self.fcstTime * 1000)
                self.validPeriod = TimeRange()
                self.validPeriod.setStart(validTimeMillis / 1000)
                self.validPeriod.setEnd(validTimeMillis / 1000)

        # figure out utility flags
        if self.fcstTime:
            self.utilityFlags.add("FCST_USED")
        if self.validPeriod and self.validPeriod.isValid():
            self.utilityFlags.add("PERIOD_USED")