def upload_portfolio_allocations(user_id, portfolio_id, filename, name): df = pd.read_excel(filename) db = Connection() table = db.get_table("Portfolio") info = lambda f: { "HashKey": f["CoinID"], "Name": f["Name"], "Allocation": Decimal(str(f["Allocation"])) } allocs = [info(df.iloc[i]) for i in range(len(df))] for a in allocs: coin = db.get_coin(a['HashKey'], get_ts=True) if len(coin.Performance) < 6: a['Allocation'] = Decimal(0) updates = {"Allocations": {"Value": allocs, "Action": "PUT"}} key = {"CompanyID": user_id, "HashKey": portfolio_id} table.update_item(Key=key, AttributeUpdates=updates) port = Portfolio({ "HashKey": portfolio_id, "Allocations": allocs, "Name": name }) proforma = port.calc_proforma(db) recalculate_portfolio_coin(portfolio_id, user_id, proforma, name, db)
def save_session(session): db = Connection() table = db.get_table("Session") table.put_item(Item=session)
def get_session(sessionid): db = Connection() table = db.get_table("Session") res = table.get_item(Key={"HashKey":sessionid}) return res['Item'] if res_ok(res) else def_sess(sessionid)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Oct 31 13:11:48 2016 @author: coin-ai """ from datalib.datalib import Connection from datalib.coin import Coin from datetime import datetime from analytics.time_series import get_frequency db = Connection() COINS = db.get_all_coins() table = db.get_table("COIN") for COIN in COINS: # print(COIN.Name) ts = COIN.Performance T = len(ts) mx = int(max(ts.index).timestamp()) mn = int(min(ts.index).timestamp()) item = COIN.to_db_item() item['MaxDate'] = mx item['MinDate'] = mn item['Frequency'] = get_frequency(ts) item['T'] = T table.put_item(Item=item) # print("COIN updated: %s" % COIN.Name)