예제 #1
0
    def test_local_import_delta(self):
        old_time = 1407000000
        new_time = 1408000000
        old_date = datetime.fromtimestamp(old_time).replace(tzinfo=UTC)
        new_date = datetime.fromtimestamp(new_time).replace(tzinfo=UTC)
        today = util.utcnow().date()

        self.import_csv(time=old_time)
        cells = self.session.query(OCIDCell).all()
        self.assertEqual(len(cells), 9)
        update_statcounter.delay(ago=0).get()
        stat_key = Stat.to_hashkey(key=StatKey.unique_ocid_cell, time=today)
        self.assertEqual(Stat.getkey(self.session, stat_key).value, 9)

        lacs = set([
            (cell.radio, cell.mcc, cell.mnc, cell.lac) for cell in cells])
        self.assertEqual(
            self.session.query(OCIDCellArea).count(), len(lacs))

        # update some entries
        self.import_csv(lo=5, hi=13, time=new_time)
        self.session.commit()

        cells = (self.session.query(OCIDCell)
                             .order_by(OCIDCell.modified).all())
        self.assertEqual(len(cells), 12)

        for i in range(0, 4):
            self.assertEqual(cells[i].modified, old_date)

        for i in range(4, 12):
            self.assertEqual(cells[i].modified, new_date)

        lacs = set([
            (cell.radio, cell.mcc, cell.mnc, cell.lac) for cell in cells])
        self.assertEqual(
            self.session.query(OCIDCellArea).count(), len(lacs))

        update_statcounter.delay(ago=0).get()
        stat_key = Stat.to_hashkey(key=StatKey.unique_ocid_cell, time=today)
        self.assertEqual(Stat.getkey(self.session, stat_key).value, 12)
예제 #2
0
    def test_local_import(self):
        self.import_csv()
        cells = self.session.query(OCIDCell).all()
        self.assertEqual(len(cells), 9)

        lacs = set([
            (cell.radio, cell.mcc, cell.mnc, cell.lac) for cell in cells])
        self.assertEqual(
            self.session.query(OCIDCellArea).count(), len(lacs))

        update_statcounter.delay(ago=0).get()
        today = util.utcnow().date()
        stat_key = Stat.to_hashkey(key=StatKey.unique_ocid_cell, time=today)
        self.assertEqual(Stat.getkey(self.session, stat_key).value, 9)
예제 #3
0
파일: stats.py 프로젝트: voolitels/ichnaea
    def update_key(self, stat_key, day):
        # determine the value from the day before
        query = (self.session.query(Stat)
                             .filter(Stat.key == stat_key)
                             .filter(Stat.time < day)
                             .order_by(Stat.time.desc()))
        before = query.first()
        old_value = 0
        if before:
            old_value = before.value

        # get the value from redis for the day in question
        stat_counter = StatCounter(stat_key, day)
        value = stat_counter.get(self.redis_client)

        # insert or update a new stat value
        hashkey = Stat.to_hashkey(key=stat_key, time=day)
        Stat.incr(self.session, hashkey, value, old=old_value)

        # queue the redis value to be decreased
        stat_counter.decr(self.pipe, value)
예제 #4
0
 def check_stat(self, stat_key, time, value):
     hashkey = Stat.to_hashkey(key=stat_key, time=time)
     stat = Stat.getkey(self.session, hashkey)
     self.assertEqual(stat.value, value)