Beispiel #1
0
def get_variables(user):
    variable_list = variable_list_django_db(user)
    i = 0
    while i < len(variable_list):
        variable_list[i].value, variable_list[i].quality, variable_list[
            i].access_rights, time = connect.read(variable_list[i].server,
                                                  variable_list[i].name)
        i = i + 1
    return variable_list
def read_update(request):
    json_data={"variables":[]}
    variable_list=get_variables(request.user)
    for e in variable_list:
        dict={}
        dict['server']=e.server
        dict['name']=e.name
        dict['value'],dict['quality'],dict['access_rights'],time=connect.read(e.server,e.name)
        json_data['variables'].append(dict)    
    return HttpResponse(json.dumps(json_data), mimetype='application/json')
Beispiel #3
0
def read_update(request):
    json_data = {"variables": []}
    variable_list = get_variables(request.user)
    for e in variable_list:
        dict = {}
        dict['server'] = e.server
        dict['name'] = e.name
        dict['value'], dict['quality'], dict[
            'access_rights'], time = connect.read(e.server, e.name)
        json_data['variables'].append(dict)
    return HttpResponse(json.dumps(json_data), mimetype='application/json')
def json_graph_live (request):
    if request.method == 'POST':
        json_data = simplejson.loads(request.body)
    try:
        data = json_data['data'][0]
    except KeyError:
        return HttpResponseServerError("Malformed data!")
    data=check_json_data(request)
    dict={}
    dict['value'],dict['quality'],access_rights,dict['time']=connect.read(data['server'],data['name'])
    
    return HttpResponse(json.dumps(dict), mimetype='application/json')
Beispiel #5
0
def json_graph_live(request):
    if request.method == 'POST':
        json_data = simplejson.loads(request.body)
    try:
        data = json_data['data'][0]
    except KeyError:
        return HttpResponseServerError("Malformed data!")
    data = check_json_data(request)
    dict = {}
    dict['value'], dict['quality'], access_rights, dict['time'] = connect.read(
        data['server'], data['name'])

    return HttpResponse(json.dumps(dict), mimetype='application/json')
def alarm(server,name,condition,value_limit,email):
    
    value,quality,access_rights,time=connect.read(server,name)    #Lectura del valor del ciente opc
    
    if condition=='greater':
        value_limit=float(value_limit)     #La variable se convierte de string a float
        value=float(value)     #La variable se convierte de string a float
        if  value > value_limit:
            send_mail('Online Scada Alarm', 'The variable ' + str(name) + ' on server ' + str(server) + ' is greater than its value limit '+ str(value_limit) + 
                      '. The actual value is '+str(value)+'.','*****@*****.**',[str(email)], fail_silently=False)
    
    if condition=='less':
        value_limit=float(value_limit)     
        value=float(value)     

        if  value < value_limit:
            send_mail('Online Scada Alarm', 'The variable ' + str(name) + ' on server ' + str(server) + ' is lesser than its value limit '+ str(value_limit)+ 
                      '. The actual value is '+str(value)+'.','*****@*****.**',['*****@*****.**'], fail_silently=False)
    
    if condition=='equal':
        value_limit=float(value_limit)     
        value=float(value)     
        if  value == value_limit:
            send_mail('Online Scada Alarm', 'The variable ' + str(name) + ' on server ' + str(server) + ' is equal to its limit '+ str(value_limit),
                      '*****@*****.**',['*****@*****.**'], fail_silently=False)

    if condition=='not equal':
        value_limit=float(value_limit)     
        value=float(value)     
        if  value != value_limit:
            send_mail('Online Scada Alarm', 'The variable ' + str(name) + ' on server ' + str(server) + ' is not equal to '+ str(value_limit)+ 
                      '. The actual value is '+str(value)+'.','*****@*****.**',['*****@*****.**'], fail_silently=False)
    return 
    
    
    
def store_value(server,name):
    value,quality,access_rights,time=connect.read(server,name)
    t = TimeSeries(server=server, name=name, value=value, time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
    t.save()
    return 
def get_writable_variables(user):
    variable_list=variable_list_django_db(user)
    i=0
    while i<len(variable_list):
        variable_list[i].value,variable_list[i].quality,variable_list[i].access_rights,time=connect.read(variable_list[i].server,variable_list[i].name)
        if variable_list[i].access_rights =='Read':
            del variable_list[i]
        i=i+1

    return variable_list