def processFile(self, start, span, locfile): """ 排序、时间范围校验 :param start: :param span: :param locfile: :return: """ lines = open(locfile).readlines() lines = map(string.strip, lines) list = map(json.loads, lines) mos = [] for _ in list: mo = MovableObject.unmarshall(_) if not mo: continue loc = mo.getLocation() if loc.time < start or loc.time > start + span: instance.getLogger().warning( 'location time is not in (%s,%s)' % (start, start + span)) continue mos.append(mo) #根据时间排序 mos = sorted( mos, lambda x, y: cmp(x.getLocation().time, y.getLocation().time)) PersistenceManager.instance().write(start, span, mos)
def init(self, cfgs): self.cfgs = cfgs PersistenceManager.instance().init(self.cfgs.get('persistence')) gevent.spawn(self._thread_persist)