Example #1
0
def everpc_GetFacWarData(user, args):
    cachetimestamp = wintime_to_datetime(args['timestamp'])
    upload = Upload.objects.create(user=user,
                                   cachetimestamp=cachetimestamp,
                                   method='map.GetVictoryPoints')
    for row in args['map']:
        if row['factionid'] is None:
            c = connection.cursor()
            c.execute("SELECT COALESCE(s.factionid, c.factionid, r.factionid) "
                      "FROM ccp.mapsolarsystems s "
                      "     INNER JOIN ccp.mapconstellations c "
                      "       ON s.constellationid = c.constellationid "
                      "     INNER JOIN ccp.mapregions r "
                      "       ON c.regionid = r.regionid "
                      "WHERE s.solarsystemid = %s", (row['systemid'],))
            row['factionid'] = c.fetchone()[0]
        if not FacWarSystemHistory.objects.filter(
            cachetimestamp=cachetimestamp).exists():
            # Not known yet
            FacWarSystemHistory.objects.create(
                upload=upload,
                cachetimestamp=cachetimestamp,
                solarsystemid=row['systemid'],
                occupyingfactionid=row['factionid'],
                victorypoints=row['current'],
                threshold=row['threshold']
                )
        obj, created = FacWarSystem.objects.get_or_create(
            solarsystemid=row['systemid'],
            defaults={'upload': upload,
                      'cachetimestamp': cachetimestamp,
                      'solarsystemid': row['systemid'],
                      'solarsystemname': '',
                      'occupyingfactionid': row['factionid'],
                      'occupyingfactionname': '',
                      'owningfactionid': 0,
                      'owningfactionname': '',
                      'victorypoints': row['current'],
                      'threshold': row['threshold']
                      })
        if created:
            obj.solarsystemname = dbutils.get_itemname(obj.solarsystemid)
            obj.occupyingfactionname = dbutils.get_itemname(
                obj.occupyingfactionid)
            obj.owningfactionid = dbutils.get_systemfaction(obj.solarsystemid)
            obj.owningfactionname = dbutils.get_itemname(obj.owningfactionid)
        elif cachetimestamp > obj.cachetimestamp:
            obj.cachetimestamp = cachetimestamp
            obj.occupyingfactionid = row['factionid']
            obj.occupyingfactionname = dbutils.get_itemname(row['factionid'])
            obj.threshold = row['threshold']
            obj.victorypoints = row['current']
            obj.save()
Example #2
0
 def clean(self, data):
     data = super(StationField, self).clean(data)
     data = data.strip()
     stationid = get_itemid(data)
     if stationid is None:
         raise forms.ValidationError('Station not found')
     return get_itemname(stationid)
Example #3
0
def stocks_view(request, watched=False):
    lu = LastUpdate.objects.get(name='stocks').timestamp
    stock_dict = {}
    if watched:
        qs = request.user.stocklevel_set.all()
    else:
        qs = StockLevel.objects.all()
    for stock in qs:
        station = get_itemname(stock.stationid)
        stock_dict.setdefault(station, [])
        stock_dict[station].append(stock)
    return direct_to_template(request, 'industry/stocks.html',
                              extra_context={'lastupdate': lu,
                                             'watched': watched,
                                             'station_list': sorted(stock_dict.items())})
Example #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},
    )
Example #5
0
 def stationname(self):
     return get_itemname(self.stationid)
Example #6
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()