예제 #1
0
def datasets():
    """
    Datasets names and Ids
    Return a dictionary of datasets names
    containing the respective Ids for the past records and the 2020 records
    ---
    responses:
      200:
        description: a dictionary containing the names and ids for all datasets
        schema:
          type: object
          properties:
            homicidios:
              type: object
              properties:
                2020:
                  type: string
                  example: 53e3d2fe-0026-4bf0-ba69-687aa4904a0f
                past:
                  type: string
                  example: f465aa6b-a49f-42ce-8da2-fef524e7eada
    """
    datasets = get_datasets()
    dsets = {}
    for dset in datasets:
        print('getting', dset)
        res_ids = getResourceId(dset)
        dsets[dset] = {}
        dsets[dset]['2020'] = res_ids[1]
        dsets[dset]['past'] = res_ids[0]
    return Response(json.dumps(dsets), mimetype='application/json')
예제 #2
0
def check_condiciones(resource):
    file_name = 'Service/data/condiciones/' + resource + '.txt'
    if os.path.exists(file_name):
        #print("leyendo de archivos")
        with open(file_name, 'r') as muns:
            condiciones = muns.read()
            condiciones = str_list(condiciones)
            return condiciones
    else:
        #print("scraping resource page")
        condiciones = getResourceFields(getResourceId(resource)[1])
        cond_str = list_str(condiciones)
        with open(file_name, 'w') as conds:
            conds.write(cond_str)
        return condiciones
예제 #3
0
def check_municipio(resource):
    file_name = 'Service/data/municipios/' + resource + '.txt'
    if os.path.exists(file_name):
        #print("leyendo de archivos")
        with open(file_name, 'r') as muns:
            municipios = muns.read()
            municipios = str_list(municipios)
            return municipios
    else:
        #print("scraping resource page")
        municipios = getMunicipios(getResourceId(resource)[1])
        mun_str = list_str(municipios)
        with open(file_name, 'w') as muns:
            muns.write(mun_str)
        return municipios
예제 #4
0
def datasets_info_by_name(dataset_name):
    """
    Dataset info by name
    Return a dictionary containing the fields for an specific dataset given by dataset name with no spaces
    joined by '-' character
    ---
    parameters:
     - in: path
       name: dataset_name
       type: string
       required: true
       description:  name with no spaces joined by the '-' character, example 'homicidios'
    responses:
      200:
        description: a dictionary containing the fields for each time range
        schema:
          type: object
          properties:
            homicidios:
              type: object
              properties:
                2020:
                  type: object
                  properties:
                    id:
                      type: string
                      example: b4fe8ba4-0d5b-4c8b-8c3b-85a20401ea3d
                    fields:
                      type: array
                      items:
                        type: object
                        properties:
                          label:
                            type: string
                            example: MES
                          type:
                            type: string
                            example: text
                past:
                  type: object
                  properties:
                    id:
                      type: string
                      example: b4fe8ba4-0d5b-4c8b-8c3b-85a20401ea3d
                    fields:
                      type: array
                      items:
                        type: object
                        properties:
                          label:
                            type: string
                            example: fecha
                          type:
                            type: string
                            example: timestamp
    """
    dsets = {}
    res_ids = getResourceId(dataset_name)
    dsets[dataset_name] = {}
    dsets[dataset_name]['2020'] = {}
    dsets[dataset_name]['past'] = {}
    dsets[dataset_name]['2020']['id'] = res_ids[1]
    dsets[dataset_name]['past']['id'] = res_ids[0]
    dsets[dataset_name]['2020']['fields'] = getResourceFields(res_ids[1])
    dsets[dataset_name]['past']['fields'] = getResourceFields(res_ids[0])
    return Response(json.dumps(dsets), mimetype='application/json')
예제 #5
0
def datasets_complete_info():
    """
    Complete datasets
    Return a dictionary of datasets names containing the respective Ids for the past records and the 2020 records
    and each id containing the fields for the dataset and the value type for each one
    ---
    responses:
      200:
        description: a dictionary of datasets
        schema:
          type: object
          properties:
            homicidios:
              type: object
              properties:
                2020:
                  type: object
                  properties:
                    id:
                      type: string
                      example: b4fe8ba4-0d5b-4c8b-8c3b-85a20401ea3d
                    fields:
                      type: array
                      items:
                        type: object
                        properties:
                          label:
                            type: string
                            example: MES
                          type:
                            type: string
                            example: text
                past:
                  type: object
                  properties:
                    id:
                      type: string
                      example: b4fe8ba4-0d5b-4c8b-8c3b-85a20401ea3d
                    fields:
                      type: array
                      items:
                        type: object
                        properties:
                          label:
                            type: string
                            example: fecha
                          type:
                            type: string
                            example: timestamp
    """
    datasets = get_datasets()
    dsets = {}
    for dset in datasets:
        print('getting', dset)
        res_ids = getResourceId(dset)
        dsets[dset] = {}
        dsets[dset]['2020'] = {}
        dsets[dset]['past'] = {}
        dsets[dset]['2020']['id'] = res_ids[1]
        dsets[dset]['past']['id'] = res_ids[0]
        dsets[dset]['2020']['fields'] = getResourceFields(res_ids[1])
        dsets[dset]['past']['fields'] = getResourceFields(res_ids[0])
    return Response(json.dumps(dsets), mimetype='application/json')