Ejemplo n.º 1
0
def test_get_filters():
    filters_empty = get_filters('')
    assert (filters_empty == '')

    one_filter = get_filters({"user": "******"})
    assert (one_filter == "user:\"account\"\n")

    several_filtes = get_filters({"user": "******", "pair": "assetPair"})
    assert (several_filtes == "user:\"account\"\npair:\"assetPair\"\n")
Ejemplo n.º 2
0
def get_data_filtered(query_input, entity, mappings_file, endpoint, filters):
    """
    Gets all the existing data from the subgraph applying the given filters
    """
    entity_name = mappings_file['entities'][entity]['query']['name']
    filters_str = get_filters(filters)

    attributes = get_attributes(entity, mappings_file)

    query = query_input.format(
        entity_name=entity_name,
        filters=filters_str,
        attributes=attributes
    )

    json_data = call_api(endpoint=endpoint, query=query)
    json_records = []

    response_lenght = len(json_data['data'][entity_name])
    if (response_lenght > 0):
        list_data = json_data['data'][entity_name]

        json_records = [*list_data]

    return json_records
Ejemplo n.º 3
0
def get_first_element(query_input, entity, mappings_file, endpoint, timestamp, aditional_filters, block=None):
    """
    Gets first existing data from the subgraph applying the given filters
    """
    entity_name = mappings_file['entities'][entity]['query']['name']
    filters_str = get_filters(aditional_filters)
    order_by = mappings_file['entities'][entity]['query']['params']['orderBy']
    attributes = get_attributes(entity, mappings_file)
    params = filter_method(block=block,
                           order_by_filter=order_by,
                           lte='_lte:',
                           timestamp=timestamp)

    query = query_input.format(
        entity_name=entity_name,
        order_by=order_by,
        order_by_filter=params['order_by_filter'],
        aditional_filters=filters_str,
        attributes=attributes,
        timestamp=params['timestamp'],
        lte=params['lte'],
        block=params['block']
    )

    json_data = call_api(endpoint=endpoint, query=query)
    json_records = []

    response_lenght = len(json_data['data'][entity_name])
    if (response_lenght > 0):
        list_data = json_data['data'][entity_name]

        json_records = [*list_data]

    return json_records
Ejemplo n.º 4
0
def get_data_from(query_input,
                  entity,
                  from_timestamp,
                  to_timestamp,
                  mappings_file,
                  endpoint,
                  aditional_filters=""):
    """
    Gets all the existing data from the subgraph at the given time range.
    One or mor filters can be passed as parameters and will be applied in the where clause
    """
    are_data = True
    json_records = []
    iteration_timestamp = from_timestamp

    entity_name = mappings_file['entities'][entity]['query']['name']
    order_by = mappings_file['entities'][entity]['query']['params']['orderBy']
    attributes = get_attributes(entity, mappings_file)
    filters_str = get_filters(aditional_filters)

    while are_data:
        query = query_input.format(entity_name=entity_name,
                                   order_by=order_by,
                                   from_timestamp=iteration_timestamp,
                                   to_timestamp=to_timestamp,
                                   attributes=attributes,
                                   aditional_filters=filters_str)

        json_data = call_api(endpoint=endpoint, query=query)

        response_lenght = len(json_data['data'][entity_name])
        if (response_lenght > 0):
            list_data = json_data['data'][entity_name]
            iteration_timestamp = json_data['data'][entity_name][
                response_lenght - 1][order_by]

            json_records = [*json_records, *list_data]
        else:
            are_data = False

    return json_records