Exemplo n.º 1
0
def createSummaryFromDay(day, daybefore):
    try:
        c.execute("CREATE TABLE daytemp AS SELECT quantity,typeName,typeID,price,transactionType FROM transactions WHERE transactionDateTime <= {1} AND transactionDateTime > {2}".format(id, timegm(day.utctimetuple()), timegm(daybefore.utctimetuple())))
    except:
        print "Unexpected error:", sys.exc_info()[0], sys.exc_info()[1]
        print "Exception on createDay"
        return

    dmy = day.strftime("%Y%m%d")

    items = set()

    for name in settings.included_items:
        typeID = evedb.getTypeIDfromTypeName(name)
        if typeID == -1:
            print 'Unable to find {0} in item database'.format(name)
            pass
        else:
            items.add(typeID)

    for item in items:
        bought = 0
        boughtCost =0
        sold = 0
        soldCost = 0
        try:
            c.execute("SELECT quantity,typeName,typeID,price,transactionType FROM daytemp WHERE typeID={0}".format(item))
            rows = c.fetchall()
            for row in rows:
                if row[4] == 'buy':
                    bought += row[0]
                    boughtCost += row[0] * row[3]
                else:
                    sold += row[0]
                    soldCost += row[0] * row[3]

            if rows:
                try:
                    c.execute('''INSERT or REPLACE INTO summary values (?, ?, ?, ?, ?, ?)''',(item, dmy, bought, boughtCost, sold, soldCost))
                    conn.commit()
                except:
                    print "Unexpected error:", sys.exc_info()[0], sys.exc_info()[1]
                    print "Exception on summary insert"

        except:
            print "Unexpected error:", sys.exc_info()[0], sys.exc_info()[1]
            print "Exception on price processing on daytemp select"

    try:
        c.execute("DROP TABLE daytemp")
        conn.commit()
    except:
        print "Unexpected error:", sys.exc_info()[0], sys.exc_info()[1]
        print "Exception on dropping daytemp"
Exemplo n.º 2
0
    for transaction in transactionsByRefTypeID[brokers_fee]:
        if transaction.refID not in matched_broker:
            print 'Unmatched broker fee {0} for {1}'.format(transaction.refID,transaction.amount)
            print transaction

if __name__ == '__main__':
    marketdb.setupdb()
    assetdb.setupdb()
    evedb.setupdb()
    included_items_ids = set()
    #parser = argparse.ArgumentParser(description='Options')
    #parser.add_argument('-n', '--name', dest='name', default=settings.name)
    #args = parser.parse_args()

    for name in settings.included_items:
        typeID = evedb.getTypeIDfromTypeName(name)
        if typeID == -1:
            print 'Unable to find {0} in item database'.format(name)
            pass
        else:
            included_items_ids.add(typeID)

    for typeID in included_items_ids:
        stock = assetdb.stockByTypeID(typeID)
        bought, boughtCost, sold, soldCost, value = marketdb.itemValueOverPeriod(settings.valuePeriod,typeID)
        origstock = stock - bought + sold
    #    if origstock < 0:
    #        origstock = 0
    #    if origstock:
    #        avgstock = ((origstock + stock) / 2) / settings.valuePeriod
    #    else: