예제 #1
0
def valores():
    '''Retorna valores'''
    rand_pot = lambda : "%.2f Kw" % (randrange(1,250)/10.)
    rand_pot_r = lambda : "%.2f KVa" % (randrange(1,250)/10.)
    rand_current = lambda : "%.2f KVa" % (randrange(1000,5000)/10.)
    rand_volt = lambda : "%.2f V" % (randrange(10000, 14000)/100.)
    
    from models import Profile, COMaster, VarSys, IED, AI, DI
    comaster = Profile.by_name('default').comaster_set.get(address='192.168.1.97')
    
    ied1 = IED.get(co_master=comaster, addr_485_IED=1)
    ied2 = IED.get(co_master=comaster, addr_485_IED=2)
    ied3 = IED.get(co_master=comaster, addr_485_IED=3)
    
    potencia_2 = AI.get(id=2).value
    potencia_2 = ("%s W" % (potencia_2 * 1.09)) if potencia_2 != 0x4000 else '0 KW'
    
    potencia_r_2 = AI.get(id=3).value
    potencia_r_2 = ("%s VA" % (potencia_r_2 * 1.09)) if potencia_r_2 != 0x4000 else '0 KW'
        
    return jsonify({
        # Potencia 
        'potencia-1': rand_pot(),
        #'potencia-2': AI.get(ied=ied2, offset=0).value,
        # FIXME: Indirección correcta
        'potencia-2': potencia_2,
        'potencia-3': rand_pot(),
        'potencia-4': rand_pot(),
        # Potencias reactivas
        'potencia-r-1': rand_pot_r(),
        #'potencia-r-2': AI.get(ied=ied2, offset=1).|value,
        'potencia-r-2': potencia_r_2,
        'potencia-r-3': rand_pot_r(),
        'potencia-r-4': rand_pot_r(),
        # Corrientes
        'corriente-1': rand_current(),
        'corriente-2': rand_current(),
        'corriente-3': rand_current(),
        'corriente-4': rand_current(),
        
        #'tension-1': "%.2f Kv" % AI.get(ied=ied1, offset=0).value,
        'tension-1': "%.2f Kv" % (AI.get(id=1).value /float(100)),  
        
        'interruptor-1': DI.get(ied=ied1, port=1, bit=0).value, 
        'interruptor-2': DI.get(ied=ied1, port=1, bit=1).value,
        })
예제 #2
0
def analog_inputs():
    """docstring for analog_inputs"""
    from flask_peewee.serializer import Serializer
    from models import AI
    from json import dumps    
    return dumps(dump(AI.select(), skip=['ied']))
예제 #3
0
 def iterais():
     # Iterar ieds
     for ied in self.factory.comaster.ied_set.order_by('offset'):
         # Itera por ais
         for ai in AI.filter(ied=ied).order_by('offset'):
             yield ai