Пример #1
0
def potencias_historicas():
    from datetime import date, time, datetime, timedelta
    d = datetime.combine(date.today(), time(0, 0, 0))
    next = datetime.today() + timedelta(days=1)
    data = []
    while d < next:
        data.append([d, randrange(1,100)])
        d += timedelta(minutes=randrange(1,60))
    return dumps(dict(data=data))
Пример #2
0
def energy_values():
    '''
    '''
    params = parseparams(request.values)
    
    #print params
    today_midnight = datetime.combine(date.today(), time(0, 0, 0))
    data = generate_pq_for_day(today_midnight)
    #data = data[:params['display_length']]
    
    paged = data[:params.get('display_length', 96)]
    return dumps({
                  'aaData': paged,
                  'iTotalRecords': len(data),
                  #'iTotalDisplayRecords': len(paged),
                  })
Пример #3
0
def events():
    '''Events'''
    from datetime import datetime
    import models
    params = parseparams(request.values)
    #models.Profile.get(name='default').comaster_
    events = models.Event.select().order_by(('timestamp', 'desc')).limit(params.get('display_length', 10))
    aaData = []
    for ev in events:
        descs = ['Apertura' if ev.value else 'Cierre     ',  'de Interruptor campo %d' % ev.di.bit, "(%s)" % ev.di, ]
        desc = ' '.join(map(unicode, descs))
        
        aaData.append(["Estacion 1", ev.value, desc, "%s.%.2f" % (ev.timestamp.strftime('%x %X'), ev.subsec)])
    #aaData = [('Estación 1', '1', 'Descripcion %d' % d, datetime.now())
    #          for d in range(10)]
    return dumps(dict(aaData=aaData, iTotalRecords=len(aaData)))
Пример #4
0
def energy_by_day(day, month, year):
    from models import Energy
    try:
        assert 1970 <= year <= 2050, "Invalid year"
        base=datetime(year, month, day)
    except ValueError:
        return "Invalid date"
    except AssertionError as e:
        return unicode(e)
    year = int(year)
    month = int(month)
    day = int(day)
    
    start = datetime(year, month, day, 0, 0, 0)
    end = datetime(year, month, day, 23, 59, 59)
    qs = Energy.filter(address=2)
    qs = qs.filter(timestamp__gte=start).filter(timestamp__lt=end)
    qs.order_by('timestamp')
    def maketuple(e):
        return e.timestamp.isoformat(), e.val, e.val
    data = [maketuple(e) for e in qs ]
    
    return dumps(dict(data=data))
Пример #5
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']))