예제 #1
0
 def stats_cell_json(self):
     data = self._get_cache('stats_cell_json')
     if data is None:
         mls_data = histogram(self.session, StatKey.unique_cell)
         ocid_data = histogram(self.session, StatKey.unique_cell_ocid)
         data = [
             {'title': 'MLS Cells', 'data': mls_data[0]},
             {'title': 'OCID Cells', 'data': ocid_data[0]},
         ]
         self._set_cache('stats_cell_json', data)
     return {'series': data}
예제 #2
0
파일: test_stats.py 프로젝트: elkos/ichnaea
    def test_histogram(self):
        from ichnaea.content.stats import histogram
        session = self.db_master_session
        today = util.utcnow().date()
        one_day = today - timedelta(days=1)
        two_days = today - timedelta(days=2)
        one_month = today - timedelta(days=35)
        two_months = today - timedelta(days=70)
        long_ago = today - timedelta(days=100)
        stats = [
            Stat(name='cell', time=long_ago, value=40),
            Stat(name='cell', time=two_months, value=50),
            Stat(name='cell', time=one_month, value=60),
            Stat(name='cell', time=two_days, value=70),
            Stat(name='cell', time=one_day, value=80),
            Stat(name='cell', time=today, value=90),
        ]
        session.add_all(stats)
        session.commit()
        result = histogram(session, 'cell', days=90)
        self.assertTrue(
            {'num': 80, 'day': one_day.strftime('%Y-%m-%d')} in result)

        if two_months.month == 12:
            expected = date(two_months.year + 1, 1, 1)
        else:
            expected = date(two_months.year, two_months.month + 1, 1)
        self.assertTrue(
            {'num': 50, 'day': expected.strftime('%Y-%m-%d')} in result)
 def test_histogram_different_stat_name(self, session):
     today = util.utcnow().date()
     session.add(Stat(key=StatKey.unique_cell, time=today, value=9))
     session.commit()
     result = histogram(session, StatKey.unique_cell)
     first_of_month = today.replace(day=1)
     assert result == [[[unixtime(first_of_month), 9]]]
예제 #4
0
    def test_histogram(self):
        session = self.session
        today = util.utcnow().date()
        one_day = today - timedelta(days=1)
        two_days = today - timedelta(days=2)
        one_month = today - timedelta(days=35)
        two_months = today - timedelta(days=70)
        long_ago = today - timedelta(days=100)
        stats = [
            Stat(key=StatKey.cell, time=long_ago, value=40),
            Stat(key=StatKey.cell, time=two_months, value=50),
            Stat(key=StatKey.cell, time=one_month, value=60),
            Stat(key=StatKey.cell, time=two_days, value=70),
            Stat(key=StatKey.cell, time=one_day, value=80),
            Stat(key=StatKey.cell, time=today, value=90),
        ]
        session.add_all(stats)
        session.commit()
        result = histogram(session, StatKey.cell, days=90)
        self.assertTrue(
            [unixtime(one_day), 80] in result[0])

        if two_months.month == 12:
            expected = date(two_months.year + 1, 1, 1)
        else:
            expected = date(two_months.year, two_months.month + 1, 1)
        self.assertTrue(
            [unixtime(expected), 50] in result[0])
예제 #5
0
    def test_histogram(self):
        session = self.db_master_session
        today = util.utcnow().date()
        one_day = today - timedelta(days=1)
        two_days = today - timedelta(days=2)
        one_month = today - timedelta(days=35)
        two_months = today - timedelta(days=70)
        long_ago = today - timedelta(days=100)
        stats = [
            Stat(key=StatKey.cell, time=long_ago, value=40),
            Stat(key=StatKey.cell, time=two_months, value=50),
            Stat(key=StatKey.cell, time=one_month, value=60),
            Stat(key=StatKey.cell, time=two_days, value=70),
            Stat(key=StatKey.cell, time=one_day, value=80),
            Stat(key=StatKey.cell, time=today, value=90),
        ]
        session.add_all(stats)
        session.commit()
        result = histogram(session, StatKey.cell, days=90)
        self.assertTrue([unixtime(one_day), 80] in result[0])

        if two_months.month == 12:
            expected = date(two_months.year + 1, 1, 1)
        else:
            expected = date(two_months.year, two_months.month + 1, 1)
        self.assertTrue([unixtime(expected), 50] in result[0])
예제 #6
0
 def test_histogram_different_stat_name(self, ro_session):
     today = util.utcnow().date()
     ro_session.add(Stat(key=StatKey.unique_cell, time=today, value=9))
     ro_session.commit()
     result = histogram(ro_session, StatKey.unique_cell)
     first_of_month = today.replace(day=1)
     assert result == [[[unixtime(first_of_month), 9]]]
예제 #7
0
파일: views.py 프로젝트: angelotex/ichnaea
 def stats_cell_json(self):
     redis_client = self.request.registry.redis_client
     cache_key = redis_client.cache_keys['stats_cell_json']
     cached = redis_client.get(cache_key)
     if cached:
         data = internal_loads(cached)
     else:
         session = self.request.db_ro_session
         mls_data = histogram(session, StatKey.unique_cell)
         ocid_data = histogram(session, StatKey.unique_cell_ocid)
         data = [
             {'title': 'MLS Cells', 'data': mls_data[0]},
             {'title': 'OCID Cells', 'data': ocid_data[0]},
         ]
         redis_client.set(cache_key, internal_dumps(data), ex=3600)
     return {'series': data}
예제 #8
0
 def stats_cell_json(self):
     redis_client = self.request.registry.redis_client
     cache_key = CACHE_KEYS['stats_cell_json']
     cached = redis_client.get(cache_key)
     if cached:
         data = loads(cached)
     else:
         session = self.request.db_slave_session
         mls_data = histogram(session, 'unique_cell')
         ocid_data = histogram(session, 'unique_ocid_cell')
         data = [
             {'title': 'MLS Cells', 'data': mls_data[0]},
             {'title': 'OCID Cells', 'data': ocid_data[0]},
         ]
         redis_client.set(cache_key, dumps(data), ex=3600)
     return {'series': data}
예제 #9
0
 def stats_cell_json(self):
     redis_client = self.request.registry.redis_client
     cache_key = redis_client.cache_keys['stats_cell_json']
     cached = redis_client.get(cache_key)
     if cached:
         data = internal_loads(cached)
     else:
         session = self.request.db_ro_session
         mls_data = histogram(session, StatKey.unique_cell)
         ocid_data = histogram(session, StatKey.unique_cell_ocid)
         data = [
             {'title': 'MLS Cells', 'data': mls_data[0]},
             {'title': 'OCID Cells', 'data': ocid_data[0]},
         ]
         redis_client.set(cache_key, internal_dumps(data), ex=3600)
     return {'series': data}
예제 #10
0
 def test_histogram(self):
     from ichnaea.content.stats import histogram
     session = self.db_master_session
     today = datetime.utcnow().date()
     one_day = (today - timedelta(1)).strftime('%Y-%m-%d')
     two_days = (today - timedelta(2)).strftime('%Y-%m-%d')
     long_ago = (today - timedelta(25)).strftime('%Y-%m-%d')
     today = today.strftime('%Y-%m-%d')
     stats = [
         Stat(time=long_ago, value=1),
         Stat(time=two_days, value=3),
         Stat(time=one_day, value=7),
         Stat(time=today, value=9),
     ]
     for stat in stats:
         stat.name = 'cell'
     session.add_all(stats)
     session.commit()
     result = histogram(session, 'cell', days=20)
     self.assertEqual(result, [
         {
             'num': 3,
             'day': two_days
         },
         {
             'num': 7,
             'day': one_day
         },
     ])
예제 #11
0
 def stats_cell_json(self):
     data = self._get_cache('stats_cell_json')
     if data is None:
         mls_data = histogram(self.session, StatKey.unique_cell)
         ocid_data = histogram(self.session, StatKey.unique_cell_ocid)
         data = [
             {
                 'title': 'MLS Cells',
                 'data': mls_data[0]
             },
             {
                 'title': 'OCID Cells',
                 'data': ocid_data[0]
             },
         ]
         self._set_cache('stats_cell_json', data)
     return {'series': data}
예제 #12
0
 def test_histogram_different_stat_name(self):
     session = self.session
     day = util.utcnow().date() - timedelta(days=1)
     stat = Stat(key=StatKey.unique_cell, time=day, value=9)
     session.add(stat)
     session.commit()
     result = histogram(session, StatKey.unique_cell)
     self.assertEqual(result, [[[unixtime(day), 9]]])
예제 #13
0
 def test_histogram_different_stat_name(self):
     session = self.db_master_session
     day = util.utcnow().date() - timedelta(days=1)
     stat = Stat(key=StatKey.unique_cell, time=day, value=9)
     session.add(stat)
     session.commit()
     result = histogram(session, StatKey.unique_cell)
     self.assertEqual(result, [[[unixtime(day), 9]]])
예제 #14
0
 def test_histogram_different_stat_name(self):
     session = self.db_master_session
     day = util.utcnow().date() - timedelta(days=1)
     stat = Stat(time=day, value=9)
     stat.name = 'unique_cell'
     session.add(stat)
     session.commit()
     result = histogram(session, 'unique_cell')
     self.assertEqual(result, [[[unixtime(day), 9]]])
예제 #15
0
파일: test_stats.py 프로젝트: elkos/ichnaea
 def test_histogram_different_stat_name(self):
     from ichnaea.content.stats import histogram
     session = self.db_master_session
     day = util.utcnow().date() - timedelta(days=1)
     stat = Stat(time=day, value=9)
     stat.name = 'unique_cell'
     session.add(stat)
     session.commit()
     result = histogram(session, 'unique_cell')
     self.assertEqual(result, [{'num': 9, 'day': day.strftime('%Y-%m-%d')}])
예제 #16
0
 def test_histogram_different_stat_name(self):
     from ichnaea.content.stats import histogram
     session = self.db_master_session
     day = datetime.utcnow().date() - timedelta(1)
     day = day.strftime('%Y-%m-%d')
     stat = Stat(time=day, value=9)
     stat.name = 'unique_cell'
     session.add(stat)
     session.commit()
     result = histogram(session, 'unique_cell')
     self.assertEqual(result, [{'num': 9, 'day': day}])
예제 #17
0
파일: views.py 프로젝트: thebent/ichnaea
 def stats_wifi_json(self):
     redis_client = self.request.registry.redis_client
     cache_key = CACHE_KEYS['stats_wifi_json']
     cached = redis_client.get(cache_key)
     if cached:
         data = loads(cached)
     else:
         session = self.request.db_ro_session
         data = histogram(session, StatKey.unique_wifi)
         redis_client.set(cache_key, dumps(data), ex=3600)
     return {'series': [{'title': 'MLS WiFi', 'data': data[0]}]}
예제 #18
0
파일: views.py 프로젝트: angelotex/ichnaea
 def stats_wifi_json(self):
     redis_client = self.request.registry.redis_client
     cache_key = redis_client.cache_keys['stats_wifi_json']
     cached = redis_client.get(cache_key)
     if cached:
         data = internal_loads(cached)
     else:
         session = self.request.db_ro_session
         data = histogram(session, StatKey.unique_wifi)
         redis_client.set(cache_key, internal_dumps(data), ex=3600)
     return {'series': [{'title': 'MLS WiFi', 'data': data[0]}]}
예제 #19
0
 def stats_wifi_json(self):
     redis_client = self.request.registry.redis_client
     cache_key = CACHE_KEYS['stats_wifi_json']
     cached = redis_client.get(cache_key)
     if cached:
         data = loads(cached)
     else:
         session = self.request.db_slave_session
         data = histogram(session, 'unique_wifi')
         redis_client.set(cache_key, dumps(data), ex=3600)
     return {'series': [{'title': 'MLS WiFi', 'data': data[0]}]}
예제 #20
0
파일: test_stats.py 프로젝트: jamjr/ichnaea
    def test_histogram_different_stat_name(self):
        from ichnaea.content.stats import histogram

        session = self.db_master_session
        day = datetime.utcnow().date() - timedelta(1)
        day = day.strftime("%Y-%m-%d")
        stat = Stat(time=day, value=9)
        stat.name = "unique_cell"
        session.add(stat)
        session.commit()
        result = histogram(session, "unique_cell")
        self.assertEqual(result, [{"num": 9, "day": day}])
예제 #21
0
파일: views.py 프로젝트: walexi/ichnaea
 def stats_cell_json(self):
     redis_client = self.request.registry.redis_client
     cache_key = CACHE_KEYS['stats_cell_json']
     cached = redis_client.get(cache_key)
     if cached:
         data = loads(cached)
     else:
         session = self.request.db_slave_session
         mls_data = histogram(session, 'unique_cell')
         ocid_data = histogram(session, 'unique_ocid_cell')
         data = [
             {
                 'title': 'MLS Cells',
                 'data': mls_data[0]
             },
             {
                 'title': 'OCID Cells',
                 'data': ocid_data[0]
             },
         ]
         redis_client.set(cache_key, dumps(data), ex=3600)
     return {'series': data}
예제 #22
0
파일: test_stats.py 프로젝트: jamjr/ichnaea
    def test_histogram(self):
        from ichnaea.content.stats import histogram

        session = self.db_master_session
        today = datetime.utcnow().date()
        one_day = (today - timedelta(1)).strftime("%Y-%m-%d")
        two_days = (today - timedelta(2)).strftime("%Y-%m-%d")
        long_ago = (today - timedelta(40)).strftime("%Y-%m-%d")
        today = today.strftime("%Y-%m-%d")
        stats = [
            Stat(time=long_ago, value=1),
            Stat(time=two_days, value=3),
            Stat(time=one_day, value=7),
            Stat(time=today, value=9),
        ]
        for stat in stats:
            stat.name = "location"
        session.add_all(stats)
        session.commit()
        result = histogram(session, "location")
        self.assertEqual(result, [{"num": 3, "day": two_days}, {"num": 7, "day": one_day}])
예제 #23
0
 def test_histogram(self):
     from ichnaea.content.stats import histogram
     session = self.db_master_session
     today = datetime.utcnow().date()
     one_day = (today - timedelta(1)).strftime('%Y-%m-%d')
     two_days = (today - timedelta(2)).strftime('%Y-%m-%d')
     long_ago = (today - timedelta(25)).strftime('%Y-%m-%d')
     today = today.strftime('%Y-%m-%d')
     stats = [
         Stat(time=long_ago, value=1),
         Stat(time=two_days, value=3),
         Stat(time=one_day, value=7),
         Stat(time=today, value=9),
     ]
     for stat in stats:
         stat.name = 'cell'
     session.add_all(stats)
     session.commit()
     result = histogram(session, 'cell', days=20)
     self.assertEqual(result, [
         {'num': 3, 'day': two_days},
         {'num': 7, 'day': one_day},
     ])
예제 #24
0
    def test_histogram(self, ro_session):
        today = util.utcnow().date()
        one_day = today - timedelta(days=1)
        two_days = today - timedelta(days=2)
        one_month = today - timedelta(days=35)
        two_months = today - timedelta(days=70)
        long_ago = today - timedelta(days=100)
        stats = [
            Stat(key=StatKey.cell, time=long_ago, value=40),
            Stat(key=StatKey.cell, time=two_months, value=50),
            Stat(key=StatKey.cell, time=one_month, value=60),
            Stat(key=StatKey.cell, time=two_days, value=70),
            Stat(key=StatKey.cell, time=one_day, value=80),
            Stat(key=StatKey.cell, time=today, value=90),
        ]
        ro_session.add_all(stats)
        ro_session.commit()
        result = histogram(ro_session, StatKey.cell, days=90)
        first_of_month = today.replace(day=1)
        assert [unixtime(first_of_month), 90] in result[0]

        expected = date(two_months.year, two_months.month, 1)
        assert [unixtime(expected), 50] in result[0]
    def test_histogram(self, session):
        today = util.utcnow().date()
        one_day = today - timedelta(days=1)
        two_days = today - timedelta(days=2)
        one_month = today - timedelta(days=35)
        two_months = today - timedelta(days=70)
        long_ago = today - timedelta(days=100)
        stats = [
            Stat(key=StatKey.cell, time=long_ago, value=40),
            Stat(key=StatKey.cell, time=two_months, value=50),
            Stat(key=StatKey.cell, time=one_month, value=60),
            Stat(key=StatKey.cell, time=two_days, value=70),
            Stat(key=StatKey.cell, time=one_day, value=80),
            Stat(key=StatKey.cell, time=today, value=90),
        ]
        session.add_all(stats)
        session.commit()
        result = histogram(session, StatKey.cell, days=90)
        first_of_month = today.replace(day=1)
        assert [unixtime(first_of_month), 90] in result[0]

        expected = date(two_months.year, two_months.month, 1)
        assert [unixtime(expected), 50] in result[0]
예제 #26
0
파일: views.py 프로젝트: Ashernor/ichnaea
 def stats_unique_wifi_json(self):
     session = self.request.db_slave_session
     return {'histogram': histogram(session, 'unique_wifi')}
예제 #27
0
 def stats_unique_wifi_json(self):
     session = self.request.db_slave_session
     return {'histogram': histogram(session, 'unique_wifi')}
예제 #28
0
 def stats_location_json(self):
     session = self.request.db_slave_session
     return {'histogram': histogram(session, 'location')}
예제 #29
0
파일: views.py 프로젝트: jwhitlock/ichnaea
 def stats_wifi_json(self):
     data = self._get_cache("stats_wifi_json")
     if data is None:
         data = histogram(self.session, StatKey.unique_wifi)
         self._set_cache("stats_wifi_json", data)
     return {"series": [{"title": "MLS WiFi", "data": data[0]}]}
예제 #30
0
 def stats_wifi_json(self):
     data = self._get_cache('stats_wifi_json')
     if data is None:
         data = histogram(self.session, StatKey.unique_wifi)
         self._set_cache('stats_wifi_json', data)
     return {'series': [{'title': 'MLS WiFi', 'data': data[0]}]}
예제 #31
0
 def stats_unique_wifi_json(self):
     session = self.request.db_slave_session
     return {"histogram": histogram(session, "unique_wifi")}
예제 #32
0
 def stats_wifi_json(self):
     data = self._get_cache('stats_wifi_json')
     if data is None:
         data = histogram(self.session, StatKey.unique_wifi)
         self._set_cache('stats_wifi_json', data)
     return {'series': [{'title': 'MLS WiFi', 'data': data[0]}]}
예제 #33
0
파일: views.py 프로젝트: Ashernor/ichnaea
 def stats_location_json(self):
     session = self.request.db_slave_session
     return {'histogram': histogram(session, 'location')}