本文整理汇总了Python中DataStore.safestrptime方法的典型用法代码示例。如果您正苦于以下问题:Python DataStore.safestrptime方法的具体用法?Python DataStore.safestrptime怎么用?Python DataStore.safestrptime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataStore
的用法示例。
在下文中一共展示了DataStore.safestrptime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CheckFixedBlock
# 需要导入模块: import DataStore [as 别名]
# 或者: from DataStore import safestrptime [as 别名]
def CheckFixedBlock(ws, params, logger):
fixed_block = ws.get_fixed_block(unbuffered=True)
if not fixed_block:
return None
# 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('fixed', 'ws type', ws.ws_type)
# store info from fixed block
pressure_offset = fixed_block['rel_pressure'] - fixed_block['abs_pressure']
old_offset = eval(params.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.set('fixed', 'pressure offset', '%g' % (pressure_offset))
params.set('fixed', 'fixed block', str(fixed_block))
params.flush()
return fixed_block
示例2: process
# 需要导入模块: import DataStore [as 别名]
# 或者: from DataStore import safestrptime [as 别名]
#.........这里部分代码省略.........
# get value
if command[0] == 'calc':
x = eval(command[1])
del command[1]
else:
x = data[command[0]]
if command[0] == 'wind_dir' and data['wind_ave'] < 0.3:
x = None
# 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 sys.version_info < (2, 5):
yield fmt % (x)
elif sys.version_info < (2, 7) and '%%' in fmt:
yield locale.format_string(
fmt.replace('%%', '##'), x).replace('##', '%')
else:
yield locale.format_string(fmt, x)
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