def test_countries(self): session = self.session 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), ] session.add_all(test_data) session.commit() # check the result expected = set(['AX', 'BM', 'DE', 'FI', 'GU', 'PR', 'TW', 'US']) result = countries(session) self.assertEqual(len(result), len(expected)) self.assertEqual(set([r['code'] for r in result]), expected) country_results = {} for r in result: code = r['code'] country_results[code] = r del country_results[code]['code'] # ensure we use apolitical names self.assertEqual(country_results['TW']['name'], 'Taiwan') for code in country_results: del country_results[code]['name'] # a simple case with a 1:1 mapping of mcc to ISO country code self.assertEqual(country_results['DE'], {'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 1, 'umts': 0, 'multiple': False, 'order': 'germany'}) # mcc 310 is valid for both GUM/USA, 313 only for USA self.assertEqual(country_results['US'], {'cdma': 1, 'gsm': 3, 'lte': 0, 'total': 4, 'umts': 0, 'multiple': True, 'order': 'united sta'}) self.assertEqual(country_results['GU'], {'cdma': 1, 'gsm': 2, 'lte': 0, 'total': 3, 'umts': 0, 'multiple': True, 'order': 'guam'}) # These two countries share a mcc, so we report the same data # for both of them self.assertEqual(country_results['FI'], {'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 2, 'umts': 1, 'multiple': True, 'order': 'finland'}) self.assertEqual(country_results['AX'], {'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 2, 'umts': 1, 'multiple': True, 'order': 'aland isla'})
def stats_countries_view(self): redis_client = self.request.registry.redis_client cache_key = CACHE_KEYS['stats_countries'] cached = redis_client.get(cache_key) if cached: data = loads(cached) else: session = self.request.db_ro_session data = countries(session) redis_client.set(cache_key, dumps(data), ex=3600) return {'page_title': 'Cell Statistics', 'metrics': data}
def test_countries(self): session = self.db_master_session test_data = [ Cell(radio=RADIO_TYPE[''], mcc=208, mnc=1), Cell(radio=RADIO_TYPE['gsm'], mcc=1, mnc=1), Cell(radio=RADIO_TYPE['lte'], mcc=262, mnc=1), Cell(radio=RADIO_TYPE['gsm'], mcc=310, mnc=1), Cell(radio=RADIO_TYPE['gsm'], mcc=310, mnc=2), Cell(radio=RADIO_TYPE['gsm'], mcc=313, mnc=1), Cell(radio=RADIO_TYPE['cdma'], mcc=310, mnc=1), Cell(radio=RADIO_TYPE['umts'], mcc=244, mnc=1), Cell(radio=RADIO_TYPE['lte'], mcc=244, mnc=1), ] session.add_all(test_data) session.commit() # check the result expected = set(['ALA', 'BMU', 'DEU', 'FIN', 'GUM', 'PRI', 'USA']) result = countries(session) self.assertEqual(len(result), len(expected)) self.assertEqual(set([r['code'] for r in result]), expected) country_results = {} for r in result: code = r['code'] country_results[code] = r del country_results[code]['code'] del country_results[code]['name'] # a simple case with a 1:1 mapping of mcc to ISO country code self.assertEqual(country_results['DEU'], {'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 1, 'umts': 0, 'multiple': False, 'order': 'germany'}) # mcc 310 is valid for both GUM/USA, 313 only for USA self.assertEqual(country_results['USA'], {'cdma': 1, 'gsm': 3, 'lte': 0, 'total': 4, 'umts': 0, 'multiple': True, 'order': 'united sta'}) self.assertEqual(country_results['GUM'], {'cdma': 1, 'gsm': 2, 'lte': 0, 'total': 3, 'umts': 0, 'multiple': True, 'order': 'guam'}) # These two countries share a mcc, so we report the same data # for both of them self.assertEqual(country_results['FIN'], {'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 2, 'umts': 1, 'multiple': True, 'order': 'finland'}) self.assertEqual(country_results['ALA'], {'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 2, 'umts': 1, 'multiple': True, 'order': 'aland isla'})
def test_countries(self): from ichnaea.content.stats import countries session = self.db_master_session test_data = [ Cell(radio=RADIO_TYPE[''], mcc=208, mnc=1), Cell(radio=RADIO_TYPE['gsm'], mcc=1, mnc=1), Cell(radio=RADIO_TYPE['lte'], mcc=262, mnc=1), Cell(radio=RADIO_TYPE['gsm'], mcc=310, mnc=1), Cell(radio=RADIO_TYPE['gsm'], mcc=310, mnc=2), Cell(radio=RADIO_TYPE['gsm'], mcc=313, mnc=1), Cell(radio=RADIO_TYPE['cdma'], mcc=310, mnc=1), Cell(radio=RADIO_TYPE['umts'], mcc=425, mnc=1), Cell(radio=RADIO_TYPE['lte'], mcc=425, mnc=1), ] session.add_all(test_data) session.commit() # check the result expected = set(['BMU', 'DEU', 'GUM', 'ISR', 'PRI', 'PSE', 'USA']) result = countries(session) self.assertEqual(len(result), len(expected)) self.assertEqual(set([r['code'] for r in result]), expected) countries = {} for r in result: code = r['code'] countries[code] = r del countries[code]['code'] del countries[code]['name'] # a simple case with a 1:1 mapping of mcc to ISO country code self.assertEqual(countries['DEU'], {'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 1, 'umts': 0, 'multiple': False}) # mcc 310 is valid for both GUM/USA, 313 only for USA self.assertEqual(countries['USA'], {'cdma': 1, 'gsm': 3, 'lte': 0, 'total': 4, 'umts': 0, 'multiple': True}) self.assertEqual(countries['GUM'], {'cdma': 1, 'gsm': 2, 'lte': 0, 'total': 3, 'umts': 0, 'multiple': True}) # These two countries share a mcc, so we report the same data # for both of them self.assertEqual(countries['ISR'], {'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 2, 'umts': 1, 'multiple': True}) self.assertEqual(countries['ISR'], countries['PSE'])
def test_countries(self): from ichnaea.content.stats import countries session = self.db_master_session test_data = [ Cell(radio=RADIO_TYPE[''], mcc=208, mnc=1), Cell(radio=RADIO_TYPE['gsm'], mcc=1, mnc=1), Cell(radio=RADIO_TYPE['gsm'], mcc=310, mnc=1), Cell(radio=RADIO_TYPE['gsm'], mcc=310, mnc=2), Cell(radio=RADIO_TYPE['gsm'], mcc=311, mnc=1), Cell(radio=RADIO_TYPE['cdma'], mcc=310, mnc=1), Cell(radio=RADIO_TYPE['umts'], mcc=262, mnc=1), Cell(radio=RADIO_TYPE['lte'], mcc=262, mnc=1), ] session.add_all(test_data) session.commit() # check the result result = countries(session) self.assertEqual(len(result), 2) self.assertEqual(result[0]['name'], 'Germany') self.assertEqual(result[1]['name'], 'United States') countries = {} for r in result: name = r['name'] countries[name] = r del countries[name]['name'] self.assertEqual(countries['United States'], { 'cdma': 1, 'gsm': 3, 'lte': 0, 'total': 4, 'umts': 0 }) self.assertEqual(countries['Germany'], { 'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 2, 'umts': 1 })
def test_countries(self): from ichnaea.content.stats import countries session = self.db_master_session test_data = [ Cell(radio=RADIO_TYPE[''], mcc=208, mnc=1), Cell(radio=RADIO_TYPE['gsm'], mcc=1, mnc=1), Cell(radio=RADIO_TYPE['gsm'], mcc=310, mnc=1), Cell(radio=RADIO_TYPE['gsm'], mcc=310, mnc=2), Cell(radio=RADIO_TYPE['gsm'], mcc=311, mnc=1), Cell(radio=RADIO_TYPE['cdma'], mcc=310, mnc=1), Cell(radio=RADIO_TYPE['umts'], mcc=262, mnc=1), Cell(radio=RADIO_TYPE['lte'], mcc=262, mnc=1), ] session.add_all(test_data) session.commit() # check the result result = countries(session) self.assertEqual(len(result), 2) self.assertEqual(result[0]['name'], 'Germany') self.assertEqual(result[1]['name'], 'United States') countries = {} for r in result: name = r['name'] countries[name] = r del countries[name]['name'] self.assertEqual( countries['United States'], {'cdma': 1, 'gsm': 3, 'lte': 0, 'total': 4, 'umts': 0} ) self.assertEqual( countries['Germany'], {'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 2, 'umts': 1} )
def stats_countries_view(self): session = self.request.db_slave_session result = {"page_title": "Cell Statistics"} result["metrics"] = countries(session) return result
def stats_countries_view(self): session = self.request.db_slave_session result = {'page_title': 'Cell Statistics'} result['metrics'] = countries(session) return result
def test_countries(self): session = self.db_master_session cell_key = {'lac': 1, 'cid': 1} test_data = [ Cell(radio=RADIO_TYPE[''], mcc=208, mnc=1, **cell_key), Cell(radio=RADIO_TYPE['gsm'], mcc=1, mnc=1, **cell_key), Cell(radio=RADIO_TYPE['lte'], mcc=262, mnc=1, **cell_key), Cell(radio=RADIO_TYPE['gsm'], mcc=310, mnc=1, **cell_key), Cell(radio=RADIO_TYPE['gsm'], mcc=310, mnc=2, **cell_key), Cell(radio=RADIO_TYPE['gsm'], mcc=313, mnc=1, **cell_key), Cell(radio=RADIO_TYPE['cdma'], mcc=310, mnc=1, **cell_key), Cell(radio=RADIO_TYPE['umts'], mcc=244, mnc=1, **cell_key), Cell(radio=RADIO_TYPE['lte'], mcc=244, mnc=1, **cell_key), ] session.add_all(test_data) session.commit() # check the result expected = set(['ALA', 'BMU', 'DEU', 'FIN', 'GUM', 'PRI', 'USA']) result = countries(session) self.assertEqual(len(result), len(expected)) self.assertEqual(set([r['code'] for r in result]), expected) country_results = {} for r in result: code = r['code'] country_results[code] = r del country_results[code]['code'] del country_results[code]['name'] # a simple case with a 1:1 mapping of mcc to ISO country code self.assertEqual( country_results['DEU'], { 'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 1, 'umts': 0, 'multiple': False, 'order': 'germany' }) # mcc 310 is valid for both GUM/USA, 313 only for USA self.assertEqual( country_results['USA'], { 'cdma': 1, 'gsm': 3, 'lte': 0, 'total': 4, 'umts': 0, 'multiple': True, 'order': 'united sta' }) self.assertEqual( country_results['GUM'], { 'cdma': 1, 'gsm': 2, 'lte': 0, 'total': 3, 'umts': 0, 'multiple': True, 'order': 'guam' }) # These two countries share a mcc, so we report the same data # for both of them self.assertEqual( country_results['FIN'], { 'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 2, 'umts': 1, 'multiple': True, 'order': 'finland' }) self.assertEqual( country_results['ALA'], { 'cdma': 0, 'gsm': 0, 'lte': 1, 'total': 2, 'umts': 1, 'multiple': True, 'order': 'aland isla' })