Exemplo n.º 1
0
def avg_thruput(request, node_id):
    #print 'Avg thruput'
    try:
        d = request.session.get(request.session.session_key)
        #print d
        if d is None:
            raise Exception, INVALID_SESSION_MSG
        if NS_TRACEFILE_KEY in d:
            #print 'Trace file key found'
            if NS_TRACEFILE_MODE in d:
                #print 'Trace file format found (', d[NS_TRACEFILE_MODE], ')'
                # Create a TraceAnalyzer object
                ta = TraceAnalyzer(d[NS_TRACEFILE_KEY], d[NS_TRACEFILE_MODE])
                return HttpResponse(ta.get_average_throughput_for_node(node_id))
            else:
                raise KeyError, 'Trace file mode not set!'
        else:
            #print 'Trace file key NOT found'
            raise KeyError, 'Wrong key!!!'        
    except KeyError, ke:
        #print str(ke)
        mesg = str(ke)
        error = {'error' : mesg}
        return HttpResponse(json.dumps(error))