Пример #1
0
def get_iface_data(request):
    try:
        md_in = request.GET['in']
        md_out = request.GET['out']
        t = request.GET['t']

        curr_time = int(time.time())
        start_t = datetime.fromtimestamp(float(curr_time - int(t)))

        values = ""
        labels = ""
 
        result = "{ \"identifier\": \"urn\", \"idAttribute\": \"urn\", \"label\": \"timestamps\", \"items\": [\n"
        
        result += "\t{\"urn\": \"%s\", \"values\":[" % md_in
        measurements = get_urn_measurements(md_in, start_t)
        
        for m in measurements:
            values += "%s,"%m.value
            labels += "'%s',"%time.strftime("%H:%M:%S", m.time.timetuple())

        result += values
        result += "], \"timestamps\":["
        result += labels
        result += "]},\n"
        
        result += "\t{\"urn\": \"%s\", \"values\":[" % md_out
        measurements = get_urn_measurements(md_out, start_t)
        values = ""
        labels = ""
        for m in measurements:
            values += "%s,"%m.value
            labels += "'%s',"%time.strftime("%H:%M:%S", m.time.timetuple())

        result += values
        result += "], \"timestamps\":["
        result += labels
        result += "]}\n]}"
        return HttpResponse(result, mimetype="application/json")

    except (KeyError):
        return HttpResponse("Invalid Request", mimetype="text/plain")
Пример #2
0
def get_iface_data(request):
    try:
        md_in = request.GET['in']
        md_out = request.GET['out']
        t = request.GET['t']

        curr_time = int(time.time())
        start_t = datetime.fromtimestamp(float(curr_time - int(t)))

        values = ""
        labels = ""
 
        result = "{ \"identifier\": \"urn\", \"idAttribute\": \"urn\", \"label\": \"timestamps\", \"items\": [\n"
        
        result += "\t{\"urn\": \"%s\", \"values\":[" % md_in
        measurements = get_urn_measurements(md_in, start_t)
        
        for m in measurements:
            values += "%s,"%m.value
            labels += "'%s',"%time.strftime("%H:%M:%S", m.time.timetuple())

        result += values
        result += "], \"timestamps\":["
        result += labels
        result += "]},\n"
        
        result += "\t{\"urn\": \"%s\", \"values\":[" % md_out
        measurements = get_urn_measurements(md_out, start_t)
        values = ""
        labels = ""
        for m in measurements:
            values += "%s,"%m.value
            labels += "'%s',"%time.strftime("%H:%M:%S", m.time.timetuple())

        result += values
        result += "], \"timestamps\":["
        result += labels
        result += "]}\n]}"
        return HttpResponse(result, mimetype="application/json")

    except (KeyError):
        return HttpResponse("Invalid Request", mimetype="text/plain")
Пример #3
0
def get_measurements_data(request):
    try:
        urn = request.GET['urn']
        event = request.GET['event']
        
        try:
            event = EventTypes.objects.get(event_type=event)
        except (EventTypes.DoesNotExist):
            return HttpResponse("Invalid Event type", mimetype="text/plain")
        
        measurements = get_urn_measurements(urn, event)
        
        result = "{\n label:'%s',\ndata:[\n"%urn
        for m in measurements:
            result += "\t[%s,%s],\n"%(time.mktime(m.time.timetuple()), m.value)
        result = result[:-2] + "]\n}"
        return HttpResponse(result, mimetype="application/json")
        
    except (KeyError):
        return HttpResponse("Invalid Request", mimetype="text/plain")
Пример #4
0
def get_measurements_data(request):
    try:
        urn = request.GET['urn']
        event = request.GET['event']
        
        try:
            event = EventTypes.objects.get(event_type=event)
        except (EventTypes.DoesNotExist):
            return HttpResponse("Invalid Event type", mimetype="text/plain")
        
        measurements = get_urn_measurements(urn, event)
        
        result = "{\n label:'%s',\ndata:[\n"%urn
        for m in measurements:
            result += "\t[%s,%s],\n"%(time.mktime(m.time.timetuple()), m.value)
        result = result[:-2] + "]\n}"
        return HttpResponse(result, mimetype="application/json")
        
    except (KeyError):
        return HttpResponse("Invalid Request", mimetype="text/plain")