本文整理汇总了Python中pywws.DataStore.live_store方法的典型用法代码示例。如果您正苦于以下问题:Python DataStore.live_store方法的具体用法?Python DataStore.live_store怎么用?Python DataStore.live_store使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pywws.DataStore
的用法示例。
在下文中一共展示了DataStore.live_store方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LiveLog
# 需要导入模块: from pywws import DataStore [as 别名]
# 或者: from pywws.DataStore import live_store [as 别名]
def LiveLog(data_dir):
logger = logging.getLogger('pywws.LiveLog')
params = DataStore.params(data_dir)
status = DataStore.status(data_dir)
# localise application
Localisation.SetApplicationLanguage(params)
# connect to weather station
ws_type = params.get('fixed', 'ws type')
if ws_type:
params.unset('fixed', 'ws type')
params.set('config', 'ws type', ws_type)
ws_type = params.get('config', 'ws type', '1080')
ws = WeatherStation.weather_station(
ws_type=ws_type, params=params, status=status)
fixed_block = CheckFixedBlock(ws, params, status, logger)
# open data file stores
raw_data = DataStore.data_store(data_dir)
live_data = DataStore.live_store(data_dir)
calib_data = DataStore.calib_store(data_dir)
hourly_data = DataStore.hourly_store(data_dir)
daily_data = DataStore.daily_store(data_dir)
monthly_data = DataStore.monthly_store(data_dir)
# create a RegularTasks object
asynch = eval(params.get('config', 'asynchronous', 'False'))
tasks = Tasks.RegularTasks(
params, status, calib_data, hourly_data, daily_data, monthly_data,
asynch=asynch)
# get time of last logged data
last_stored = raw_data.before(datetime.max)
if last_stored == None:
last_stored = datetime.min
if datetime.utcnow() < last_stored:
raise ValueError('Computer time is earlier than last stored data')
last_stored += timedelta(minutes=2)
# get live data
next_hour = datetime.utcnow().replace(
minute=0, second=0, microsecond=0) + Process.HOUR
next_ptr = None
try:
for data, ptr, logged in ws.live_data(
logged_only=(not tasks.has_live_tasks())):
now = data['idx']
live_data[now] = data
if logged:
if ptr == next_ptr:
# data is contiguous with last logged value
raw_data[now] = data
else:
# catch up missing data
Catchup(ws, logger, raw_data, now, ptr)
next_ptr = ws.inc_ptr(ptr)
# process new data
Process.Process(params, status, raw_data, calib_data,
hourly_data, daily_data, monthly_data)
# do tasks
tasks.do_tasks()
if now >= next_hour:
next_hour += Process.HOUR
fixed_block = CheckFixedBlock(ws, params, status, logger)
# save any unsaved data
raw_data.flush()
else:
tasks.do_live(data)
finally:
tasks.stop_thread()
return 0