Fetch data from the server.

    Parameters
    ----------
    top_n : int
        Number of data sets which get fetched from the server.
420206
def get_segmented_raw_data(top_n=10000):
    
    cfg = utils.get_database_configuration()
    mysql = cfg['mysql_online']
    connection = pymysql.connect(host=mysql['host'],
                                 user=mysql['user'],
                                 passwd=mysql['passwd'],
                                 db=mysql['db'],
                                 cursorclass=pymysql.cursors.DictCursor)
    cursor = connection.cursor()
    sql = ("SELECT `id`, `data`, `segmentation` "
           "FROM `wm_raw_draw_data` WHERE "
           "(`segmentation` IS NOT NULL OR `accepted_formula_id` IS NOT NULL) "
           "AND `wild_point_count` = 0 "
           "AND `stroke_segmentable` = 1 "
           "ORDER BY `id` LIMIT 0, %i") % top_n
    logging.info(sql)
    cursor.execute(sql)
    datasets = cursor.fetchall()
    logging.info("Fetched %i recordings. Add missing segmentations.",
                 len(datasets))
    for i in range(len(datasets)):
        if datasets[i]['segmentation'] is None:
            stroke_count = len(json.loads(datasets[i]['data']))
            if stroke_count > 10:
                print("Massive stroke count! %i" % stroke_count)
            datasets[i]['segmentation'] = str([[s for s in
                                                range(stroke_count)]])
    return datasets
483497
async def fetchall(self):
        
        rows = []
        while True:
            row = await self.fetchone()
            if row is None:
                break
            rows.append(row)
        return rows
1213180
def fetch(self, customer_id, data={}, **kwargs):
        "
        return super(Customer, self).fetch(customer_id, data, **kwargs)
473741
def raw(self, n=1):
        
        size = self.__strct.size  # struct size
        dataset = list()          # list of raw data

        try:
            # For n times...
            for _ in range(n):
                data = self.__file.read(size)  # get raw data from file
                dataset.append(data)           # save raw data in the list
        finally:
            return dataset
1244456
def fetchcbatch(self):
        ''''''
        if not self._last_operation.is_columnar:
            raise NotSupportedError("Server does not support columnar "
                                    "fetching")
        if not self.has_result_set:
            raise ProgrammingError(
                "Trying to fetch results on an operation with no results.")
        if len(self._buffer) > 0:
            log.debug('fetchcbatch: buffer has data in. Returning it and wiping buffer')
            batch = self._buffer
            self._buffer = Batch()
            return batch
        elif self._last_operation_active:
            log.debug('fetchcbatch: buffer empty and op is active => fetching '
                      'more data')
            batch = (self._last_operation.fetch(
                         self.description,
                         self.buffersize,
                         convert_types=self.convert_types))
            if len(batch) == 0:
               return None
            return batch
        else:
           return None
627522
def fetch(self, resource_data=None):
        """"""
        if not self._populated:
            params = {
                "Page"      : self.page,
                "PageSize"  : self.page_size,
            }

            params.update(self._filters)

            if not resource_data:
                self._resource_data = self._client._get(self._url + ".json", params)
            else:
                self._resource_data = resource_data

            self.total = self._resource_data["total"]
            self._page_start = self._resource_data["start"]
            self._page_end = self._resource_data["end"]

            self._populated = True
406096
async def fetchrow(self, *args, timeout=None):
        
        data = await self.__bind_execute(args, 1, timeout)
        if not data:
            return None
        return data[0]
514567
def top_stream(cache, user_id):
    
    if not user_id:
        return None
    
    stack = cache.get(user_id)
    if stack is None:
        return None
    return stack.pop()
905525
def fetch(self):
        
        raw = yield gen.Task(self._redis_client.get, self._key)
        if raw:
            self.loads(base64.b64decode(raw))
            raise gen.Return(True)
        raise gen.Return(False)
1173932
def get_tops(self):
        '''
        
        '''
        tops = collections.defaultdict(list)
        include = collections.defaultdict(list)
        done = collections.defaultdict(list)
        errors = []
        # Gather initial top files
        try:
            saltenvs = set()
            if self.opts['pillarenv']:
                # If the specified pillarenv is not present in the available
                # pillar environments, do not cache the pillar top file.
                if self.opts['pillarenv'] not in self.opts['pillar_roots']:
                    log.debug(
                        'pillarenv \'%s\' not found in the configured pillar '
                        'environments (%s)',
                        self.opts['pillarenv'], ', '.join(self.opts['pillar_roots'])
                    )
                else:
                    saltenvs.add(self.opts['pillarenv'])
            else:
                saltenvs = self._get_envs()
                if self.opts.get('pillar_source_merging_strategy', None) == "none":
                    saltenvs &= set([self.saltenv or 'base'])

            for saltenv in saltenvs:
                top = self.client.cache_file(self.opts['state_top'], saltenv)
                if top:
                    tops[saltenv].append(compile_template(
                        top,
                        self.rend,
                        self.opts['renderer'],
                        self.opts['renderer_blacklist'],
                        self.opts['renderer_whitelist'],
                        saltenv=saltenv,
                        _pillar_rend=True,
                    ))
        except Exception as exc:
            errors.append(
                    ('Rendering Primary Top file failed, render error:\n{0}'
                        .format(exc)))
            log.exception('Pillar rendering failed for minion %s', self.minion_id)

        # Search initial top files for includes
        for saltenv, ctops in six.iteritems(tops):
            for ctop in ctops:
                if 'include' not in ctop:
                    continue
                for sls in ctop['include']:
                    include[saltenv].append(sls)
                ctop.pop('include')
        # Go through the includes and pull out the extra tops and add them
        while include:
            pops = []
            for saltenv, states in six.iteritems(include):
                pops.append(saltenv)
                if not states:
                    continue
                for sls in states:
                    if sls in done[saltenv]:
                        continue
                    try:
                        tops[saltenv].append(
                                compile_template(
                                    self.client.get_state(
                                        sls,
                                        saltenv
                                        ).get('dest', False),
                                    self.rend,
                                    self.opts['renderer'],
                                    self.opts['renderer_blacklist'],
                                    self.opts['renderer_whitelist'],
                                    saltenv=saltenv,
                                    _pillar_rend=True,
                                    )
                                )
                    except Exception as exc:
                        errors.append(
                                ('Rendering Top file {0} failed, render error'
                                 ':\n{1}').format(sls, exc))
                    done[saltenv].append(sls)
            for saltenv in pops:
                if saltenv in include:
                    include.pop(saltenv)

        return tops, errors
1166376
def _master_tops(self, load):
        '''
        
        '''
        load = self.__verify_load(load, ('id', 'tok'))
        if load is False:
            return {}
        return self.masterapi._master_tops(load, skip_verify=True)
974337
def top(**kwargs):
    '''
    
    '''
    if 'id' not in kwargs['opts']:
        return {}
    cmd = '{0} {1}'.format(
            __opts__['master_tops']['ext_nodes'],
            kwargs['opts']['id']
            )
    ndata = salt.utils.yaml.safe_load(
        subprocess.Popen(
            cmd,
            shell=True,
            stdout=subprocess.PIPE).communicate()[0]
    )
    if not ndata:
        log.info('master_tops ext_nodes call did not return any data')
    ret = {}
    if 'environment' in ndata:
        env = ndata['environment']
    else:
        env = 'base'

    if 'classes' in ndata:
        if isinstance(ndata['classes'], dict):
            ret[env] = list(ndata['classes'])
        elif isinstance(ndata['classes'], list):
            ret[env] = ndata['classes']
        else:
            return ret
    else:
        log.info('master_tops ext_nodes call did not have a dictionary with a "classes" key.')

    return ret
564129
public static function getTopStates($t_state_v, $top_k = 4, $options = array())
    {
        arsort($t_state_v);

        $top_states = array_slice($t_state_v, 0, $top_k);

        return $top_states;
    }
607013
def fetch_next_page(self):
        
        if self.response_future.has_more_pages:
            self.response_future.start_fetching_next_page()
            result = self.response_future.result()
            self._current_rows = result._current_rows  # ResultSet has already _set_current_rows to the appropriate form
        else:
            self._current_rows = []
1264513
def get_top(self):
        '''
        
        '''
        try:
            tops = self.get_tops()
        except SaltRenderError as err:
            log.error('Unable to render top file: %s', err.error)
            return {}
        return self.merge_tops(tops)
98948
def _fetch_data(self, dataset, query={}, include_inactive_stations=False):
        
        data = []
        parameter = dataset
        station_dim = dataset.dimensions["station"]
        all_stations = station_dim.allowed_values
        # Step 1: Prepare query
        if "station" not in query:
            if include_inactive_stations:
                # Get all stations
                query["station"] = list(all_stations)
            else:
                # Get only active stations
                query["station"] = list(station_dim.active_stations())
        else:
            if not isinstance(query["station"], list):
                query["station"] = [query["station"]]
            # Make sure that the queried stations actually exist
            query["station"] = [ all_stations.get_by_label(x) for x in query["station"]]

        if "period" not in query:
            # TODO: I'd prepare to do dataset.get("period").allowed_values here
            query["period"] = PERIODS

        elif not isinstance(query["period"], list):
            query["period"] = [query["period"]]

        for period in query["period"]:
            if period not in PERIODS:
                msg = u"{} is not an allowed period".format(period)
                raise Exception(msg)


        # Step 3: Get data
        n_queries = len(query["station"]) * len(query["period"])
        counter = 0
        print("Fetching data with {} queries.".format(n_queries))
        for station in query["station"]:
            for period in query["period"]:
                url = dataset.url\
                    .replace(".json", "/station/{}/period/{}/data.csv"\
                        .format(station.key, period))
                print("/GET {} ".format(url))
                r = requests.get(url)

                if r.status_code == 200:
                    raw_data = DataCsv().from_string(r.content).to_dictlist()

                    # TODO: This is a very hard coded parse function
                    # Expects fixed start row and number of cols
                    for row in raw_data:
                        #timepoint = datetime.strptime(timepoint_str, "%Y-%m-%d %H:%M:%S")
                        value_col = parameter.id.split(",")[0]
                        value = float(row[value_col])

                        row["parameter"] = parameter.id
                        row["station"] = station.label
                        row["station_key"] = station.key
                        row["period"] = period

                        row.pop(value_col,None)

                        datapoint = Result(value, row)

                        yield datapoint

                elif r.status_code == 404:
                    print("Warning no data at {}".format(url))
                else:
                    raise Exception("Connection error for {}".format(url))
1102995
def fetch(self):
        
        LOGGER.debug('Fetching session data: %s', self.id)
        result = yield gen.Task(RedisSession._redis_client.get, self._key)
        if result:
            self.loads(result)
            raise gen.Return(True)
        else:
            raise gen.Return(False)