Ejemplo n.º 1
0
 def clean(self, data):
     data = super(BlueprintTypeField, self).clean(data)
     data = data.strip()
     typeid = get_typeid(data)
     if typeid is None:
         raise forms.ValidationError('Blueprint name not found')
     return get_typename(typeid)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def redo_cache():
    """
    The models cache quite a few names for ids to make display faster.
    Rebuild all of those.
    """
    for obj in BlueprintOriginal.objects.all():
        obj.typename = get_typename(obj.typeid)
        if obj.typename is None:
            print "Bad typeID in BlueprintOriginal: %s" % obj.typeid
        else:
            obj.save()
    for obj in TransactionInfo.objects.all():
        obj.typename = get_typename(obj.transaction.typeid)
        if obj.typename is None:
            print "Bad typeID in TransactionInfo: %s" % obj.typeid
        else:
            obj.save()
    for obj in PriceList.objects.all():
        obj.typename = get_typename(obj.typeid)
        if obj.typename is None:
            print "Bad typeID in PriceList: %s" % obj.typeid
        else:
            obj.save()
    for obj in WantedMarketOrder.objects.all():
        obj.typename = get_typename(obj.typeid)
        if obj.typename is None:
            print "Bad typeID in WantedMarketOrder: %s" % obj.typeid
        else:
            obj.save()
    for obj in StockLevel.objects.all():
        obj.typename = get_typename(obj.typeid)
        if obj.typename is None:
            print "Bad typeID in StockLevel: %s" % obj.typeid
        else:
            obj.save()
    for obj in Stock.objects.all():
        obj.typename = get_typename(obj.typeid)
        if obj.typename is None:
            print "Bad typeID in Stock: %s" % obj.typeid
        else:
            obj.save()
Ejemplo n.º 4
0
def marketorders_view(request):
    lu = LastUpdate.objects.get(name="marketorders").timestamp
    order_set = MarketOrder.objects.all()
    wanted_set = WantedMarketOrder.objects.all()
    pilot_name = None
    if request.GET.get("all") is None:
        pilot_name = request.user.profile.name
        order_set = order_set.filter(characterid=request.user.profile.characterid)
        wanted_set = wanted_set.filter(characterid=request.user.profile.characterid)
    order_dict = {}
    for order in order_set:
        order.station = get_itemname(order.stationid)
        order.typename = get_typename(order.typeid)
        ordertype = order.ordertype
        order_dict.setdefault(order.station, {})
        order_dict[order.station].setdefault(ordertype, [])
        order_dict[order.station][ordertype].append(order)
        if pilot_name is None:
            order.pilotname = get_membername(order.characterid)
        if request.GET.get("all") is None:
            equal = MarketOrder.objects.filter(
                stationid=order.stationid, typeid=order.typeid, ordertype=order.ordertype
            )
            equal = equal.exclude(characterid=request.user.profile.characterid)
            order.othercorp = [get_membername(other.characterid) for other in equal]
    for wanted in wanted_set:
        station = get_itemname(wanted.stationid)
        typename = get_typename(wanted.typeid)
        ordertype = wanted.ordertype
        order_dict.setdefault(station, {})
        order_dict[station].setdefault(ordertype, [])
        if wanted.typeid not in [order.typeid for order in order_dict[station][ordertype]]:
            try:
                pl = PriceList.objects.get(typeid=wanted.typeid)
            except PriceList.DoesNotExist:
                productioncost = 0.0
            else:
                productioncost = pl.productioncost * pl.safetymargin

            price = last_price(ordertype, wanted.stationid, wanted.typeid)
            if ordertype == "sell":
                if price == 0:
                    profitmargin = 0
                else:
                    profitmargin = 1 - (productioncost / price)
                profitperitem = price - productioncost
            else:
                if price == 0:
                    profitmargin = 0
                else:
                    profitmargin = (productioncost - price) / price
                profitperitem = productioncost - price
            order = KeyValue(
                stationid=wanted.stationid,
                stationname=station,
                typeid=wanted.typeid,
                typename=typename,
                ordertype=ordertype,
                expires=datetime.datetime(2000, 1, 1),
                volremaining=0,
                price=price,
                productioncost=productioncost,
                salesperday=0.0,
                trend=0.0,
                expiredays=0,
                profitmargin=profitmargin,
                profitperitem=profitperitem,
                daysremaining=0,
                profitperday=0,
            )
            order_dict[station][ordertype].append(order)
            if request.GET.get("all") is None:
                equal = MarketOrder.objects.filter(
                    stationid=order.stationid, typeid=order.typeid, ordertype=order.ordertype
                )
                equal = equal.exclude(characterid=request.user.profile.characterid)
                order.othercorp = [get_membername(other.characterid) for other in equal]

    order_list = []
    for station, otypes in order_dict.items():
        newotypes = {}
        for ordertype, orders in otypes.items():
            newotypes[ordertype] = sorted(orders, key=lambda o: o.typename)
        order_list.append((station, newotypes))
    return direct_to_template(
        request,
        "industry/marketorders.html",
        extra_context={"pilot_name": pilot_name, "order_list": order_list, "lastupdate": lu},
    )
Ejemplo n.º 5
0
 def typename(self):
     return get_typename(self.typeid)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
def add_transaction_info(grd):
    api = apiroot()
    standingmap = dict((row.contactID, row.standing)
                       for row in grd.ContactList().allianceContactList)
    for entry in Transaction.objects.filter(info=None):
        info = TransactionInfo()
        info.transaction = entry
        info.account = Account.objects.get(accountkey=entry.accountkey)
        info.typename = get_typename(entry.typeid)
        if info.typename is None:
            continue
        try:
            pl = PriceList.objects.get(typeid=entry.typeid)
            info.cost = pl.productioncost
            info.safetymargin = pl.safetymargin
        except PriceList.DoesNotExist:
            try:
                index = Index.objects.filter(typeid=entry.typeid)[0:1].get()
                info.cost = index.republic
                info.safetymargin = 1.0
            except Index.DoesNotExist:
                info.cost = 0.0
                info.safetymargin = 1.1
        info.stationname = get_itemname(entry.stationid)
        if entry.characterid is not None:
            info.charactername = get_membername(entry.characterid)
        try:
            charinfo = api.eve.CharacterInfo(characterID=entry.clientid)
        except:
            pass
        else:
            info.clientname = charinfo.characterName
            info.clientstanding = standingmap.get(charinfo.characterID, None)
            info.clientcorp = charinfo.corporation
            info.clientcorpid = charinfo.corporationID
            info.clientcorpstanding = standingmap.get(charinfo.corporationID,
                                                      None)
            if hasattr(charinfo, 'allianceID'):
                info.clientalliance = charinfo.alliance
                info.clientallianceid = charinfo.allianceID
                info.clientalliancestanding = standingmap.get(
                    charinfo.allianceID,
                    None)
            info.save()
            transaction.commit()
            continue
        # It's a CorporationID!
        info.clientname = None
        info.clientstanding = None
        info.clientcorpid = entry.clientid
        name = get_itemname(entry.clientid)
        if name is not None: # NPC corp
            info.clientcorp = name
            info.clientcorpstanding = standingmap.get(entry.clientid, None)
            info.save()
            transaction.commit()
            continue
        # Player corp
        try:
            corpinfo = api.eve.CorporationSheet(corporationID=entry.clientid)
        except: # Something bad happened, ignore this
            transaction.rollback()
            continue
        info.clientcorp = corpinfo.corporationName
        info.clientcorpstanding = standingmap.get(corpinfo.corporationID,
                                                  None)
        if hasattr(corpinfo, 'allianceID'):
            info.clientalliance = corpinfo.allianceName
            info.clientallianceid = corpinfo.allianceID
            info.clientalliancestanding = standingmap.get(corpinfo.allianceID,
                                                          None)
        info.save()
        transaction.commit()
Ejemplo n.º 9
0
 def from_typename(cls, typename):
     typeid = get_typeid(typename)
     if typeid is None:
         raise RuntimeError("typename %r does not exist" % typename)
     typename = get_typename(typeid)
     return cls(typeid=typeid, typename=typename)