Пример #1
0
def statsGraphs():
    dbConn = DbConnector('wurst.db')
    opens = dbConn.getStatOpen()
    dbConn.close()
    usedNum = []
    usedDate = []
    genNum = []
    genDate = []

    for date, use in sorted(opens['used'], key=lambda tup: tup[0]):
        if (len(usedNum) > 0):
            usedNum.append(usedNum[-1] + use)
        else:
            usedNum.append(use)
        usedDate.append(datetime.datetime.fromtimestamp(date))
    for date, gen in sorted(opens['generated'], key=lambda tup: tup[0]):
        if (len(genNum) > 0):
            genNum.append(genNum[-1] + gen)
        else:
            genNum.append(gen)
        genDate.append(datetime.datetime.fromtimestamp(date))
    # output to static HTML file
    root_dir = os.path.dirname(os.getcwd())

    output_file(os.path.join(root_dir, 'tmp', "lines.html"))

    # create a new plot with a title and axis labels
    p = figure(title="Wurst Down Chart",
               x_axis_label='Date',
               y_axis_label='',
               x_axis_type="datetime",
               plot_width=1000,
               plot_height=600)

    p.yaxis.major_tick_line_color = None  # turn off y-axis major ticks
    p.yaxis.minor_tick_line_color = None  # turn off y-axis minor ticks
    p.yaxis.visible = False

    # add a line renderer with legend and line thickness
    p.line(usedDate,
           usedNum,
           legend="used Wurstchers",
           line_width=2,
           color='#be1e3c')
    p.line(genDate,
           genNum,
           legend="generated Wurstchers",
           line_width=2,
           color='#66b4d3')
    p.line(usedDate,
           list(600 - np.asarray(usedNum)),
           legend="Wurst Reserve",
           line_width=2,
           color='#e16d00')
    p.legend.location = "top_left"

    # show the results
    save(p)
    time.sleep(0.1)
    return send_from_directory(os.path.join(root_dir, 'tmp'), 'lines.html')
Пример #2
0
def getCode():
    dbConn = DbConnector('wurst.db')
    attr = json.loads(request.data.decode())
    try:
        code = dbConn.getCode(attr['volume'], attr['method'])
        ret = {'code': code}
    except InvalidPubMethodError as e:
        ret = {'error': e.message}
    dbConn.close()
    return json.dumps(ret)
Пример #3
0
def methodStuff(method):
    dbConn = DbConnector('wurst.db')
    if request.method == 'PUT':
        dbConn.addPubMethod(method)
        return ''
    if request.method == 'POST':
        dbConn.enablePubMethod(method)
        return ''
    if request.method == 'DELETE':
        dbConn.blackList(method)
        return ''

    dbConn.close()
Пример #4
0
def statsOpen():
    dbConn = DbConnector('wurst.db')
    opens = dbConn.getStatOpen()
    dbConn.close()
    return json.dumps(opens)
Пример #5
0
def checkCode(code):
    dbConn = DbConnector('wurst.db')
    valid = dbConn.checkCode(code)
    dbConn.close()
    return json.dumps({'valid': valid})