Ejemplo n.º 1
0
def getCounters(date):
    db = dbOpenDatabase(dbName)
    queryDate, lastMidnight = timeBounds(date)
    dataPoints = sortAndLocalise(integrateRows(
        db,
        queryDate,
    ))
    return {
        'data': dataPoints,
        'now': javaTimestamp(datetime.now()),
    }
Ejemplo n.º 2
0
def getEvents(date):
    '''
        all events for a given date (possibly None->today)
    '''
    db = dbOpenDatabase(dbName)
    queryDate, lastMidnight = timeBounds(date)
    entries = sortAndLocalise(dbGetRows(db, queryDate))
    histo = timeHistogram(entries, barSeconds=barSeconds)
    return {
        'data': histo,
        'now': javaTimestamp(datetime.now()),
    }
Ejemplo n.º 3
0
def getHistory(daysback):
    db = dbOpenDatabase(dbName)
    if daysback != 'forever':
        try:
            dbackInt = int(daysback)
            firstDate = findPreviousMidnight(
                datetime.utcnow()) - timedelta(days=dbackInt - 2)
        except:
            firstDate = None
    else:
        firstDate = None
    dates = dbGetDateList(db, startDate=firstDate)
    history = [
        jHistorizer(integrateRows(db, d, cumulate=False))
        for d in sorted(dates, reverse=True)
    ]
    return {
        'data': history,
        'now': javaTimestamp(datetime.now()),
    }
Ejemplo n.º 4
0
def ep_download_history():
    db = dbOpenDatabase(dbName)
    now = localiseDate(datetime.utcnow())
    # 1. history
    history = getHistory(daysback=None)['data']
    # 2. daily detail
    dates = dbGetDateList(db)
    perDay = {
        tDate: getCounters(tDate.strftime(dateFormat))['data']
        for tDate in dates
    }
    #
    spreadsheet = makeSpreadsheet(history=history, perDay=perDay, now=now)
    #
    spreadsheetFilename = 'opabinia_history_%s.xlsx' % now.strftime(
        fileNameDateFormat)
    return send_file(
        spreadsheet,
        attachment_filename=spreadsheetFilename,
        as_attachment=True,
        last_modified=now,
        cache_timeout=0,
    )
Ejemplo n.º 5
0
def ep_chooseday(target='counters'):
    db = dbOpenDatabase(dbName)
    dates = dbGetDateList(db)
    dateTree = makeDateListToTree(dates)

    # these are the names of the endpoint functions!
    epname = {
        'counters': 'ep_counters',
        'events': 'ep_events',
    }.get(target, 'ep_counters')
    eptitle = {
        'counters': 'Counts',
        'events': 'Hits',
    }.get(target, 'Counts')

    return render_template(
        'chooseday.html',
        pagetitle='Select the date for %s' % eptitle,
        datetree=dateTree,
        epname=epname,
        monthnames=monthNames,
        dateFormat=dateFormat,
    )
Ejemplo n.º 6
0
def getCurrentStatus(now):
    db = dbOpenDatabase(dbName)
    curStatus = integrateRows(db, now.date(), cumulate=False)
    return curStatus