Пример #1
0
def chart_metadata(request, res_ids):

    print "running chart_metadata " + res_ids

    # checks if there is two resource IDs
    resources = res_ids.split("_")

    data_for_chart = {'series':[None, None]}
    if len(resources) == 2:

        # checks if we already have an unzipped xml file
        file_path = utilities.waterml_file_path(resources[0])
        # if we don't have the xml file, downloads and unzips it
        if not os.path.exists(file_path):
            utilities.unzip_waterml(request, resources[0])
        # returns an error message if the unzip_waterml failed
        if not os.path.exists(file_path):
            series_x = {'status': 'Resource file not found'}
        else:
            # parses the WaterML to a chart data object
            series_x = waterml.parse(file_path, True)

        # checks if we already have an unzipped xml file
        file_path = utilities.waterml_file_path(resources[1])
        # if we don't have the xml file, downloads and unzips it
        if not os.path.exists(file_path):
            utilities.unzip_waterml(request, resources[1])
        # returns an error message if the unzip_waterml failed
        if not os.path.exists(file_path):
            series_y = {'status': 'Resource file not found'}
        else:
            # parses the WaterML to a chart data object
            series_y = waterml.parse(file_path, True)

        # retrieves the metadata
        if series_x['status'] == 'success' and series_x['status'] == 'success':
            # series_x['for_highchart'] = None
            # series_y['for_highchart'] = None
            metadata = {'status': 'success', 'x': series_x, 'y': series_y}
        else:
            metadata = {'status': 'error reading one of the time series', 'x': None, 'y': None}
    else:
        metadata = {'status': 'error loading data, expecting 2 time series, found ' + str(len(resources)), 'x': None, 'y': None}

    return JsonResponse(metadata)
Пример #2
0
def chart_data(request, res_id):

    # checks if we already have an unzipped xml file
    file_path = utilities.waterml_file_path(res_id)
    # if we don't have the xml file, downloads and unzips it
    if not os.path.exists(file_path):
        utilities.unzip_waterml(request, res_id)

    # returns an error message if the unzip_waterml failed
    if not os.path.exists(file_path):
        data_for_chart = {'status': 'Resource file not found'}
    else:
        # parses the WaterML to a chart data object
        data_for_chart = utilities.Original_Checker(file_path)
    return JsonResponse(data_for_chart)
def chart_data(request, res_id, src):
    print "start chart_data"
    print datetime.now()
    # checks if we already have an unzipped xml file
    file_path = utilities.waterml_file_path(res_id)
    # if we don't have the xml file, downloads and unzips it
    if not os.path.exists(file_path):
        utilities.unzip_waterml(request, res_id,src)

    # returns an error message if the unzip_waterml failed
    if not os.path.exists(file_path):
        data_for_chart = {'status': 'Resource file not found'}
    else:
        # parses the WaterML to a chart data object
        data_for_chart = utilities.Original_Checker(file_path,res_id)
        # print data_for_chart

        # print datetime.now()
    # csv_file = utilities.get_workspace() + "/id/master.csv"

    # print csv_file
    print "JSON Reponse"
    print datetime.now()
    # data = []
    # data1 = []
    # with open(csv_file) as csvfile:
    #     reader = csv.reader(csvfile, delimiter = ',', quotechar = "'")
    #     # data1 = map(float,reader)
    #
    #     counter = 0
    #     for row in reader:
    #
    #         if counter ==0:
    #             print "first line"
    #         else:
    #             data.append(row)
    #         # print row
    #         counter = counter +1
    #
    # chart ={"for_highchart":data}
    # chart =  json.dumps(data_for_chart, sort_keys =True)
    # response = HttpResponse(chart, content_type="text/plain")
    return JsonResponse(data_for_chart )
Пример #4
0
def chart_data(request, res_id, src,id_qms):
    data_for_chart =[]
    test = ''
    file_number =0
    xml_id = None
    xml_rest = False
    if "xmlrest" in src:#id from USGS Gauge Viewer app
        xml_rest = True
        test = request.POST.get('url_xml')
        xml_id =  str(uuid.uuid4())#creates a unique id for the time series

    # print datetime.now()
    # checks if we already have an unzipped xml file
    file_path = utilities.waterml_file_path(res_id,xml_rest,xml_id)
    if src =='hydroshare':
        file_number = utilities.unzip_waterml(request, res_id, src, test,xml_id)
    else:
        if not os.path.exists(file_path):
            file_number = utilities.unzip_waterml(request, res_id, src, test,xml_id)
    # if we don't have the xml file, downloads and unzips it
    if file_number >0:
        for i in range(0,file_number):
            print i
            temp_dir = utilities.get_workspace()
            file_path = temp_dir+'/id/timeserieslayer' + str(i) + '.xml'
            data_for_chart.append(utilities.Original_Checker(file_path,id_qms))
        # data_for_chart.append({'file_number':file_number})
    else:
        # returns an error message if the unzip_waterml failed
        if not os.path.exists(file_path):
            data_for_chart = {'status': 'Resource file not found'}
        else:
            # parses the WaterML to a chart data object
            data_for_chart.append(utilities.Original_Checker(file_path,id_qms))
    # print "JSON Reponse"
    # print datetime.now()
    print "end of chart data"
    return JsonResponse({'data':data_for_chart})