コード例 #1
0
ファイル: _view4.py プロジェクト: riverbed/flyscript
 def _convert_sample_time(self, sample_timestamp):
     if self.view.timestamp_format == APITimestampFormat.SECOND:
         return timeutils.sec_string_to_datetime(sample_timestamp)
     elif self.view.timestamp_format == APITimestampFormat.MILLISECOND:
         return timeutils.msec_string_to_datetime(sample_timestamp)
     elif self.view.timestamp_format == APITimestampFormat.MICROSECOND:
         return timeutils.usec_string_to_datetime(sample_timestamp)
     elif self.view.timestamp_format == APITimestampFormat.NANOSECOND:
         return timeutils.nsec_string_to_datetime(sample_timestamp)
     else:
         raise ValueError('invalid time format %s' % str(view.timestamp_format))
コード例 #2
0
ファイル: _view4.py プロジェクト: geraldcombs/flyscript
def _to_native(string, legend_entry):
    """ convert `string` to an appropriate native type given `legend_entry` """
    if legend_entry.calculation == 'AVG':
        string, den = string.split(':', 1)
        denominator = int(den)
    else:
        denominator = 1
    
    if legend_entry.type.startswith('INT') \
      or legend_entry.type.startswith('UINT') \
      or legend_entry.type in ( 'TCP_PORT', 'UDP_PORT'):
        if legend_entry.base == 'DEC':
            baseval = 10
        elif legend_entry.base == 'HEX':
            baseval = 16
        else:
            raise ValueError('do not know how to handle integer base %s' %
                             legend_entry.base)
        return int(string, baseval) / denominator

    if legend_entry.type == 'DOUBLE':
        return float(string) / denominator

    if legend_entry.type == 'BOOLEAN':
        if string.lower() == 'false' or string.lower() == '0':
            return 0
        elif string.lower() == 'true' or string.lower() == '1':
            return 1
        else:
            # Booleans can be a count of successes
            return int(string)

    if legend_entry.type == 'ABSOLUTE_TIME':
        return timeutils.nsec_string_to_datetime(string)
    
    if legend_entry.type == 'RELATIVE_TIME':
        # consider it an integer for now
        return int(string)

    # XXX anything with IPv4 or ETHER?

    return string