예제 #1
0
    def test_regions(self, ro_session):
        RegionStatFactory(
            session=ro_session, region='DE', gsm=2, wcdma=1, wifi=4)
        RegionStatFactory(session=ro_session, region='GB', wifi=1, blue=1)
        RegionStatFactory(session=ro_session, region='TW', wcdma=1)
        RegionStatFactory(session=ro_session, region='US', gsm=3, blue=2)
        ro_session.flush()

        result = regions(ro_session)
        expected = set(['DE', 'GB', 'TW', 'US'])
        assert set([r['code'] for r in result]) == expected

        region_results = {}
        for r in result:
            code = r['code']
            region_results[code] = r
            del region_results[code]['code']

        # ensure we use GENC names
        assert region_results['TW']['name'] == 'Taiwan'

        # strip out names to make assertion statements shorter
        for code in region_results:
            del region_results[code]['name']

        assert (region_results['DE'] ==
                {'gsm': 2, 'wcdma': 1, 'lte': 0, 'cell': 3,
                 'blue': 0, 'wifi': 4, 'order': 'germany'})
        assert (region_results['GB'] ==
                {'gsm': 0, 'wcdma': 0, 'lte': 0, 'cell': 0,
                 'blue': 1, 'wifi': 1, 'order': 'united kin'})
        assert (region_results['US'] ==
                {'gsm': 3, 'wcdma': 0, 'lte': 0, 'cell': 3,
                 'blue': 2, 'wifi': 0, 'order': 'united sta'})
예제 #2
0
    def test_regions(self):
        RegionStatFactory(region='DE', gsm=2, wcdma=1, wifi=4)
        RegionStatFactory(region='GB', wifi=1)
        RegionStatFactory(region='TW', wcdma=1)
        RegionStatFactory(region='US', gsm=3)
        self.session.flush()

        result = regions(self.session)
        expected = set(['DE', 'GB', 'TW', 'US'])
        self.assertEqual(set([r['code'] for r in result]), expected)

        region_results = {}
        for r in result:
            code = r['code']
            region_results[code] = r
            del region_results[code]['code']

        # ensure we use GENC names
        self.assertEqual(region_results['TW']['name'], 'Taiwan')

        # strip out names to make assertion statements shorter
        for code in region_results:
            del region_results[code]['name']

        self.assertEqual(region_results['DE'],
                         {'gsm': 2, 'wcdma': 1, 'lte': 0, 'cell': 3,
                          'wifi': 4, 'order': 'germany'})
        self.assertEqual(region_results['GB'],
                         {'gsm': 0, 'wcdma': 0, 'lte': 0, 'cell': 0,
                          'wifi': 1, 'order': 'united kin'})
        self.assertEqual(region_results['US'],
                         {'gsm': 3, 'wcdma': 0, 'lte': 0, 'cell': 3,
                          'wifi': 0, 'order': 'united sta'})
    def test_regions(self, session):
        RegionStatFactory(region='DE', gsm=2, wcdma=1, wifi=4)
        RegionStatFactory(region='GB', wifi=1, blue=1)
        RegionStatFactory(region='TW', wcdma=1)
        RegionStatFactory(region='US', gsm=3, blue=2)
        session.flush()

        result = regions(session)
        expected = set(['DE', 'GB', 'TW', 'US'])
        assert set([r['code'] for r in result]) == expected

        region_results = {}
        for r in result:
            code = r['code']
            region_results[code] = r
            del region_results[code]['code']

        # ensure we use GENC names
        assert region_results['TW']['name'] == 'Taiwan'

        # strip out names to make assertion statements shorter
        for code in region_results:
            del region_results[code]['name']

        assert (region_results['DE'] ==
                {'gsm': 2, 'wcdma': 1, 'lte': 0, 'cell': 3,
                 'blue': 0, 'wifi': 4, 'order': 'germany'})
        assert (region_results['GB'] ==
                {'gsm': 0, 'wcdma': 0, 'lte': 0, 'cell': 0,
                 'blue': 1, 'wifi': 1, 'order': 'united kin'})
        assert (region_results['US'] ==
                {'gsm': 3, 'wcdma': 0, 'lte': 0, 'cell': 3,
                 'blue': 2, 'wifi': 0, 'order': 'united sta'})
예제 #4
0
    def test_regions(self):
        cell_key = {'lac': 1, 'cid': 1}
        test_data = [
            Cell(radio=Radio.gsm, mcc=1, mnc=1, **cell_key),
            Cell(radio=Radio.lte, mcc=262, mnc=1, **cell_key),
            Cell(radio=Radio.gsm, mcc=310, mnc=1, **cell_key),
            Cell(radio=Radio.gsm, mcc=310, mnc=2, **cell_key),
            Cell(radio=Radio.gsm, mcc=313, mnc=1, **cell_key),
            Cell(radio=Radio.cdma, mcc=310, mnc=1, **cell_key),
            Cell(radio=Radio.umts, mcc=244, mnc=1, **cell_key),
            Cell(radio=Radio.lte, mcc=244, mnc=1, **cell_key),
            Cell(radio=Radio.gsm, mcc=466, mnc=3, **cell_key),
        ]
        self.session.add_all(test_data)
        self.session.commit()

        # check the result
        expected = set(['AX', 'BM', 'DE', 'FI', 'GU', 'PR', 'TW', 'US'])
        result = regions(self.session)
        self.assertEqual(len(result), len(expected))
        self.assertEqual(set([r['code'] for r in result]), expected)

        region_results = {}
        for r in result:
            code = r['code']
            region_results[code] = r
            del region_results[code]['code']

        # ensure we use apolitical names
        self.assertEqual(region_results['TW']['name'], 'Taiwan')

        # strip out names to make assertion statements shorter
        for code in region_results:
            del region_results[code]['name']

        # a simple case with a 1:1 mapping of mcc to ISO code
        self.assertEqual(region_results['DE'],
                         {'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 1,
                          'umts': 0, 'multiple': False, 'order': 'germany'})

        # mcc 310 is valid for both GU/US, 313 only for US
        self.assertEqual(region_results['US'],
                         {'cdma': 1, 'gsm': 3, 'lte': 0, 'total': 4,
                          'umts': 0, 'multiple': True, 'order': 'united sta'})
        self.assertEqual(region_results['GU'],
                         {'cdma': 1, 'gsm': 2, 'lte': 0, 'total': 3,
                          'umts': 0, 'multiple': True, 'order': 'guam'})

        # These two regions share a mcc, so we report the same data
        # for both of them
        self.assertEqual(region_results['FI'],
                         {'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 2,
                          'umts': 1, 'multiple': True, 'order': 'finland'})
        self.assertEqual(region_results['AX'],
                         {'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 2,
                          'umts': 1, 'multiple': True, 'order': 'aland isla'})
예제 #5
0
파일: views.py 프로젝트: angelotex/ichnaea
    def stats_regions_view(self):
        redis_client = self.request.registry.redis_client
        cache_key = redis_client.cache_keys['stats_regions']
        cached = redis_client.get(cache_key)
        if cached:
            data = internal_loads(cached)
        else:
            session = self.request.db_ro_session
            data = regions(session)
            redis_client.set(cache_key, internal_dumps(data), ex=3600)

        return {'page_title': 'Region Statistics', 'metrics': data}
예제 #6
0
    def stats_regions_view(self):
        redis_client = self.request.registry.redis_client
        cache_key = redis_client.cache_keys['stats_regions']
        cached = redis_client.get(cache_key)
        if cached:
            data = internal_loads(cached)
        else:
            session = self.request.db_ro_session
            data = regions(session)
            redis_client.set(cache_key, internal_dumps(data), ex=3600)

        return {'page_title': 'Region Statistics', 'metrics': data}
예제 #7
0
파일: views.py 프로젝트: SOFTowaha/ichnaea
    def stats_regions_view(self):
        redis_client = self.request.registry.redis_client
        cache_key = CACHE_KEYS['stats_regions']
        cached = redis_client.get(cache_key)
        if cached:
            data = loads(cached)
        else:
            session = self.request.db_ro_session
            data = regions(session)
            redis_client.set(cache_key, dumps(data), ex=3600)

        return {'page_title': 'Cell Statistics', 'metrics': data}
예제 #8
0
    def test_regions(self, session):
        RegionStatFactory(region="DE", gsm=2, wcdma=1, wifi=4)
        RegionStatFactory(region="GB", wifi=1, blue=1)
        RegionStatFactory(region="TW", wcdma=1)
        RegionStatFactory(region="US", gsm=3, blue=2)
        session.flush()

        result = regions(session)
        expected = set(["DE", "GB", "TW", "US"])
        assert set([r["code"] for r in result]) == expected

        region_results = {}
        for r in result:
            code = r["code"]
            region_results[code] = r
            del region_results[code]["code"]

        # ensure we use GENC names
        assert region_results["TW"]["name"] == "Taiwan"

        # strip out names to make assertion statements shorter
        for code in region_results:
            del region_results[code]["name"]

        assert region_results["DE"] == {
            "gsm": 2,
            "wcdma": 1,
            "lte": 0,
            "cell": 3,
            "blue": 0,
            "wifi": 4,
            "order": "germany",
        }
        assert region_results["GB"] == {
            "gsm": 0,
            "wcdma": 0,
            "lte": 0,
            "cell": 0,
            "blue": 1,
            "wifi": 1,
            "order": "united kin",
        }
        assert region_results["US"] == {
            "gsm": 3,
            "wcdma": 0,
            "lte": 0,
            "cell": 3,
            "blue": 2,
            "wifi": 0,
            "order": "united sta",
        }
예제 #9
0
파일: views.py 프로젝트: jwhitlock/ichnaea
 def stats_regions_view(self):
     data = self._get_cache("stats_regions")
     if data is None:
         data = regions(self.session)
         self._set_cache("stats_regions", data)
     return {"page_title": "Regions", "metrics": data}
예제 #10
0
 def stats_regions_view(self):
     data = self._get_cache('stats_regions')
     if data is None:
         data = regions(self.session)
         self._set_cache('stats_regions', data)
     return {'page_title': 'Region Statistics', 'metrics': data}
예제 #11
0
 def stats_regions_view(self):
     data = self._get_cache('stats_regions')
     if data is None:
         data = regions(self.session)
         self._set_cache('stats_regions', data)
     return {'page_title': 'Region Statistics', 'metrics': data}