Exemplo n.º 1
0
    def stats_view(self):
        redis_client = self.request.registry.redis_client
        cache_key = redis_client.cache_keys['stats']
        cached = redis_client.get(cache_key)
        if cached:
            data = internal_loads(cached)
        else:
            session = self.request.db_ro_session
            data = {
                'leaders': [],
                'metrics1': [],
                'metrics2': [],
            }
            metrics = global_stats(session)
            metric_names = [
                (StatKey.unique_cell.name, 'MLS Cells'),
                (StatKey.unique_cell_ocid.name, 'OpenCellID Cells'),
                (StatKey.cell.name, 'MLS Cell Observations'),
                (StatKey.unique_wifi.name, 'Wifi Networks'),
                (StatKey.wifi.name, 'Wifi Observations'),
            ]
            for mid, name in metric_names[:3]:
                data['metrics1'].append({'name': name, 'value': metrics[mid]})
            for mid, name in metric_names[3:]:
                data['metrics2'].append({'name': name, 'value': metrics[mid]})
            redis_client.set(cache_key, internal_dumps(data), ex=3600)

        result = {'page_title': 'Statistics'}
        result.update(data)
        return result
Exemplo n.º 2
0
    def stats_view(self):
        redis_client = self.request.registry.redis_client
        cache_key = CACHE_KEYS['stats']
        cached = redis_client.get(cache_key)
        if cached:
            data = loads(cached)
        else:
            session = self.request.db_ro_session
            data = {
                'leaders': [],
                'metrics1': [],
                'metrics2': [],
            }
            metrics = global_stats(session)
            metric_names = [
                (StatKey.unique_cell.name, 'MLS Cells'),
                (StatKey.unique_ocid_cell.name, 'OpenCellID Cells'),
                (StatKey.cell.name, 'MLS Cell Observations'),
                (StatKey.unique_wifi.name, 'Wifi Networks'),
                (StatKey.wifi.name, 'Wifi Observations'),
            ]
            for mid, name in metric_names[:3]:
                data['metrics1'].append({'name': name, 'value': metrics[mid]})
            for mid, name in metric_names[3:]:
                data['metrics2'].append({'name': name, 'value': metrics[mid]})
            redis_client.set(cache_key, dumps(data), ex=3600)

        result = {'page_title': 'Statistics'}
        result.update(data)
        return result
Exemplo n.º 3
0
    def stats_view(self):
        redis_client = self.request.registry.redis_client
        cache_key = CACHE_KEYS['stats']
        cached = redis_client.get(cache_key)
        if cached:
            data = loads(cached)
        else:
            session = self.request.db_slave_session
            data = {
                'leaders': [],
                'metrics1': [],
                'metrics2': [],
            }
            metrics = global_stats(session)
            metric_names = [
                ('unique_cell', 'Unique Cells'),
                ('cell', 'Cell Observations'),
                ('unique_wifi', 'Unique Wifi Networks'),
                ('wifi', 'Wifi Observations'),
            ]
            for mid, name in metric_names[:2]:
                data['metrics1'].append({'name': name, 'value': metrics[mid]})
            for mid, name in metric_names[2:]:
                data['metrics2'].append({'name': name, 'value': metrics[mid]})
            redis_client.set(cache_key, dumps(data), ex=3600)

        result = {'page_title': 'Statistics'}
        result.update(data)
        return result
Exemplo n.º 4
0
 def stats_view(self):
     session = self.request.db_slave_session
     result = {'leaders': [], 'metrics': [], 'page_title': 'Statistics'}
     metrics = global_stats(session)
     metric_names = [
         ('unique_cell', 'Unique Cells'),
         ('cell', 'Cell Observations'),
         ('unique_wifi', 'Unique Wifi Networks'),
         ('wifi', 'Wifi Observations'),
     ]
     for mid, name in metric_names:
         result['metrics'].append({'name': name, 'value': metrics[mid]})
     return result
Exemplo n.º 5
0
 def stats_view(self):
     session = self.request.db_slave_session
     result = {"leaders": [], "metrics": [], "page_title": "Statistics"}
     metrics = global_stats(session)
     metric_names = [
         ("unique_cell", "Unique Cells"),
         ("cell", "Cell Observations"),
         ("unique_wifi", "Unique Wifi Networks"),
         ("wifi", "Wifi Observations"),
     ]
     for mid, name in metric_names:
         result["metrics"].append({"name": name, "value": metrics[mid]})
     return result
Exemplo n.º 6
0
 def stats_view(self):
     session = self.request.db_slave_session
     result = {'leaders': [], 'metrics': [], 'page_title': 'Statistics'}
     metrics = global_stats(session)
     metric_names = [
         ('unique_cell', 'Unique Cells'),
         ('cell', 'Cell Observations'),
         ('unique_wifi', 'Unique Wifi Networks'),
         ('wifi', 'Wifi Observations'),
     ]
     for mid, name in metric_names:
         result['metrics'].append({'name': name, 'value': metrics[mid]})
     return result
Exemplo n.º 7
0
    def test_global_stats(self):
        from ichnaea.content.stats import global_stats
        session = self.db_master_session
        day = datetime.utcnow().date() - timedelta(1)
        stats = [
            Stat(key=STAT_TYPE['location'], time=day, value=3),
            Stat(key=STAT_TYPE['cell'], time=day, value=6),
            Stat(key=STAT_TYPE['wifi'], time=day, value=3),
            Stat(key=STAT_TYPE['unique_cell'], time=day, value=3),
            Stat(key=STAT_TYPE['unique_wifi'], time=day, value=2),
        ]
        session.add_all(stats)
        session.commit()

        result = global_stats(session)
        self.assertDictEqual(result, {'location': 3, 'cell': 6,
                             'unique_cell': 3, 'wifi': 3, 'unique_wifi': 2})
Exemplo n.º 8
0
    def test_global_stats(self):
        session = self.db_master_session
        day = util.utcnow().date() - timedelta(1)
        stats = [
            Stat(key=STAT_TYPE['cell'], time=day, value=6100000),
            Stat(key=STAT_TYPE['wifi'], time=day, value=3212000),
            Stat(key=STAT_TYPE['unique_cell'], time=day, value=3289900),
            Stat(key=STAT_TYPE['unique_wifi'], time=day, value=2009000),
        ]
        session.add_all(stats)
        session.commit()

        result = global_stats(session)
        self.assertDictEqual(
            result, {
                'cell': '6.10', 'unique_cell': '3.28',
                'wifi': '3.21', 'unique_wifi': '2.00'
            })
    def test_global_stats_missing_today(self, session):
        day = util.utcnow().date() - timedelta(1)
        yesterday = day - timedelta(days=1)
        stats = [
            Stat(key=StatKey.cell, time=yesterday, value=5000000),
            Stat(key=StatKey.cell, time=day, value=6000000),
            Stat(key=StatKey.wifi, time=day, value=3000000),
            Stat(key=StatKey.unique_cell, time=yesterday, value=4000000),
        ]
        session.add_all(stats)
        session.commit()

        result = global_stats(session)
        assert (result == {
            'blue': '0.00', 'unique_blue': '0.00',
            'cell': '6.00', 'unique_cell': '4.00',
            'wifi': '3.00', 'unique_wifi': '0.00',
        })
    def test_global_stats(self, session):
        day = util.utcnow().date() - timedelta(1)
        stats = [
            Stat(key=StatKey.blue, time=day, value=2200000),
            Stat(key=StatKey.cell, time=day, value=6100000),
            Stat(key=StatKey.wifi, time=day, value=3212000),
            Stat(key=StatKey.unique_blue, time=day, value=1100000),
            Stat(key=StatKey.unique_cell, time=day, value=3289900),
            Stat(key=StatKey.unique_wifi, time=day, value=2009000),
        ]
        session.add_all(stats)
        session.commit()

        result = global_stats(session)
        assert (result == {
            'blue': '2.20', 'unique_blue': '1.10',
            'cell': '6.10', 'unique_cell': '3.28',
            'wifi': '3.21', 'unique_wifi': '2.00',
        })
Exemplo n.º 11
0
    def test_global_stats_missing_today(self):
        session = self.db_master_session
        day = util.utcnow().date() - timedelta(1)
        yesterday = day - timedelta(days=1)
        stats = [
            Stat(key=STAT_TYPE['cell'], time=yesterday, value=5000000),
            Stat(key=STAT_TYPE['cell'], time=day, value=6000000),
            Stat(key=STAT_TYPE['wifi'], time=day, value=3000000),
            Stat(key=STAT_TYPE['unique_cell'], time=yesterday, value=4000000),
        ]
        session.add_all(stats)
        session.commit()

        result = global_stats(session)
        self.assertDictEqual(
            result, {
                'cell': '6.00', 'unique_cell': '4.00',
                'wifi': '3.00', 'unique_wifi': '0.00'
            })
Exemplo n.º 12
0
    def test_global_stats(self):
        from ichnaea.content.stats import global_stats

        session = self.db_master_session
        day = datetime.utcnow().date() - timedelta(1)
        stats = [
            Stat(key=STAT_TYPE["location"], time=day, value=35412000),
            Stat(key=STAT_TYPE["cell"], time=day, value=6100000),
            Stat(key=STAT_TYPE["wifi"], time=day, value=3212000),
            Stat(key=STAT_TYPE["unique_cell"], time=day, value=3289900),
            Stat(key=STAT_TYPE["unique_wifi"], time=day, value=2009000),
        ]
        session.add_all(stats)
        session.commit()

        result = global_stats(session)
        self.assertDictEqual(
            result, {"location": "35.41", "cell": "6.10", "unique_cell": "3.28", "wifi": "3.21", "unique_wifi": "2.00"}
        )
Exemplo n.º 13
0
    def test_global_stats(self):
        session = self.session
        day = util.utcnow().date() - timedelta(1)
        stats = [
            Stat(key=StatKey.cell, time=day, value=6100000),
            Stat(key=StatKey.wifi, time=day, value=3212000),
            Stat(key=StatKey.unique_cell, time=day, value=3289900),
            Stat(key=StatKey.unique_cell_ocid, time=day, value=1523000),
            Stat(key=StatKey.unique_wifi, time=day, value=2009000),
        ]
        session.add_all(stats)
        session.commit()

        result = global_stats(session)
        self.assertDictEqual(
            result, {
                'cell': '6.10', 'unique_cell': '3.28',
                'wifi': '3.21', 'unique_wifi': '2.00',
                'unique_cell_ocid': '1.52',
            })
Exemplo n.º 14
0
    def test_global_stats_missing_today(self):
        from ichnaea.content.stats import global_stats

        session = self.db_master_session
        day = datetime.utcnow().date() - timedelta(1)
        yesterday = day - timedelta(days=1)
        stats = [
            Stat(key=STAT_TYPE["location"], time=yesterday, value=2000000),
            Stat(key=STAT_TYPE["location"], time=day, value=3000000),
            Stat(key=STAT_TYPE["cell"], time=day, value=6000000),
            Stat(key=STAT_TYPE["wifi"], time=day, value=3000000),
            Stat(key=STAT_TYPE["unique_cell"], time=yesterday, value=3000000),
        ]
        session.add_all(stats)
        session.commit()

        result = global_stats(session)
        self.assertDictEqual(
            result, {"location": "3.00", "cell": "6.00", "unique_cell": "3.00", "wifi": "3.00", "unique_wifi": "0.00"}
        )
Exemplo n.º 15
0
    def stats_view(self):
        data = self._get_cache("stats")
        if data is None:
            data = {"metrics1": [], "metrics2": []}
            metric_names = [
                ("1", StatKey.unique_blue.name, "Bluetooth Networks"),
                ("1", StatKey.blue.name, "Bluetooth Observations"),
                ("1", StatKey.unique_wifi.name, "Wifi Networks"),
                ("1", StatKey.wifi.name, "Wifi Observations"),
                ("2", StatKey.unique_cell.name, "MLS Cells"),
                ("2", StatKey.cell.name, "MLS Cell Observations"),
            ]
            metrics = global_stats(self.session)
            for i, mid, name in metric_names:
                data["metrics" + i].append({"name": name, "value": metrics[mid]})
            self._set_cache("stats", data)

        result = {"page_title": "Statistics"}
        result.update(data)
        return result
Exemplo n.º 16
0
    def test_global_stats(self):
        from ichnaea.content.stats import global_stats
        session = self.db_master_session
        day = datetime.utcnow().date() - timedelta(1)
        stats = [
            Stat(key=STAT_TYPE['cell'], time=day, value=6100000),
            Stat(key=STAT_TYPE['wifi'], time=day, value=3212000),
            Stat(key=STAT_TYPE['unique_cell'], time=day, value=3289900),
            Stat(key=STAT_TYPE['unique_wifi'], time=day, value=2009000),
        ]
        session.add_all(stats)
        session.commit()

        result = global_stats(session)
        self.assertDictEqual(
            result, {
                'cell': '6.10',
                'unique_cell': '3.28',
                'wifi': '3.21',
                'unique_wifi': '2.00'
            })
Exemplo n.º 17
0
    def test_global_stats_missing_today(self, session):
        day = util.utcnow().date() - timedelta(1)
        yesterday = day - timedelta(days=1)
        stats = [
            Stat(key=StatKey.cell, time=yesterday, value=5000000),
            Stat(key=StatKey.cell, time=day, value=6000000),
            Stat(key=StatKey.wifi, time=day, value=3000000),
            Stat(key=StatKey.unique_cell, time=yesterday, value=4000000),
        ]
        session.add_all(stats)
        session.commit()

        result = global_stats(session)
        assert result == {
            "blue": "0.00",
            "unique_blue": "0.00",
            "cell": "6.00",
            "unique_cell": "4.00",
            "wifi": "3.00",
            "unique_wifi": "0.00",
        }
    def stats_view(self):
        data = self._get_cache('stats')
        if data is None:
            data = {'metrics1': [], 'metrics2': []}
            metric_names = [
                ('1', StatKey.unique_blue.name, 'Bluetooth Networks'),
                ('1', StatKey.blue.name, 'Bluetooth Observations'),
                ('1', StatKey.unique_wifi.name, 'Wifi Networks'),
                ('1', StatKey.wifi.name, 'Wifi Observations'),
                ('2', StatKey.unique_cell.name, 'MLS Cells'),
                ('2', StatKey.cell.name, 'MLS Cell Observations'),
            ]
            metrics = global_stats(self.session)
            for i, mid, name in metric_names:
                data['metrics' + i].append(
                    {'name': name, 'value': metrics[mid]})
            self._set_cache('stats', data)

        result = {'page_title': 'Statistics'}
        result.update(data)
        return result
Exemplo n.º 19
0
    def test_global_stats_missing_today(self):
        from ichnaea.content.stats import global_stats
        session = self.db_master_session
        day = datetime.utcnow().date() - timedelta(1)
        yesterday = day - timedelta(days=1)
        stats = [
            Stat(key=STAT_TYPE['cell'], time=yesterday, value=5000000),
            Stat(key=STAT_TYPE['cell'], time=day, value=6000000),
            Stat(key=STAT_TYPE['wifi'], time=day, value=3000000),
            Stat(key=STAT_TYPE['unique_cell'], time=yesterday, value=4000000),
        ]
        session.add_all(stats)
        session.commit()

        result = global_stats(session)
        self.assertDictEqual(
            result, {
                'cell': '6.00',
                'unique_cell': '4.00',
                'wifi': '3.00',
                'unique_wifi': '0.00'
            })
Exemplo n.º 20
0
    def test_global_stats(self, session):
        day = util.utcnow().date() - timedelta(1)
        stats = [
            Stat(key=StatKey.blue, time=day, value=2200000),
            Stat(key=StatKey.cell, time=day, value=6100000),
            Stat(key=StatKey.wifi, time=day, value=3212000),
            Stat(key=StatKey.unique_blue, time=day, value=1100000),
            Stat(key=StatKey.unique_cell, time=day, value=3289900),
            Stat(key=StatKey.unique_wifi, time=day, value=2009000),
        ]
        session.add_all(stats)
        session.commit()

        result = global_stats(session)
        assert result == {
            "blue": "2.20",
            "unique_blue": "1.10",
            "cell": "6.10",
            "unique_cell": "3.28",
            "wifi": "3.21",
            "unique_wifi": "2.00",
        }
Exemplo n.º 21
0
    def test_global_stats_missing_today(self):
        session = self.db_master_session
        day = util.utcnow().date() - timedelta(1)
        yesterday = day - timedelta(days=1)
        stats = [
            Stat(key=StatKey.cell, time=yesterday, value=5000000),
            Stat(key=StatKey.cell, time=day, value=6000000),
            Stat(key=StatKey.wifi, time=day, value=3000000),
            Stat(key=StatKey.unique_cell, time=yesterday, value=4000000),
        ]
        session.add_all(stats)
        session.commit()

        result = global_stats(session)
        self.assertDictEqual(
            result, {
                'cell': '6.00',
                'unique_cell': '4.00',
                'wifi': '3.00',
                'unique_wifi': '0.00',
                'unique_ocid_cell': '0.00',
            })
Exemplo n.º 22
0
    def test_global_stats(self):
        session = self.db_master_session
        day = util.utcnow().date() - timedelta(1)
        stats = [
            Stat(key=StatKey.cell, time=day, value=6100000),
            Stat(key=StatKey.wifi, time=day, value=3212000),
            Stat(key=StatKey.unique_cell, time=day, value=3289900),
            Stat(key=StatKey.unique_ocid_cell, time=day, value=1523000),
            Stat(key=StatKey.unique_wifi, time=day, value=2009000),
        ]
        session.add_all(stats)
        session.commit()

        result = global_stats(session)
        self.assertDictEqual(
            result, {
                'cell': '6.10',
                'unique_cell': '3.28',
                'wifi': '3.21',
                'unique_wifi': '2.00',
                'unique_ocid_cell': '1.52',
            })
Exemplo n.º 23
0
    def test_global_stats(self):
        from ichnaea.content.stats import global_stats
        session = self.db_master_session
        day = datetime.utcnow().date() - timedelta(1)
        stats = [
            Stat(key=STAT_TYPE['location'], time=day, value=3),
            Stat(key=STAT_TYPE['cell'], time=day, value=6),
            Stat(key=STAT_TYPE['wifi'], time=day, value=3),
            Stat(key=STAT_TYPE['unique_cell'], time=day, value=3),
            Stat(key=STAT_TYPE['unique_wifi'], time=day, value=2),
        ]
        session.add_all(stats)
        session.commit()

        result = global_stats(session)
        self.assertDictEqual(
            result, {
                'location': 3,
                'cell': 6,
                'unique_cell': 3,
                'wifi': 3,
                'unique_wifi': 2
            })