Exemple #1
0
 def POST(self):
     data = web.input()
     print data.condition
     if data.queryType == 'where':
         values = db.queryAll(data.tableName, data.condition, data.orderCondition)
         cols = db.getColumns(data.tableName)
     elif data.queryType == 'full':
         cols = []
         values = db.execQuery(data.condition)
     returnMap = {"v":values,"k":cols}
     return json.dumps(returnMap,cls=CJsonEncoder)
Exemple #2
0
def getCorrelation():
    results = db.execQuery("""
        select epoch, price from historic where coin='bitcoin' 
        and epoch >= (UNIX_TIMESTAMP(STR_TO_DATE('Jan 1 2014', '%%M %%d %%Y')) * 1000) 
        and epoch < (UNIX_TIMESTAMP(STR_TO_DATE('Mar 29 2014', '%%M %%d %%Y')) * 1000)
        limit 10000;
        """)
    data = [(tick[0], float(tick[1])) for tick in results]
    price = pd.DataFrame.from_records(data, columns=["epoch", "2014"])
    price['2015'] = getPriceSeries("2015").values
    price['2016'] = getPriceSeries("2016").values
    price['2017'] = getPriceSeries("2017").values
    price['2018'] = getPriceSeries("2018").values
    c = price.corr()
    sns.heatmap(c, xticklabels=c.columns.values, yticklabels=c.columns.values)
    plt.show()
Exemple #3
0
def getCoinTicks(coin="bitcoin", reset=False):
    jump_start = 0
    e_start = 0
    e_end = 999999999999999
    if reset:
        db.execUpdate("delete from historic where coin=%s", (coin, ))
    else:
        max_epoch = db.execQuery(
            """
            select max(epoch) from historic where coin=%s
            """, (coin, ))
        if max_epoch[0][0] is not None:
            jump_start = int(max_epoch[0][0])

    base_url = "https://graphs2.coinmarketcap.com/currencies/" + coin + "/"
    url = base_url + str(e_start) + "/" + str(e_end)
    page = requests.get(url)
    data = json.loads(page.content)
    days = [int(tick[0]) for tick in data["price_btc"]]
    for i, day in enumerate(days):
        if i + 1 != len(days):
            if jump_start > days[i + 1]:
                continue
        e_start = day
        if i + 1 == len(days):
            e_end = e_start + 86400000
        else:
            e_end = days[i + 1]
        url = base_url + str(e_start) + "/" + str(e_end)
        page = requests.get(url)
        data = json.loads(page.content)
        for mc, price, vol in zip(data["market_cap_by_available_supply"],
                                  data["price_usd"], data["volume_usd"]):
            epoch = mc[0]
            db.execUpdate(
                """
                insert ignore into historic(coin, epoch, marketcap, price, vol)
                values(%s,%s,%s,%s,%s)
                """, (coin, epoch, mc[1], price[1], vol[1]))
    db.execUpdate(
        "update historic set dt=from_unixtime(epoch/1000.) where dt is null")
Exemple #4
0
 def POST(self):
     data = web.input()
     result = db.execQuery("show create table "+ data.tableName)
     return json.dumps(result)
Exemple #5
0
    def GET(self):
        global fullname
        fullname =''
        if need_login and session is not None:
            fullname = web.cookies().get('fullname')
            if fullname is None or fullname=='' or fullname not in whiteList:
                #web.redirect(openid.REDIRECT_URL)
                return "not authed"
            else:
                print 'welcome,'+fullname
        render = web.template.render('html/')
        tables=db.initTables()
        return render.index(tables=tables,fullname=fullname,target=target)

class CJsonEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime):
            return obj.strftime('%Y-%m-%d %H:%M:%S')
        elif isinstance(obj, date):
            return obj.strftime('%Y-%m-%d')
        elif isinstance(obj, decimal.Decimal):
            return float(obj)
        else:
            return json.JSONEncoder.default(self, obj)

if __name__ == "__main__":
    print "1. check encoding..."
    print db.execQuery("show variables like 'character_set_%';")
    print "2. web container starting..."
    app.run()