Exemple #1
0
def getorders(item, location, order_type):
    order_type = order_type.lower()
    if isinstance(item, str): item = auxdatatools.getitemid(item)
    if isinstance(location, str):
        location = auxdatatools.getlocationid(location)

    region = auxdatatools.getlocationregion(location)

    if order_type == 'buy':
        url, params = crest.getcresturl('BuyOrders',
                                        regionID=region,
                                        typeID=item)
    elif order_type == 'sell':
        url, params = crest.getcresturl('SellOrders',
                                        regionID=region,
                                        typeID=item)
    else:
        raise Exception()

    regionOrders = crest.getcrestdata(url, params)['items']

    if auxdatatools.isregion(location):
        return regionOrders
    elif auxdatatools.issystem(location) or auxdatatools.isstation(location):
        return selectordersbylocation(regionOrders, location)
Exemple #2
0
def iteminpricelist(item, pricelist, order_type):
    item = auxdatatools.getitemid(item)

    if item in pricelist:
        if order_type in pricelist[
                item] and pricelist[item][order_type] != None:
            return True

    return False
Exemple #3
0
def getdailystats(item, region, days_back=1):
    # CREST history returns data for previous 13 months, days_back specifies how many days of data to retrieve
    # days_back = 1 will get just yesterday's data
    if isinstance(item, str): item = auxdatatools.getitemid(item)
    if isinstance(region, str): region = auxdatatools.getregionID(region)

    stats = crest.getcrestdata(
        crest.getcresturl('DailyStats', regionID=region, typeID=item))['items']

    return list(reversed(stats))[0:days_back]
Exemple #4
0
def getbasecostforitem(item):
    item = auxdatatools.getitemid(item)

    if 'baseCost' not in sqlitetools.columnsindbtable(presets.auxdataDB, 'Items'):
        baseCost = calcbasecostforitem(item)
    else:
        baseCost = sqlitetools.getxbyyfromdb(presets.auxdataDB, 'Items', 'baseCost', 'typeID', item)
        if not baseCost: baseCost = calcbasecostforitem(item)

    return baseCost
Exemple #5
0
def getinventmats(invent_type, decryptortype='NONE'):
    # get list materials need for invention - datacores, decryptor (if specified), and hull section (if applicable) (T1 BPCs are not counted)
    # invent_type: either the T2/T3 item desired (or its BP), or the T1 item invented from (or its BP)

    if auxdatatools.isT2(invent_type): # if we've been given a T2/T3 item, we must find out what it's invented from
        invent_type = auxdatatools.getinventbase(invent_type)
        if isinstance(invent_type, list) or isinstance(invent_type,tuple): raise Exception('Multiple invention bases found: %s' % invent_type) # this will fail if given a T3 hull/component, as there are multiple things it could be invented from
    elif auxdatatools.ishullsection(invent_type):
        invent_type = auxdatatools.getitemid(invent_type) # hull sections appear as items, but are actually BPs - so we just need to get the ID and we're good to go
    elif auxdatatools.isitem(invent_type): # we've been given something T1...
        if auxdatatools.isbp(invent_type): # T1 BP
            invent_type = auxdatatools.getitemid(invent_type)
        else: # T1 item
            invent_type = auxdatatools.getbpIDforitem(invent_type)

    invent_mats = auxdatatools.getmatsforbp(invent_type, activity='Invention') # datacores
    if decryptortype != 'NONE': invent_mats = combinematslists(invent_mats, {decryptortype+' Decryptor': 1}) # decryptor (if applicable)
    if auxdatatools.ishullsection(invent_type): combinematslists(invent_mats, {invent_type: 1})

    return invent_mats
Exemple #6
0
def get_matslist_cost_from_pricelist(matslist, pricelist, order_type, return_type):
    totalcost = 0
    matscostslist = {}
    for mat in matslist:
        matID, quantity = auxdatatools.getitemid(mat), matslist[mat]
        matcost = pricelist[matID][order_type] * quantity
        if return_type == 'total': totalcost += matcost
        if return_type == 'list': matscostslist[matID] = matcost

    if return_type == 'total':
        return totalcost
    elif return_type == 'list':
        return matscostslist
Exemple #7
0
def addmissingitemstopricelist(items, pricelist, order_type, location='Jita'):
    if isinstance(items, str) or isinstance(items, int): items = [items]

    missingitems = []
    for item in items:
        item = auxdatatools.getitemid(item)
        if not iteminpricelist(item, pricelist, order_type):
            missingitems.append(item)

    if missingitems:
        pricelist = combinepricelists(
            pricelist, getpricelist(items, order_type, location))

    return pricelist
Exemple #8
0
def getpricelist(items, order_type, location='Jita'):
    # get a dict of buy or sell prices for list of items, at a given location
    # items: list of items (name or ID), or list of materials e.g. ((item1, quantity1), (item2, quantity2))
    # returned dict is of form {item1ID : {order_type : price}}

    if isinstance(items, str) or isinstance(items, int):
        items = [items]  # so we can iterate if there's just one item
    elif (isinstance(items, list) or isinstance(items, tuple)) and (isinstance(
            items[0], list) or isinstance(items[0], tuple)):
        items = [ii[0] for ii in items
                 ]  # if we have a materials list, get just the items

    pricelist = {}

    if verbose > 1: counter, print_str = 0, ''
    for item in items:
        if verbose > 1:
            counter += 1
            if len(print_str) > 0: print('\r' + ' ' * len(print_str), end='\r')
            print_str = 'Getting price for item %s/%s...' % (counter,
                                                             len(items))
            print(print_str, end='')
            sys.stdout.flush()

        item = auxdatatools.getitemid(item)

        price = getitemstats(item,
                             location,
                             order_type,
                             get_region_stats=False,
                             return_type='dict')['percentilePrice']

        if item not in pricelist: pricelist[item] = {}
        pricelist[item][order_type] = price

    if verbose > 1: print('done')

    return pricelist
Exemple #9
0
def calcbuildcosts(product, productRuns, **kwargs):
    if 'bpMaxRuns' not in kwargs or not kwargs['bpMaxRuns']:
        bpMaxRuns = 99999
    else:
        bpMaxRuns = kwargs['bpMaxRuns']
    
    if 'baseMatsList' not in kwargs or not kwargs['baseMatsList']:
        passargdict = {'item' : product, 'n_produced' : productRuns}
        for arg in ('ME','production_efficiences','ME_components','production_efficiences_components','bpMaxRuns','bpMaxRuns_components'):
            if arg in kwargs: passargdict[arg] = kwargs[arg]

        baseMatsList = getbasematsforitem(**passargdict)

    else:
        baseMatsList = kwargs['baseMatsList']

    basematids = [ii for ii in baseMatsList]

    if 'componentsList' not in kwargs or not kwargs['componentsList']:
        passargdict = {'item' : product, 'n_produced' : productRuns}
        for arg in ('ME','production_efficiences','bpMaxRuns'):
            if arg in kwargs: passargdict[arg] = kwargs[arg]

        componentsList = getmatsforitem(**passargdict)

    else:
        componentsList = kwargs['componentsList']

    if 'buySystem' not in kwargs or not kwargs['buySystem']:
        buySystem = 'Jita'
    else:
        buySystem = kwargs['buySystem']

    if 'buildLocation' not in kwargs or not kwargs['buildLocation']:
        buildLocation = 'POS'
    else:
        buildLocation = kwargs['buildLocation']

    if 'systemModifier' not in kwargs or not kwargs['systemModifier']:
        systemModifier = 0.025
    else:
        systemModifier = kwargs['systemModifier']

    if 'baseMatsPriceList' in kwargs and kwargs['baseMatsPriceList']:
        baseMatsPriceList = kwargs['baseMatsPriceList']
    else:
        if verbose: print('Pulling prices...')
        baseMatsPriceList = evemarket.getpricelist(basematids, 'buy', buySystem)
    
    baseMatsCosts = get_matslist_cost_from_pricelist(baseMatsList, baseMatsPriceList, order_type='buy', return_type='list')

    baseMatsBuyFees = {}
    for basematID, basematcost in baseMatsCosts.items(): baseMatsBuyFees[basematID] = evemarket.calcbuyfee(basematcost, 'buy', skillBrokerRelations=1)

    componentsBuildFees = {}
    for compID, comp_qty in componentsList.items():
        if compID in basematids:
            componentsBuildFees[compID] = 0 # for components which are not manufactured
        else:
            componentsBuildFees[compID] = calcjobfee(compID, comp_qty, systemModifier, buildLocation)

    if isinstance(product, str): product = auxdatatools.getitemid(product)

    if productRuns > bpMaxRuns:
        maxruns = floor(productRuns/bpMaxRuns)
        remruns = productRuns - maxruns*bpMaxRuns
        productBuildFee = calcjobfee(product, bpMaxRuns, systemModifier) * maxruns + calcjobfee(product, remruns, systemModifier)
    else:
        productBuildFee = calcjobfee(product, productRuns, systemModifier)
   
    totalCost = sum(baseMatsCosts.values()) + sum(baseMatsBuyFees.values()) + sum(componentsBuildFees.values()) + productBuildFee

    return {
            'baseMatsPriceList' : baseMatsPriceList,
            'baseMatsCosts' : baseMatsCosts,
            'baseMatsBuyFees' : baseMatsBuyFees,
            'componentsBuildFees' : componentsBuildFees,
            'productBuildFee' : productBuildFee,
            'totalCost' : totalCost,
            }
Exemple #10
0
def getrunsfornproducts(product, n_produced):
    # calc number of runs of a BP needed to make desired n of a given product (e.g. if BP produces 100 of product per run and we need 250, we must run BP 3 times)
    product = auxdatatools.getitemid(product)
    bp_output_quantity = sqlitetools.getxbyyfromdb(presets.auxdataDB, 'bpProducts', 'quantity', 'productTypeID', product)

    return(ceil(n_produced / bp_output_quantity))
Exemple #11
0
def getadjpriceforitem(item):
    item = auxdatatools.getitemid(item)

    if 'adjPrice' not in sqlitetools.columnsindbtable(presets.auxdataDB, 'Items'): pulladjprices(updatedb=True)

    return sqlitetools.getxbyyfromdb(presets.auxdataDB, 'Items', 'adjPrice', 'typeID', item)