Exemplo n.º 1
0
def main():
    '''
    Main function
    '''

    ore = EveOnlineManufacturingJob(DATA_ACCESS_OBJECT)
    reproc_mat_list = ore.get_mineral_matrix_adjusted(sec_status_low_limit=0.9,
                                                      fclt_base_yield=0.54,
                                                      rprcs_skill_lvl=5,
                                                      rprcs_eff_skill_lvl=5,
                                                      mtrl_spcfc_prcs_skill_lvl=5,
                                                      implant_bonus=0)

    # for simplyfication we filter ore list
    reproc_mat_list_filtered = {}
    reproc_mat_list_filtered[DATA_ACCESS_OBJECT.get_inv_type(type_name='Veldspar')['type_id']] = reproc_mat_list[DATA_ACCESS_OBJECT.get_inv_type(type_name='Veldspar')['type_id']]
#    reproc_mat_list_filtered[DATA_ACCESS_OBJECT.get_inv_item(type_name='Plagioclase')['type_id']] = reproc_mat_list[DATA_ACCESS_OBJECT.get_inv_item(type_name='Plagioclase')['type_id']]
#    reproc_mat_list_filtered[DATA_ACCESS_OBJECT.get_inv_item(type_name='Scordite')['type_id']] = reproc_mat_list[DATA_ACCESS_OBJECT.get_inv_item(type_name='Scordite')['type_id']]
    reproc_mat_list_filtered[DATA_ACCESS_OBJECT.get_inv_type(type_name='Pyroxeres')['type_id']] = reproc_mat_list[DATA_ACCESS_OBJECT.get_inv_type(type_name='Pyroxeres')['type_id']]
    reproc_mat_list = reproc_mat_list_filtered

    # define mineral amounts we want to get refining the ores
    mineral_amounts_desired={}
    mineral_amounts_desired[DATA_ACCESS_OBJECT.get_inv_type(type_name='Tritanium')['type_id']] = 200
    mineral_amounts_desired[DATA_ACCESS_OBJECT.get_inv_type(type_name='Nocxium')['type_id']] = 1
#    mineral_amounts_desired[DATA_ACCESS_OBJECT.get_inv_item(type_name='Pyerite')['type_id']] = 160
#    mineral_amounts_desired[DATA_ACCESS_OBJECT.get_inv_item(type_name='Mexallon')['type_id']] = 80

    # define variables for building matrices
    list_of_mineral_matrices = []
    mineral_amounts_desired_matrix = []
    ore_quantity_matrix = []

    # build matrices for linear programming
    for k_ore,v_minerals in reproc_mat_list.iteritems():
        min_quantity_list = [-float(quant) for quant in v_minerals.values()]
        list_of_mineral_matrices.append(min_quantity_list)
        ore_quantity_matrix.append(float(1.0))
        min_id_list = v_minerals.keys()

    for min_id in min_id_list:
        if (min_id not in mineral_amounts_desired.keys()):
            mineral_amounts_desired_matrix.append(float(0.0))
        else:
            mineral_amounts_desired_matrix.append(-float(mineral_amounts_desired[min_id]))
        
    A = matrix(list_of_mineral_matrices)
    b = matrix(mineral_amounts_desired_matrix)
    c = matrix(ore_quantity_matrix)

    printing.options['dformat'] = '%.1f'
    printing.options['width'] = -1
    
    print A
    print b
    print c

    sol=solvers.lp(c,A,b)
    print(sol['x'])
    def setUp(self):
        '''
        Set up of test
        '''
        self.db_access_obj = DBAccessSQLite(self.DATA_FILE)
        self.data_access = EveDB(self.db_access_obj)

        self.eve_item_manufacturing = EveOnlineManufacturingJob(self.data_access,
                                                                type_name=self.BUILD_PRODUCT_NAME)
class Test(unittest.TestCase):
    '''
    Unit test for class EveItemManufacturing
    '''

    DATA_FILE = '../data/eve.db'
    eve_item_manufacturing = None

    BUILD_PRODUCT_NAME = 'Ark'
    BUILD_PRODUCT_RUNS = 1
    BUILD_PRODUCT_ME = 5
    BUILD_PRODUCT_TE = 0

    maxDiff = None

    def setUp(self):
        '''
        Set up of test
        '''
        self.db_access_obj = DBAccessSQLite(self.DATA_FILE)
        self.data_access = EveDB(self.db_access_obj)

        self.eve_item_manufacturing = EveOnlineManufacturingJob(self.data_access,
                                                                type_name=self.BUILD_PRODUCT_NAME)

    def tearDown(self):
        '''
        Tear down of test
        '''
        self.db_access_obj.close()

    def test_get_item(self):
        '''
        Get item
        '''
        self.eve_item_manufacturing.get_item(type_name="Providence")
        self.failUnlessEqual("Providence",
                             self.eve_item_manufacturing.type_name)

    def test_get_manufacturing_job_list(self):
        '''
        Obtain list of manufacturing jobs
        '''
        job_list = ['Ark',
                    'Capital Jump Drive',
                    'Capital Radar Sensor Cluster',
                    'Capital Linear Shield Emitter',
                    'Capital Antimatter Reactor Unit',
                    'Capital Nanoelectrical Microprocessor',
                    'Capital Tungsten Carbide Armor Plate',
                    'R.A.M.- Starship Tech',
                    'Providence',
                    'Capital Propulsion Engine',
                    'Capital Cargo Bay',
                    'Capital Construction Parts',
                    'Capital Armor Plates',
                    'Capital Tesseract Capacitor Unit',
                    'Capital Fusion Thruster']

        self.eve_item_manufacturing.get_item(type_name="Ark")
        self.eve_item_manufacturing.blueprint_me_level = self.BUILD_PRODUCT_ME
        self.eve_item_manufacturing.manufacturing_runs = self.BUILD_PRODUCT_RUNS
        self.eve_item_manufacturing.manufacturing_data_calculate()

        self.failUnlessEqual(job_list,
                             [job.type_name for job in self.eve_item_manufacturing.get_manufacturing_job_list()])

    def test_get_manufacturing_job_list_with_assets(self):
        '''
        Get manufacturing job list, with assets
        '''
        job_list = ['Ark',
                    'Capital Radar Sensor Cluster',
                    'Capital Linear Shield Emitter',
                    'Capital Antimatter Reactor Unit',
                    'Capital Nanoelectrical Microprocessor',
                    'Capital Tungsten Carbide Armor Plate',
                    'R.A.M.- Starship Tech',
                    'Providence',
                    'Capital Propulsion Engine',
                    'Capital Cargo Bay',
                    'Capital Construction Parts',
                    'Capital Armor Plates',
                    'Capital Tesseract Capacitor Unit',
                    'Capital Fusion Thruster']

        assets = {21025: 29}   # 21025: Capital Jump Drive

        self.eve_item_manufacturing.get_item(type_name="Ark")
        self.eve_item_manufacturing.blueprint_me_level = self.BUILD_PRODUCT_ME
        self.eve_item_manufacturing.manufacturing_runs = self.BUILD_PRODUCT_RUNS
        self.eve_item_manufacturing.asset_list = assets

        self.eve_item_manufacturing.manufacturing_data_calculate()

        self.failUnlessEqual(job_list,
                             [job.type_name for job in self.eve_item_manufacturing.get_manufacturing_job_list()])

    def test_get_material_list(self):
        '''
        Get material list
        '''
        material_list = {16672: 11401167.0, 16678: 2976997.0, 34: 133069643.0, 35: 19441019.0, 36: 7163272.0, 37: 1089400.0, 38: 314014.0, 39: 51734.0, 40: 41236.0, 16681: 40084.0, 16682: 13904.0, 11399: 3563.0, 33360: 44176.0, 16680: 76090.0, 3828: 2138.0, 16679: 1115444.0, 16683: 13673.0, 17317: 16258.0}

        assets = {39: 51732}  # 39: Zydrine

        self.eve_item_manufacturing.get_item(type_name="Ark")
        self.eve_item_manufacturing.blueprint_me_level = self.BUILD_PRODUCT_ME
        self.eve_item_manufacturing.manufacturing_runs = self.BUILD_PRODUCT_RUNS
        self.eve_item_manufacturing.asset_list = assets

        self.eve_item_manufacturing.manufacturing_data_calculate()

        self.failUnlessEqual(material_list,
                             self.eve_item_manufacturing.get_manufacturing_material_list())

    def test_get_material_list_with_assets(self):
        '''
        Get material list with assets
        '''
        material_list = {16672: 11401167.0, 16678: 2976997.0, 34: 133069643.0, 35: 19441019.0, 36: 7163272.0, 37: 1089400.0, 38: 314014.0, 39: 103466.0, 40: 41236.0, 16681: 40084.0, 16682: 13904.0, 11399: 3563.0, 33360: 44176.0, 16680: 76090.0, 3828: 2138.0, 16679: 1115444.0, 16683: 13673.0, 17317: 16258.0}

        self.eve_item_manufacturing.get_item(type_name="Ark")
        self.eve_item_manufacturing.blueprint_me_level = self.BUILD_PRODUCT_ME
        self.eve_item_manufacturing.manufacturing_runs = self.BUILD_PRODUCT_RUNS
        self.eve_item_manufacturing.manufacturing_data_calculate()

        self.failUnlessEqual(material_list,
                             self.eve_item_manufacturing.get_manufacturing_material_list())

    def test_get_manufacturing_job_by_id(self):
        '''
        Get manufacturing job by ID
        '''
        self.eve_item_manufacturing.get_item(type_name="Ark")
        self.eve_item_manufacturing.blueprint_me_level = self.BUILD_PRODUCT_ME
        self.eve_item_manufacturing.manufacturing_runs = self.BUILD_PRODUCT_RUNS
        self.eve_item_manufacturing.manufacturing_data_calculate()

        job_name = "Capital Jump Drive"

        self.failUnlessEqual(job_name,
                             self.eve_item_manufacturing.get_manufacturing_job_by_id(type_id=21025).type_name)

    def test_get_manufacturing_job_by_name(self):
        '''
        Get manufacturing job by manufactured item name
        '''
        self.eve_item_manufacturing.get_item(type_name="Ark")
        self.eve_item_manufacturing.blueprint_me_level = self.BUILD_PRODUCT_ME
        self.eve_item_manufacturing.manufacturing_runs = self.BUILD_PRODUCT_RUNS
        self.eve_item_manufacturing.manufacturing_data_calculate()

        job_id = 21025

        self.failUnlessEqual(job_id,
                             self.eve_item_manufacturing.get_manufacturing_job_by_name(type_name="Capital Jump Drive").type_id)
Exemplo n.º 4
0
def main():
    '''
    Main function for testing the classes
    '''

    building_job_chain = EveOnlineManufacturingJob(DATA_ACCESS_OBJECT,
                                                   type_name=BUILD_PRODUCT_NAME,
                                                   blueprint_me_level=BUILD_PRODUCT_ME,
                                                   manufacturing_runs=BUILD_PRODUCT_RUNS,
                                                   assembly_line_type_name=BUILD_FACILITY)

    if building_job_chain.is_buildable() == False:
        print ("Can not build this item.")
        exit()

    # generate manufacturing job tree
    building_job_chain.manufacturing_data_calculate()

    # set facility for all jobs
    manufacturing_job_list = building_job_chain.get_manufacturing_job_list()

    for job in manufacturing_job_list:
        if job.type_name[0:7] == 'Capital':
            job.blueprint_me_level = 10
            job.assembly_line = EveOnlineRamAssemblyLineTypes(DATA_ACCESS_OBJECT,
                                                              assembly_line_type_name='STATION manufacturing')

    # Recalculate after setting facility
    asset_dict = create_asset_list(ASSETS_LIST)
    building_job_chain.asset_list = asset_dict
    building_job_chain.manufacturing_data_calculate()

    manufacturing_job_list = building_job_chain.get_manufacturing_job_list()

    for job in manufacturing_job_list:

        print ("level: %d, runs %d (produced %d), %s (ME: %d, Facility: %s)" % (job.build_queue_level,
                                                                                job.manufacturing_runs,
                                                                                job.blueprint_produced_quantity,
                                                                                job.type_name,
                                                                                job.blueprint_me_level,
                                                                                job.assembly_line.assembly_line_type_name
                                                                                ))

    print

    market = EveMarket(MarketAccessEveCentral())

    total_material_cost = 0

    for mat_id, quant in building_job_chain.get_manufacturing_material_list().iteritems():
        e_material_item = EveOnlineManufacturingJob(DATA_ACCESS_OBJECT,
                                                    type_id=mat_id)

        mat_price = market.get_price(type_id=mat_id,
                                     solar_system_id=30000142,
                                     price_type='buy',
                                     price_param='max')

        mat_cost = (mat_price * quant)
        total_material_cost += mat_cost

        print "%s\tQuantity: %s\tPrice: %s\tCost: %s" % (e_material_item.type_name,
                                    locale.format("%d", quant, grouping=True),
                                    locale.format("%.2f", mat_price, grouping=True),
                                    locale.format("%d", mat_cost, grouping=True))

    print ("\nCost total: %s\n" % locale.format("%d", total_material_cost, grouping=True))

    manufacturing_product_price = market.get_price(type_id=building_job_chain.type_id,
                                                   solar_system_id=30000142,
                                                   price_type='sell',
                                                   price_param='min')

    total_income = manufacturing_product_price * \
                   building_job_chain.blueprint_produced_quantity * \
                   building_job_chain.manufacturing_runs

    produced_quantity = building_job_chain.blueprint_produced_quantity * \
                        building_job_chain.manufacturing_runs

    profit = total_income - total_material_cost

    print ("Total material cost:\t%s\nSell price:\t%s\nProduced quantity:\t%s\nSelling product income:\t%s\nProfit:\t%s" % (locale.format("%d", total_material_cost, grouping=True),
                                                                                   locale.format("%d", manufacturing_product_price, grouping=True),
                                                                                   locale.format("%d", produced_quantity, grouping=True),
                                                                                   locale.format("%d", total_income, grouping=True),
                                                                                   locale.format("%d", profit, grouping=True)))
    # refining_type = EveOnlineInvType(DATA_ACCESS_OBJECT,
    #                                  type_name="White Glaze")
    #
    # refining_list = DATA_ACCESS_OBJECT.get_lst_mat_for_rfn(type_id=refining_type.type_id)
    # print ("Refining list for %s:" % (refining_type.type_name))
    #
    # for mat in refining_list:
    #     print ("material: %s, quantity: %d" % (DATA_ACCESS_OBJECT.get_inv_type(mat['material_type_id'])['type_name'],
    #                                            mat['quantity']))

    print json.dumps(building_job_chain.get_manufacturing_job_parameter_list(),
                     indent=2)