Пример #1
0
def update_journal(grd, accountkey):
    def save_entry(entry):
        try:
            Journal.objects.get(journalid=entry.refID)
            return
        except Journal.DoesNotExist:
            pass
        Journal.objects.create(
            journalid=entry.refID,
            accountkey=accountkey,
            timestamp=datetime.datetime.utcfromtimestamp(entry.date),
            reftypeid=entry.refTypeID,
            amount=entry.amount,
            ownerid1=entry.ownerID1,
            ownerid2=entry.ownerID2,
            argname1=entry.argName1,
            argid1=entry.argID1,
            reason=entry.reason
            )
    gwj = grd.WalletJournal(rowCount=ROWS, accountKey=accountkey)
    set_last_update('journal',
                    datetime.datetime.utcfromtimestamp(gwj._meta.currentTime))
    for entry in gwj.entries:
        save_entry(entry)
    while len(gwj.entries) >= ROWS:
        fromid = min(entry.refID for entry in gwj.entries)
        gwj = grd.WalletJournal(fromID=fromid,
                                rowCount=ROWS,
                                accountKey=accountkey)
        for entry in gwj.entries:
            save_entry(entry)
Пример #2
0
def update_transaction(grd, accountkey):
    def save_entry(entry):
        try:
            Transaction.objects.get(transactionid=entry.transactionID)
            return
        except Transaction.DoesNotExist:
            pass
        Transaction.objects.create(
            transactionid=entry.transactionID,
            accountkey=accountkey,
            timestamp=datetime.datetime.utcfromtimestamp(entry.transactionDateTime),
            typeid=entry.typeID,
            quantity=entry.quantity,
            price=entry.price,
            clientid=entry.clientID,
            characterid=entry.characterID,
            stationid=entry.stationID,
            transactiontype=entry.transactionType,
            journalid=entry.journalTransactionID
            )
    gwt = grd.WalletTransactions(rowCount=ROWS, accountKey=accountkey)
    set_last_update('transactions',
                    datetime.datetime.utcfromtimestamp(gwt._meta.currentTime))
    for entry in gwt.transactions:
        save_entry(entry)
    while len(gwt.transactions) >= ROWS:
        fromid = min(entry.transactionID for entry in gwt.transactions)
        gwt = grd.WalletTransactions(fromID=fromid,
                                     rowCount=ROWS,
                                     accountKey=accountkey)
        for entry in gwt.transactions:
            save_entry(entry)
Пример #3
0
def update_publicmarket():
    log = logging.getLogger('industry')
    for pl in PriceList.objects.all():
        for regionid in [HEIMATAR, METROPOLIS, MOLDENHEATH, THEFORGE]:
            query = urllib.urlencode([('regionlimit', regionid),
                                      ('typeid', str(pl.typeid))])
            url = "http://api.eve-central.com/api/quicklook?" + query
            try:
                data = urllib.urlopen(url).read()
                tree = ElementTree.fromstring(data)
            except Exception as e:
                log.info("Couldn't retrieve public market info for %s: %s" %
                         (pl.typename, str(e)))
            else:
                publicmarket_save(regionid, pl.typeid, tree)
    set_last_update('public-market', datetime.datetime.utcnow())
Пример #4
0
def update_stock(grd):
    stocks = {}
    gal = grd.AssetList()
    set_last_update('stocks',
                    datetime.datetime.utcfromtimestamp(gal._meta.currentTime))
    for asset in gal.assets:
        stationid = make_stationid(asset.locationID)
        if stationid is None: # in space
            continue
        if asset.flag in STOCK_FLAGS:
            stocks.setdefault(stationid, Bag())
            stocks[stationid][asset.typeID] += asset.quantity
        if asset.typeID == OFFICE_TYPEID and hasattr(asset, 'contents'):
            for asset2 in asset.contents:
                if asset2.flag in STOCK_FLAGS:
                    stocks.setdefault(stationid, Bag())
                    stocks[stationid][asset2.typeID] += asset2.quantity

                if (asset2.flag == HANGAR_OUTGOING and
                    asset2.typeID in CAN_TYPEIDS
                    and hasattr(asset2, 'contents')): # Outgoing
                    for asset3 in asset2.contents:
                        stocks.setdefault(stationid, Bag())
                        stocks[stationid][asset3.typeID] += asset3.quantity
    Stock.objects.all().delete()
    for stationid, levels in stocks.items():
        for typeid, quantity in levels.items():
            typename = get_typename(typeid)
            if typename is None:
                typename = '<TypeID %s>' % typeid
            try:
                pl = PriceList.objects.get(typeid=typeid)
            except PriceList.DoesNotExist:
                pl = None
            try:
                sl = StockLevel.objects.get(typeid=typeid,
                                            stationid=stationid)
            except StockLevel.DoesNotExist:
                sl = None
            Stock.objects.create(typename=typename,
                                 typeid=typeid,
                                 stationid=stationid,
                                 current=quantity,
                                 price=pl,
                                 level=sl)
Пример #5
0
def update_marketorder(grd):
    index = IndexCalculator()
    pricelist = dict((p.typename, p.productioncost * p.safetymargin)
                     for p in PriceList.objects.all())
    MarketOrder.objects.all().delete()
    gmo = grd.MarketOrders()
    have_orders = set()
    wanted_orders = {}
    for wmo in WantedMarketOrder.objects.all():
        wanted_orders.setdefault((wmo.characterid, wmo.stationid,
                                  wmo.ordertype), set())
        wanted_orders[(wmo.characterid, wmo.stationid,
                       wmo.ordertype)].add(wmo.typeid)
    set_last_update('marketorders',
                    datetime.datetime.utcfromtimestamp(gmo._meta.currentTime))
    for order in gmo.orders:
        ordertype = 'buy' if order.bid else 'sell'
        expires = (datetime.datetime.utcfromtimestamp(order.issued) +
                   datetime.timedelta(days=order.duration))
        volremaining = order.volRemaining
        if order.orderState != 0:
            volremaining = 0
            expires = datetime.datetime.utcnow()
            if (order.charID, order.stationID,
                ordertype, order.typeID) in have_orders:
                continue
            if order.typeID not in wanted_orders.get((order.charID,
                                                      order.stationID,
                                                      ordertype),
                                                     set()):
                continue
        have_orders.add((order.charID, order.stationID,
                         ordertype, order.typeID))
        typename = get_typename(order.typeID)
        if typename is None:
            typename = '<typeID %s>' % order.typeID
        productioncost = pricelist.get(typename)
        if productioncost is None:
            productioncost = index.materialcost(typename)
        if productioncost is None:
            productioncost = 0.0
        sales7d = get_transactions(ordertype, order.stationID,
                                   order.typeID, 7) / 7.0
        sales28d = get_transactions(ordertype, order.stationID,
                                    order.typeID, 28) / 28.0
        if sales7d > 0:
            salesperday = sales7d
        else:
            salesperday = sales28d
        competitionprice = get_competitionprice(
            ordertype,
            order.stationID,
            order.typeID,
            volremaining,
            order.price,
            order.range
            )
        if sales28d == 0 and sales7d == 0:
            trend = 0.0
        else:
            trend = sales7d / float(sales7d + sales28d)
        MarketOrder.objects.create(
            characterid=order.charID,
            stationid=order.stationID,
            typeid=order.typeID,
            ordertype=ordertype,
            expires=expires,
            volremaining=volremaining,
            price=order.price,
            productioncost=productioncost,
            salesperday=salesperday,
            competitionprice=competitionprice,
            trend=trend)
Пример #6
0
def update_pricelist(grd):
    set_last_update('pricelist', datetime.datetime.utcnow())
    index = IndexCalculator()
    bposet = set()
    inventable = []
    known = set()
    PriceList.objects.all().delete()
    mfglinecosts = get_mfglinecosts()
    for bpo in BlueprintOriginal.objects.all():
        bposet.add(bpo.typeid)
        bptype = InvType(bpo.typeid, bpo.typename)
        product = bptype.product()
        if product is None:
            raise RuntimeError("Can't find product for BPO %s (%s)"
                               % (bpo.typeid, bpo.typename))
        productioncost = index.cost(product.typename)
        if productioncost is None or not productioncost > 0:
            continue
        safetymargin = get_safetymargin(product, mfglinecosts)
        PriceList.objects.create(typename=product.typename,
                                 typeid=product.typeid,
                                 productioncost=productioncost,
                                 safetymargin=safetymargin)
        known.add(product.typeid)
        # We lack the parts for the Anshar...
        if not (product.typename == 'Obelisk' or
                product.group().startswith("Rig ")):
            inventable.extend(bptype.invent_to())

    for bpc in inventable:
        if bpc.typeid in bposet:
            continue
        product = bpc.product()
        productioncost = index.cost(product.typename)
        if productioncost is None or not productioncost > 0:
            continue
        safetymargin = get_safetymargin(product, mfglinecosts)
        PriceList.objects.create(typename=product.typename,
                                 typeid=product.typeid,
                                 productioncost=productioncost,
                                 safetymargin=safetymargin)
        known.add(product.typeid)
    for wmo in WantedMarketOrder.objects.filter(forcorp=True):
        if wmo.typeid in known:
            continue
        typename = get_typename(wmo.typeid)
        typeid = wmo.typeid
        product = InvType(typeid, typename)
        productioncost = index.cost(typename)
        if productioncost is None or not productioncost > 0:
            continue
        safetymargin = 1.02 # Broker's fee of 1%
        PriceList.objects.create(typename=typename,
                                 typeid=typeid,
                                 productioncost=productioncost,
                                 safetymargin=safetymargin)
        known.add(typeid)
    for bpname in SYNTH_BOOSTER_BPC:
        bptype = InvType.from_typename(bpname)
        product = bptype.product()
        if product.typeid in known:
            continue
        productioncost = index.cost(product.typename)
        if productioncost is None or not productioncost > 0:
            continue
        productioncost += 25000 # Per-run BPC cost as per Damian
        PriceList.objects.create(typename=product.typename,
                                 typeid=product.typeid,
                                 productioncost=productioncost,
                                 safetymargin=1.0)
        known.add(product.typeid)