def test_get_lat_longs(self): exp = [ [74.0894932572, 65.3283470202], [57.571893782, 32.5563076447], [13.089194595, 92.5274472082], [12.7065957714, 84.9722975792], [44.9725384282, 66.1920014699], [10.6655599093, 70.784770579], [29.1499460692, 82.1270418227], [35.2374368957, 68.5041623253], [53.5050692395, 31.6056761814], [60.1102854322, 74.7123248382], [4.59216095574, 63.5115213108], [68.0991287718, 34.8360987059], [84.0030227585, 66.8954849864], [3.21190859967, 26.8138925876], [82.8302905615, 86.3615778099], [12.6245524972, 96.0693176066], [85.4121476399, 15.6526750776], [23.1218032799, 42.838497795], [43.9614715197, 82.8516734159], [68.51099627, 2.35063674718], [0.291867635913, 68.5945325743], [40.8623799474, 6.66444220187], [95.2060749748, 27.3592668624], [78.3634273709, 74.423907894], [38.2627021402, 3.48274264219]] obs = get_lat_longs() self.assertItemsEqual(obs, exp)
def _get_stats(self, callback): # check if the key exists in redis redis_lats_key = '%s:stats:sample_lats' % qiita_config.portal redis_longs_key = '%s:stats:sample_longs' % qiita_config.portal lats = r_client.lrange(redis_lats_key, 0, -1) longs = r_client.lrange(redis_longs_key, 0, -1) if not (lats and longs): # if we don't have them, then fetch from disk and add to the # redis server with a 24-hour expiration lat_longs = get_lat_longs() lats = [float(x[0]) for x in lat_longs] longs = [float(x[1]) for x in lat_longs] with r_client.pipeline() as pipe: for latitude, longitude in lat_longs: # storing as a simple data structure, hopefully this # doesn't burn us later pipe.rpush(redis_lats_key, latitude) pipe.rpush(redis_longs_key, longitude) # set the key to expire in 24 hours, so that we limit the # number of times we have to go to the database to a reasonable # amount r_client.expire(redis_lats_key, 86400) r_client.expire(redis_longs_key, 86400) pipe.execute() else: # If we do have them, put the redis results into the same structure # that would come back from the database longs = [float(x) for x in longs] lats = [float(x) for x in lats] lat_longs = zip(lats, longs) # Get the number of studies num_studies = get_count('qiita.study') # Get the number of samples num_samples = len(lats) # Get the number of users num_users = get_count('qiita.qiita_user') callback([num_studies, num_samples, num_users, lat_longs])
def test_get_lat_longs_EMP_portal(self): info = { 'timeseries_type_id': 1, 'lab_person_id': None, 'principal_investigator_id': 3, 'metadata_complete': False, 'mixs_compliant': True, 'study_description': 'desc', 'study_alias': 'alias', 'study_abstract': 'abstract'} study = Study.create(User('*****@*****.**'), 'test_study_1', efo=[1], info=info) Portal('EMP').add_studies([study.id]) md = { 'my.sample': { 'physical_specimen_location': 'location1', 'physical_specimen_remaining': True, 'dna_extracted': True, 'sample_type': 'type1', 'collection_timestamp': datetime(2014, 5, 29, 12, 24, 51), 'host_subject_id': 'NotIdentified', 'Description': 'Test Sample 4', 'str_column': 'Value for sample 4', 'int_column': 4, 'latitude': 42.42, 'longitude': 41.41, 'taxon_id': 9606, 'scientific_name': 'h**o sapiens'} } md_ext = pd.DataFrame.from_dict(md, orient='index') SampleTemplate.create(md_ext, study) qiita_config.portal = 'EMP' obs = get_lat_longs() exp = [[42.42, 41.41]] self.assertItemsEqual(obs, exp)