示例#1
0
    def test_get_lat_longs(self):
        exp = [
            [74.0894932572, 65.3283470202],
            [57.571893782, 32.5563076447],
            [13.089194595, 92.5274472082],
            [12.7065957714, 84.9722975792],
            [31.7167821863, 95.5088566087],
            [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],
            [63.6505562766, 31.2003474585],
            [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.assertEqual(obs, exp)
示例#2
0
    def test_get_lat_longs(self):
        exp = [[74.0894932572, 65.3283470202], [57.571893782, 32.5563076447],
               [13.089194595, 92.5274472082], [12.7065957714, 84.9722975792],
               [31.7167821863, 95.5088566087], [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],
               [63.6505562766, 31.2003474585], [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.assertEqual(obs, exp)
示例#3
0
文件: stats.py 项目: DarcyMyers/qiita
    def _get_stats(self, callback):
        # check if the key exists in redis
        lats = r_client.lrange('stats:sample_lats', 0, -1)
        longs = r_client.lrange('stats:sample_longs', 0, -1)
        if not (lats or 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()
            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('stats:sample_lats', latitude)
                    pipe.rpush('stats:sample_longs', 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('stats:sample_lats', 86400)
                r_client.expire('stats:sample_longs', 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])
示例#4
0
    def _get_stats(self, callback):
        # check if the key exists in redis
        lats = r_client.lrange('stats:sample_lats', 0, -1)
        longs = r_client.lrange('stats:sample_longs', 0, -1)
        if not (lats or 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()
            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('stats:sample_lats', latitude)
                    pipe.rpush('stats:sample_longs', 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('stats:sample_lats', 86400)
                r_client.expire('stats:sample_longs', 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])