Beispiel #1
0
def datasets_series_list(dataset):
    """Return all series for one dataset
    """
    
    query = {'enable': True, 'slug': dataset}
    projection = {"_id": False, "values": False}
    dataset_doc = queries.col_datasets().find_one(query, projection)
    if not dataset_doc:
        abort(404)

    query = {'provider_name': dataset_doc['provider_name'], 
             'dataset_code': dataset_doc["dataset_code"]}
    projection = {"_id": False, "values": False}
    
    query = queries.complex_queries_series(query)

    limit = request.args.get('limit', default=1000, type=int)
    
    docs = queries.col_series().find(query, projection)

    if limit:
        docs= docs.limit(limit)
    
    _docs = [doc for doc in docs]
    
    return json_tools.json_response(_docs)
Beispiel #2
0
def datasets_series_list(dataset):
    """Return all series for one dataset
    """

    query = {'enable': True, 'slug': dataset}
    projection = {"_id": False, "values": False}
    dataset_doc = queries.col_datasets().find_one(query, projection)
    if not dataset_doc:
        abort(404)

    query = {
        'provider_name': dataset_doc['provider_name'],
        'dataset_code': dataset_doc["dataset_code"]
    }
    projection = {"_id": False, "values": False}

    query = queries.complex_queries_series(query)

    docs = queries.col_series().find(query, projection)

    page = request.args.get('page', default=1, type=int)
    per_page = request.args.get('per_page', default=20, type=int)
    if per_page > 100:
        per_page = 100
    pagination = queries.Pagination(docs, page, per_page)
    meta = {
        "page": pagination.page,
        "pages": pagination.pages,
        "per_page": pagination.per_page,
        "total": pagination.total,
    }
    _docs = [doc for doc in pagination.items]
    return json_tools.json_response(_docs, meta=meta)
Beispiel #3
0
def datasets_series_list(dataset):
    """Return all series for one dataset
    """

    query = {'enable': True, 'slug': dataset}
    projection = {"_id": False, "values": False}
    dataset_doc = queries.col_datasets().find_one(query, projection)
    if not dataset_doc:
        abort(404)

    query = {
        'provider_name': dataset_doc['provider_name'],
        'dataset_code': dataset_doc["dataset_code"]
    }
    projection = {"_id": False, "values": False}

    query = queries.complex_queries_series(query)

    limit = request.args.get('limit', default=1000, type=int)

    docs = queries.col_series().find(query, projection)

    if limit:
        docs = docs.limit(limit)

    _docs = [doc for doc in docs]

    return json_tools.json_response(_docs)
Beispiel #4
0
def datasets_series_list(dataset):
    """Return all series for one dataset
    """
    
    query = {'enable': True, 'slug': dataset}
    projection = {"_id": False, "values": False}
    dataset_doc = queries.col_datasets().find_one(query, projection)
    if not dataset_doc:
        abort(404)

    query = {'provider_name': dataset_doc['provider_name'], 
             'dataset_code': dataset_doc["dataset_code"]}
    projection = {"_id": False, "values": False}
    
    query = queries.complex_queries_series(query)

    docs = queries.col_series().find(query, projection)

    page = request.args.get('page', default=1, type=int)
    per_page = request.args.get('per_page', default=20, type=int)
    if per_page > 100:
        per_page = 100
    pagination = queries.Pagination(docs, page, per_page)
    meta = {
        "page": pagination.page,
        "pages": pagination.pages,
        "per_page": pagination.per_page,
        "total": pagination.total,
    }
    _docs = [doc for doc in pagination.items]
    return json_tools.json_response(_docs, meta=meta)
Beispiel #5
0
def dataset_series_list_values(dataset):

    query = {'enable': True, 'slug': dataset}
    projection = {"_id": False, "provider_name": True, "dataset_code": True }
    doc = queries.col_datasets().find_one(query, projection)
    if not doc:
        abort(404)
        
    query = {"provider_name": doc["provider_name"], 
             'dataset_code': doc["dataset_code"]}
    projection = {
        "_id": False, 
        "key": True, "slug": True, 
        "name": True, "frequency": True,
        "start_date": True, "end_date": True,
        "dimensions": True, "attributes": True,
        "values.value": True, "values.period": True,
    }

    query = queries.complex_queries_series(query)
    docs = queries.col_series().find(query, projection)

    page = request.args.get('page', default=1, type=int)
    per_page = request.args.get('per_page', default=50, type=int)
    if per_page > 1000:
        per_page = 1000
    pagination = queries.Pagination(docs, page, per_page)
    meta = {
        "page": pagination.page,
        "pages": pagination.pages,
        "per_page": pagination.per_page,
        "total": pagination.total,
    }
    _docs = [doc for doc in pagination.items]
    return json_tools.json_response_async(_docs, meta=meta)
Beispiel #6
0
def dataset_series_list_values(dataset):

    query = {'enable': True, 'slug': dataset}
    projection = {"_id": False, "provider_name": True, "dataset_code": True}
    doc = queries.col_datasets().find_one(query, projection)
    if not doc:
        abort(404)

    query = {
        "provider_name": doc["provider_name"],
        'dataset_code': doc["dataset_code"]
    }
    projection = {
        "_id": False,
        "key": True,
        "slug": True,
        "name": True,
        "frequency": True,
        "start_date": True,
        "end_date": True,
        "dimensions": True,
        "attributes": True,
        "values.value": True,
        "values.period": True,
    }

    query = queries.complex_queries_series(query)
    docs = queries.col_series().find(query, projection)

    page = request.args.get('page', default=1, type=int)
    per_page = request.args.get('per_page', default=50, type=int)
    if per_page > 1000:
        per_page = 1000
    pagination = queries.Pagination(docs, page, per_page)
    meta = {
        "page": pagination.page,
        "pages": pagination.pages,
        "per_page": pagination.per_page,
        "total": pagination.total,
    }
    _docs = [doc for doc in pagination.items]
    return json_tools.json_response_async(_docs, meta=meta)
Beispiel #7
0
def _dataset_values(provider_name=None, dataset_code=None, 
                    frequency=None, 
                    separator='dot'):

    query = {}
    query['provider_name'] = provider_name
    query['dataset_code'] = dataset_code

    _format = request.args.get('format', default='html')

    limit = request.args.get('limit', default=0, type=int)
    
    query['frequency'] = frequency

    separator = request.args.get('separator', default=separator)
    if not separator in ['dot', 'comma']:
        abort(400, "separator [%s] not supported. valid separator[dot, comma]" % separator)
    
    query = queries.complex_queries_series(query, 
                                   search_attributes=False, 
                                   bypass_args=['limit', 'tags', 'provider', 'dataset', 'frequency', 'separator', 'format'])    
    
    start = time.time()
    
    cursor = queries.col_series().find(query)
    
    max_limit = current_app.config.get("WIDUKIND_DISPLAY_LIMIT", 1000)
    
    if limit:
        cursor = cursor.limit(limit)
    else:
        if cursor.count() > max_limit:
            abort(400, "The number of result exceeds the allowed limit [%s]. You must use the limit parameter in the query." % max_limit)

    if cursor.count() == 0:
        dates, series_keys, series_names, values = [], [], [], []
        abort(400, "no data found")
    else:
        dates, series_keys, series_names, values = _dataset_series_list(cursor, frequency, separator=separator)
    
    context = {
        "dates": dates,
        "series_keys": series_keys, 
        "series_names": series_names, 
        "values": values           
    }
    
    end = time.time() - start
    msg = "eviews-series - provider[%s] - dataset[%s] - frequency[%s] - limit[%s] - duration[%.3f]"
    current_app.logger.info(msg % (provider_name, dataset_code, frequency, limit, end))
    
    response_str = render_template("html/values.html", **context)
    
    """
    TODO: use lang browser pour choix separator ?
    TODO: header lang ?
    """
    
    EXTENSIONS_MAP = {
        "excel": ("xls", "application/vnd.ms-excel"),
        "xls": ("xls", "application/vnd.ms-excel"),
        "xlsx": ("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
        "calc": ("ods", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
    }
    
    if _format and _format in EXTENSIONS_MAP:
        response = make_response(response_str)

        _ext = EXTENSIONS_MAP[_format][0]
        content_type = EXTENSIONS_MAP[_format][1]
        
        filename = generate_filename(provider_name=provider_name, 
                                     dataset_code=dataset_code, 
                                     #key=key,
                                     #slug=slug, 
                                     prefix="series-list")

        filename = "%s.%s" % (filename, _ext)
        response.headers['Content-Type'] = content_type
        response.headers["Content-disposition"] = "attachment; filename=%s" % filename
        #response.content_length = fileobj.length
        #TODO: response.last_modified = fileobj.upload_date
        #TODO: response.set_etag(fileobj.md5)
        response.make_conditional(request)
        return response
    
    return response_str
Beispiel #8
0
def _dataset_values(provider_name=None,
                    dataset_code=None,
                    frequency=None,
                    separator='dot'):

    query = {}
    query['provider_name'] = provider_name
    query['dataset_code'] = dataset_code

    _format = request.args.get('format', default='html')

    limit = request.args.get('limit', default=0, type=int)

    query['frequency'] = frequency

    separator = request.args.get('separator', default=separator)
    if not separator in ['dot', 'comma']:
        abort(
            400, "separator [%s] not supported. valid separator[dot, comma]" %
            separator)

    query = queries.complex_queries_series(query,
                                           search_attributes=False,
                                           bypass_args=[
                                               'limit', 'tags', 'provider',
                                               'dataset', 'frequency',
                                               'separator', 'format'
                                           ])

    start = time.time()

    cursor = queries.col_series().find(query)

    max_limit = current_app.config.get("WIDUKIND_DISPLAY_LIMIT", 1000)

    if limit:
        cursor = cursor.limit(limit)
    else:
        if cursor.count() > max_limit:
            abort(
                400,
                "The number of result exceeds the allowed limit [%s]. You must use the limit parameter in the query."
                % max_limit)

    if cursor.count() == 0:
        dates, series_keys, series_names, values = [], [], [], []
        abort(400, "no data found")
    else:
        dates, series_keys, series_names, values = _dataset_series_list(
            cursor, frequency, separator=separator)

    context = {
        "dates": dates,
        "series_keys": series_keys,
        "series_names": series_names,
        "values": values
    }

    end = time.time() - start
    msg = "eviews-series - provider[%s] - dataset[%s] - frequency[%s] - limit[%s] - duration[%.3f]"
    current_app.logger.info(
        msg % (provider_name, dataset_code, frequency, limit, end))

    response_str = render_template("html/values.html", **context)
    """
    TODO: use lang browser pour choix separator ?
    TODO: header lang ?
    """

    EXTENSIONS_MAP = {
        "excel": ("xls", "application/vnd.ms-excel"),
        "xls": ("xls", "application/vnd.ms-excel"),
        "xlsx":
        ("xlsx",
         "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
        "calc":
        ("ods",
         "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
    }

    if _format and _format in EXTENSIONS_MAP:
        response = make_response(response_str)

        _ext = EXTENSIONS_MAP[_format][0]
        content_type = EXTENSIONS_MAP[_format][1]

        filename = generate_filename(
            provider_name=provider_name,
            dataset_code=dataset_code,
            #key=key,
            #slug=slug,
            prefix="series-list")

        filename = "%s.%s" % (filename, _ext)
        response.headers['Content-Type'] = content_type
        response.headers[
            "Content-disposition"] = "attachment; filename=%s" % filename
        #response.content_length = fileobj.length
        #TODO: response.last_modified = fileobj.upload_date
        #TODO: response.set_etag(fileobj.md5)
        response.make_conditional(request)
        return response

    return response_str