当前位置: 首页>>代码示例>>Python>>正文


Python DataStore.safestrptime方法代码示例

本文整理汇总了Python中pywws.DataStore.safestrptime方法的典型用法代码示例。如果您正苦于以下问题:Python DataStore.safestrptime方法的具体用法?Python DataStore.safestrptime怎么用?Python DataStore.safestrptime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pywws.DataStore的用法示例。


在下文中一共展示了DataStore.safestrptime方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CheckFixedBlock

# 需要导入模块: from pywws import DataStore [as 别名]
# 或者: from pywws.DataStore import safestrptime [as 别名]
def CheckFixedBlock(ws, params, status, logger):
    fixed_block = ws.get_fixed_block(unbuffered=True)
    # check clocks
    try:
        s_time = DataStore.safestrptime(
            fixed_block['date_time'], '%Y-%m-%d %H:%M')
    except Exception:
        s_time = None
    if s_time:
        c_time = datetime.now().replace(second=0, microsecond=0)
        diff = abs(s_time - c_time)
        if diff > timedelta(minutes=2):
            logger.warning(
                "Computer and weather station clocks disagree by %s (H:M:S).", str(diff))
    # store weather station type
    params.set('config', 'ws type', ws.ws_type)
    # store info from fixed block
    pressure_offset = fixed_block['rel_pressure'] - fixed_block['abs_pressure']
    old_offset = eval(status.get('fixed', 'pressure offset', 'None'))
    if old_offset and abs(old_offset - pressure_offset) > 0.01:
        # re-read fixed block, as can get incorrect values
        logger.warning('Re-read fixed block')
        fixed_block = ws.get_fixed_block(unbuffered=True)
        if not fixed_block:
            return None
        pressure_offset = fixed_block['rel_pressure'] - fixed_block['abs_pressure']
    if old_offset and abs(old_offset - pressure_offset) > 0.01:
        logger.warning(
            'Pressure offset change: %g -> %g', old_offset, pressure_offset)
    params.unset('fixed', 'pressure offset')
    params.unset('fixed', 'fixed block')
    status.set('fixed', 'pressure offset', '%g' % (pressure_offset))
    status.set('fixed', 'fixed block', str(fixed_block))
    return fixed_block
开发者ID:miguelvb,项目名称:r-weather,代码行数:36,代码来源:LogData.py

示例2: check_fixed_block

# 需要导入模块: from pywws import DataStore [as 别名]
# 或者: from pywws.DataStore import safestrptime [as 别名]
 def check_fixed_block(self):
     fixed_block = self.ws.get_fixed_block(unbuffered=True)
     # check clocks
     try:
         s_time = DataStore.safestrptime(
             fixed_block['date_time'], '%Y-%m-%d %H:%M')
     except Exception:
         s_time = None
     if s_time:
         c_time = datetime.now().replace(second=0, microsecond=0)
         diff = abs(s_time - c_time)
         if diff > timedelta(minutes=2):
             self.logger.warning(
                 "Computer and weather station clocks disagree by %s (H:M:S).", str(diff))
     # store weather station type
     self.params.set('config', 'ws type', self.ws.ws_type)
     # store info from fixed block
     self.status.unset('fixed', 'pressure offset')
     if not self.params.get('config', 'pressure offset'):
         self.params.set('config', 'pressure offset', '%g' % (
             fixed_block['rel_pressure'] - fixed_block['abs_pressure']))
     self.params.unset('fixed', 'fixed block')
     self.status.set('fixed', 'fixed block', str(fixed_block))
     return fixed_block
开发者ID:aarzho,项目名称:pywws,代码行数:26,代码来源:LogData.py

示例3: process

# 需要导入模块: from pywws import DataStore [as 别名]
# 或者: from pywws.DataStore import safestrptime [as 别名]

#.........这里部分代码省略.........
                        continue
                    # format is: key fmt_string no_value_string conversion
                    # get value
                    if command[0] == 'calc':
                        x = eval(command[1])
                        del command[1]
                    else:
                        x = data[command[0]]
                    # adjust time
                    if isinstance(x, datetime):
                        if round_time:
                            x += round_time
                        x = x.replace(tzinfo=utc)
                        x = x.astimezone(time_zone)
                    # convert data
                    if x != None and len(command) > 3:
                        x = eval(command[3])
                    # get format
                    fmt = '%s'
                    if len(command) > 1:
                        fmt = command[1]
                    # write output
                    if x == None:
                        if len(command) > 2:
                            yield command[2]
                    elif isinstance(x, datetime):
                        yield x.strftime(fmt)
                    elif not self.use_locale:
                        yield fmt % (x)
                    elif sys.version_info >= (2, 7) or '%%' not in fmt:
                        yield locale.format_string(fmt, x)
                    else:
                        yield locale.format_string(
                            fmt.replace('%%', '##'), x).replace('##', '%')
                elif command[0] == 'monthly':
                    data_set = self.monthly_data
                    idx, valid_data = jump(datetime.max, -1)
                    data = data_set[idx]
                elif command[0] == 'daily':
                    data_set = self.daily_data
                    idx, valid_data = jump(datetime.max, -1)
                    data = data_set[idx]
                elif command[0] == 'hourly':
                    data_set = self.hourly_data
                    idx, valid_data = jump(datetime.max, -1)
                    data = data_set[idx]
                elif command[0] == 'raw':
                    data_set = self.calib_data
                    idx, valid_data = jump(datetime.max, -1)
                    data = data_set[idx]
                elif command[0] == 'live':
                    data_set = self.calib_data
                    idx = datetime.max
                    valid_data = True
                    data = live_data
                elif command[0] == 'timezone':
                    if command[1] == 'utc':
                        time_zone = utc
                    elif command[1] == 'local':
                        time_zone = Local
                    else:
                        self.logger.error("Unknown time zone: %s", command[1])
                        return
                elif command[0] == 'roundtime':
                    if eval(command[1]):
                        round_time = timedelta(seconds=30)
                    else:
                        round_time = None
                elif command[0] == 'jump':
                    prevdata = data
                    idx, valid_data = jump(idx, int(command[1]))
                    data = data_set[idx]
                elif command[0] == 'goto':
                    prevdata = data
                    time_str = command[1]
                    if '%' in time_str:
                        lcl = idx.replace(tzinfo=utc).astimezone(time_zone)
                        time_str = lcl.strftime(time_str)
                    new_idx = DataStore.safestrptime(time_str)
                    new_idx = new_idx.replace(tzinfo=time_zone).astimezone(utc)
                    new_idx = data_set.after(new_idx.replace(tzinfo=None))
                    if new_idx:
                        idx = new_idx
                        data = data_set[idx]
                        valid_data = True
                    else:
                        valid_data = False
                elif command[0] == 'loop':
                    loop_count = int(command[1])
                    loop_start = tmplt.tell()
                elif command[0] == 'endloop':
                    loop_count -= 1
                    if valid_data and loop_count > 0:
                        tmplt.seek(loop_start, 0)
                else:
                    self.logger.error(
                        "Unknown processing directive: #%s#", parts[i])
                    return
        tmplt.close()
        return
开发者ID:3v1n0,项目名称:pywws,代码行数:104,代码来源:Template.py

示例4: open

# 需要导入模块: from pywws import DataStore [as 别名]
# 或者: from pywws.DataStore import safestrptime [as 别名]
 in_name = args[0]
 out_name = args[1]
 # open input
 in_file = open(in_name, 'r')
 # open data file store
 ds = DataStore.data_store(out_name)
 # get time to go forward to
 first_stored = ds.after(datetime.min)
 if first_stored == None:
     first_stored = datetime.max
 # copy any missing data
 last_date = None
 count = 0
 for line in in_file:
     items = line.split(',')
     local_date = DataStore.safestrptime(items[2].strip(), '%Y-%m-%d %H:%M:%S')
     local_date = local_date.replace(tzinfo=TimeZone.Local)
     date = local_date.astimezone(TimeZone.utc)
     if last_date and date < last_date:
         date = date + timedelta(hours=1)
         print "Corrected DST ambiguity %s %s -> %s" % (
             local_date, local_date.tzname(), date)
     last_date = date
     date = date.replace(tzinfo=None)
     # get data
     data = {}
     data['delay'] = int(items[3])
     data['hum_in'] = int(items[4])
     data['temp_in'] = float(items[5])
     try:
         data['hum_out'] = int(items[6])
开发者ID:x2q,项目名称:pywws,代码行数:33,代码来源:EWtoPy.py

示例5: catchup

# 需要导入模块: from pywws import DataStore [as 别名]
# 或者: from pywws.DataStore import safestrptime [as 别名]
 def catchup(self, last_date, last_ptr):
     fixed_block = self.ws.get_fixed_block(unbuffered=True)
     # get time to go back to
     last_stored = self.raw_data.before(datetime.max)
     if not last_stored:
         last_stored = datetime.min
     if self.status.get('data', 'ptr'):
         saved_ptr, saved_date = self.status.get('data', 'ptr').split(',')
         saved_ptr = int(saved_ptr, 16)
         saved_date = DataStore.safestrptime(saved_date)
         saved_date = self.raw_data.nearest(saved_date)
         while saved_date < last_stored:
             saved_date = self.raw_data.after(saved_date + SECOND)
             saved_ptr = self.ws.inc_ptr(saved_ptr)
     else:
         saved_ptr = None
         saved_date = None
     last_stored += timedelta(seconds=fixed_block['read_period'] * 30)
     if last_date <= last_stored:
         # nothing to do
         return
     self.status.set(
         'data', 'ptr', '%06x,%s' % (last_ptr, last_date.isoformat(' ')))
     # data_count includes record currently being updated every 48 seconds
     max_count = fixed_block['data_count'] - 1
     count = 0
     duplicates = []
     while last_date > last_stored and count < max_count:
         data = self.ws.get_data(last_ptr)
         if last_ptr == saved_ptr:
             if any(data[key] != self.raw_data[saved_date][key] for key in (
                     'hum_in', 'temp_in', 'hum_out', 'temp_out',
                     'abs_pressure', 'wind_ave', 'wind_gust', 'wind_dir',
                     'rain', 'status')):
                 # pointer matches but data is different, so no duplicates
                 duplicates = None
                 saved_ptr = None
                 saved_date = None
             else:
                 # potential duplicate data
                 duplicates.append(last_date)
                 saved_date = self.raw_data.before(saved_date)
                 saved_ptr = self.ws.dec_ptr(saved_ptr)
         if (data['delay'] is None or
                 data['delay'] > max(fixed_block['read_period'] * 2, 35)):
             self.logger.error('invalid data at %04x, %s',
                               last_ptr, last_date.isoformat(' '))
             last_date -= timedelta(minutes=fixed_block['read_period'])
         else:
             self.raw_data[last_date] = data
             count += 1
             last_date -= timedelta(minutes=data['delay'])
         last_ptr = self.ws.dec_ptr(last_ptr)
     if duplicates:
         for d in duplicates:
             del self.raw_data[d]
         count -= len(duplicates)
     last_date = self.raw_data.nearest(last_date)
     next_date = self.raw_data.after(last_date + SECOND)
     if next_date:
         gap = (next_date - last_date).seconds // 60
         gap -= fixed_block['read_period']
         if gap > 0:
             self.logger.critical("%d minutes gap in data detected", gap)
     self.logger.info("%d catchup records", count)
开发者ID:hydrogeog,项目名称:pywws,代码行数:67,代码来源:LogData.py

示例6: process

# 需要导入模块: from pywws import DataStore [as 别名]
# 或者: from pywws.DataStore import safestrptime [as 别名]

#.........这里部分代码省略.........
                        if round_time:
                            x += round_time
                        x = x.replace(tzinfo=utc)
                        x = x.astimezone(time_zone)
                    # convert data
                    if x is not None and len(command) > 3:
                        x = eval(command[3])
                    # get format
                    fmt = u'%s'
                    if len(command) > 1:
                        fmt = command[1]
                    # write output
                    if x is None:
                        if len(command) > 2:
                            yield command[2]
                    elif isinstance(x, datetime):
                        if sys.version_info[0] < 3:
                            fmt = fmt.encode(file_encoding)
                        x = x.strftime(fmt)
                        if sys.version_info[0] < 3:
                            x = x.decode(file_encoding)
                        yield x
                    elif not use_locale:
                        yield fmt % (x)
                    elif sys.version_info >= (2, 7) or '%%' not in fmt:
                        yield locale.format_string(fmt, x)
                    else:
                        yield locale.format_string(
                            fmt.replace('%%', '##'), x).replace('##', '%')
                elif command[0] == 'monthly':
                    data_set = self.monthly_data
                    idx, valid_data = jump(datetime.max, -1)
                    data = data_set[idx]
                elif command[0] == 'daily':
                    data_set = self.daily_data
                    idx, valid_data = jump(datetime.max, -1)
                    data = data_set[idx]
                elif command[0] == 'hourly':
                    data_set = self.hourly_data
                    idx, valid_data = jump(datetime.max, -1)
                    data = data_set[idx]
                elif command[0] == 'raw':
                    data_set = self.calib_data
                    idx, valid_data = jump(datetime.max, -1)
                    data = data_set[idx]
                elif command[0] == 'live':
                    data_set = self.calib_data
                    idx = datetime.max
                    valid_data = True
                    data = live_data
                elif command[0] == 'timezone':
                    if command[1] == 'utc':
                        time_zone = utc
                    elif command[1] == 'local':
                        time_zone = Local
                    else:
                        self.logger.error("Unknown time zone: %s", command[1])
                        return
                elif command[0] == 'locale':
                    use_locale = eval(command[1])
                elif command[0] == 'encoding':
                    self.encoding = command[1]
                    file_encoding = self.encoding
                    if file_encoding == 'html':
                        file_encoding = 'ascii'
                elif command[0] == 'roundtime':
                    if eval(command[1]):
                        round_time = timedelta(seconds=30)
                    else:
                        round_time = None
                elif command[0] == 'jump':
                    prevdata = data
                    idx, valid_data = jump(idx, int(command[1]))
                    data = data_set[idx]
                elif command[0] == 'goto':
                    prevdata = data
                    time_str = command[1]
                    if '%' in time_str:
                        lcl = idx.replace(tzinfo=utc).astimezone(time_zone)
                        time_str = lcl.strftime(time_str)
                    new_idx = DataStore.safestrptime(time_str)
                    new_idx = new_idx.replace(tzinfo=time_zone).astimezone(utc)
                    new_idx = data_set.after(new_idx.replace(tzinfo=None))
                    if new_idx:
                        idx = new_idx
                        data = data_set[idx]
                        valid_data = True
                    else:
                        valid_data = False
                elif command[0] == 'loop':
                    loop_count = int(command[1])
                    loop_start = tmplt.tell()
                elif command[0] == 'endloop':
                    loop_count -= 1
                    if valid_data and loop_count > 0:
                        tmplt.seek(loop_start, 0)
                else:
                    self.logger.error(
                        "Unknown processing directive: #%s#", parts[i])
                    return
开发者ID:hydrogeog,项目名称:pywws,代码行数:104,代码来源:Template.py


注:本文中的pywws.DataStore.safestrptime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。