【发布时间】:2015-02-07 09:17:15
【问题描述】:
我正在处理事件数据(在本例中为 USGS 地震)。美国地质调查局给你例如所有地震的最后一小时或最后一天以及每隔几分钟列出的更新。 我需要每分钟轮询该列表并对该列表中的新事件采取行动,但忽略我已采取行动的那些。
我可以轻松地创建一个列表,向其中添加新的地震事件:
events = list()
for f in features:
event = [{
'name': 'usgs.earthquake.feature', # Time Series Name
'columns': ['id', 'long', 'lat', 'depth', 'mag', 'type'\
'magtype', 'tz', 'felt', 'place', 'status'\
'gap', 'dmin', 'rms', 'ids', 'title', 'types'\
'cdi', 'net', 'nst', 'sources', 'alert', 'time'\
'tsunami', 'code', 'sig'
], # Keys
'points': [[ f['id'],\
f['geometry']['coordinates'][0],\
f['geometry']['coordinates'][1],\
f['geometry']['coordinates'][2],\
f['properties']['mag'],\
f['properties']['type'],\
f['properties']['magType'],\
f['properties']['tz'],\
...
f['properties']['time'],\
f['properties']['tsunami'],\
f['properties']['code'],\
f['properties']['sig']
]] # Data points
}]
if event in events:
log.debug('Surpressing duplicate event id: %s', event[0]['points'][0][0])
else:
log.debug('Event data: %s', event)
events.insert(0, event)
handler.postEvent(event)
log.debug('Event Cache Count: %s', len(events))
这是一种聪明的方法 - 通过这样的列表构建查找? 我如何最好地保留列表中过去 2 小时或 36 小时的数据,同时丢弃旧的整体?
【问题讨论】:
标签: python arrays list caching dictionary