Example #1
0
 def set_block_model(self, block_model, blocks):
     name = block_model['name']
     mineral_deposit = block_model['mineral_deposit_name']
     headers = block_model['headers']
     data_map = block_model['data_map']
     max_x, max_y, max_z = self.db_manager.get_max_x_y_z_value(
         mineral_deposit, name)
     self.block_model = BlockModel(name, mineral_deposit, headers, data_map,
                                   max_x, max_y, max_z)
     self.block_model.add_blocks(blocks)
Example #2
0
 def setUp(self):
     name = "v1"
     mineral_deposit = "Zuck small"
     headers = [
         "id", "x", "y", "z", "cost", "value", "rock_tonnes", "ore_tonnes"
     ]
     data_map = {
         "x": "x",
         "y": "y",
         "z": "z",
         "weight": "rock_tonnes",
         "grade": {
             "Au": "ore_tonnes"
         }
     }
     blocks = [{
         "_id": {
             "$oid": "5cb0f608b766f9aa245cb3f0"
         },
         "mineral_deposit": "Zuck small",
         "block_model": "v1",
         "id": 9369,
         "x": 0,
         "y": 0,
         "z": 0,
         "cost": 56592,
         "value": 135786.28,
         "rock_tonnes": 62880,
         "ore_tonnes": 0.25572519083969464
     }, {
         "_id": {
             "$oid": "5cb0f608b766f9aa245cb3f1"
         },
         "mineral_deposit": "Zuck small",
         "block_model": "v1",
         "id": 9370,
         "x": 1,
         "y": 0,
         "z": 0,
         "cost": 56592,
         "value": 115580.184,
         "rock_tonnes": 1,
         "ore_tonnes": 0
     }, {
         "_id": {
             "$oid": "5cb0f608b766f9aa245cb3f1"
         },
         "mineral_deposit": "Zuck small",
         "block_model": "v1",
         "id": 9370,
         "x": 0,
         "y": 1,
         "z": 0,
         "cost": 56592,
         "value": 115580.184,
         "rock_tonnes": 0,
         "ore_tonnes": 0
     }, {
         "_id": {
             "$oid": "5cb0f608b766f9aa245cb3f1"
         },
         "mineral_deposit": "Zuck small",
         "block_model": "v1",
         "id": 9370,
         "x": 1,
         "y": 1,
         "z": 0,
         "cost": 56592,
         "value": 115580.184,
         "rock_tonnes": 0,
         "ore_tonnes": 0
     }]
     self.block_model = BlockModel(name, mineral_deposit, headers, data_map,
                                   1, 1, 0)
     self.block_model.add_blocks(blocks)
     self.rx = 2
     self.ry = 2
     self.rz = 1
Example #3
0
class TestReblock(unittest.TestCase):
    def setUp(self):
        name = "v1"
        mineral_deposit = "Zuck small"
        headers = [
            "id", "x", "y", "z", "cost", "value", "rock_tonnes", "ore_tonnes"
        ]
        data_map = {
            "x": "x",
            "y": "y",
            "z": "z",
            "weight": "rock_tonnes",
            "grade": {
                "Au": "ore_tonnes"
            }
        }
        blocks = [{
            "_id": {
                "$oid": "5cb0f608b766f9aa245cb3f0"
            },
            "mineral_deposit": "Zuck small",
            "block_model": "v1",
            "id": 9369,
            "x": 0,
            "y": 0,
            "z": 0,
            "cost": 56592,
            "value": 135786.28,
            "rock_tonnes": 62880,
            "ore_tonnes": 0.25572519083969464
        }, {
            "_id": {
                "$oid": "5cb0f608b766f9aa245cb3f1"
            },
            "mineral_deposit": "Zuck small",
            "block_model": "v1",
            "id": 9370,
            "x": 1,
            "y": 0,
            "z": 0,
            "cost": 56592,
            "value": 115580.184,
            "rock_tonnes": 1,
            "ore_tonnes": 0
        }, {
            "_id": {
                "$oid": "5cb0f608b766f9aa245cb3f1"
            },
            "mineral_deposit": "Zuck small",
            "block_model": "v1",
            "id": 9370,
            "x": 0,
            "y": 1,
            "z": 0,
            "cost": 56592,
            "value": 115580.184,
            "rock_tonnes": 0,
            "ore_tonnes": 0
        }, {
            "_id": {
                "$oid": "5cb0f608b766f9aa245cb3f1"
            },
            "mineral_deposit": "Zuck small",
            "block_model": "v1",
            "id": 9370,
            "x": 1,
            "y": 1,
            "z": 0,
            "cost": 56592,
            "value": 115580.184,
            "rock_tonnes": 0,
            "ore_tonnes": 0
        }]
        self.block_model = BlockModel(name, mineral_deposit, headers, data_map,
                                      1, 1, 0)
        self.block_model.add_blocks(blocks)
        self.rx = 2
        self.ry = 2
        self.rz = 1

    def test_reblock(self):
        self.assertEqual(self.block_model.reblock(self.rx, self.ry, self.rz),
                         True)

    def test_change_block_quantity(self):
        self.block_model.reblock(self.rx, self.ry, self.rz)
        new_blocks = self.block_model.count_blocks()
        self.assertEqual(new_blocks, 1)

    def test_new_weight(self):
        old_blocks_weight = self.block_model.get_total_weight()
        self.block_model.reblock(self.rx, self.ry, self.rz)
        new_blocks_weight = self.block_model.get_total_weight()
        self.assertEqual(old_blocks_weight, new_blocks_weight)

    def test_new_mineral_percentage(self):
        old_mineral_weight = self.block_model.get_total_mineral_weight()
        self.block_model.reblock(self.rx, self.ry, self.rz)
        new_mineral_weight = self.block_model.get_total_mineral_weight()
        self.assertEqual(old_mineral_weight, new_mineral_weight)

    def test_max_values(self):
        self.block_model.reblock(self.rx, self.ry, self.rz)
        max_x = self.block_model.max_x
        max_y = self.block_model.max_y
        max_z = self.block_model.max_z
        max_found_x = max([block.x for block in self.block_model.blocks])
        max_found_y = max([block.y for block in self.block_model.blocks])
        max_found_z = max([block.z for block in self.block_model.blocks])

        self.assertEqual((max_x, max_y, max_z), (
            max_found_x, max_found_y, max_found_z
        ), "Maximum values of coordinates x, y, z doesnt match the blocks of the block model"
                         )
Example #4
0
class TestReblock(unittest.TestCase):
    def setUp(self):
        name = "v1"
        mineral_deposit = "Zuck small"
        headers = [
            "id", "x", "y", "z", "cost", "value", "rock_tonnes", "ore_tonnes"
        ]
        data_map = {
            "x": "x",
            "y": "y",
            "z": "z",
            "weight": "rock_tonnes",
            "grade": {
                "Au": "ore_tonnes"
            }
        }
        blocks = [{
            "_id": {
                "$oid": "5cb0f608b766f9aa245cb3f0"
            },
            "mineral_deposit": "Zuck small",
            "block_model": "v1",
            "id": 9369,
            "x": 0,
            "y": 0,
            "z": 0,
            "cost": 56592,
            "value": 135786.28,
            "rock_tonnes": 0,
            "ore_tonnes": 0
        }, {
            "_id": {
                "$oid": "5cb0f608b766f9aa245cb3f1"
            },
            "mineral_deposit": "Zuck small",
            "block_model": "v1",
            "id": 9370,
            "x": 1,
            "y": 0,
            "z": 0,
            "cost": 56592,
            "value": 115580.184,
            "rock_tonnes": 0,
            "ore_tonnes": 0
        }, {
            "_id": {
                "$oid": "5cb0f608b766f9aa245cb3f1"
            },
            "mineral_deposit": "Zuck small",
            "block_model": "v1",
            "id": 9370,
            "x": 0,
            "y": 1,
            "z": 0,
            "cost": 56592,
            "value": 115580.184,
            "rock_tonnes": 0,
            "ore_tonnes": 0
        }, {
            "_id": {
                "$oid": "5cb0f608b766f9aa245cb3f1"
            },
            "mineral_deposit": "Zuck small",
            "block_model": "v1",
            "id": 9370,
            "x": 1,
            "y": 1,
            "z": 0,
            "cost": 56592,
            "value": 115580.184,
            "rock_tonnes": 0,
            "ore_tonnes": 0
        }]
        self.block_model = BlockModel(name, mineral_deposit, headers, data_map,
                                      1, 1, 0)
        self.block_model.add_blocks(blocks)
        self.rx = 1
        self.ry = 1
        self.rz = 1

    def test_change_block_quantity(self):
        self.block_model.reblock(self.rx, self.ry, self.rz)
        new_blocks = self.block_model.count_blocks()
        self.assertEqual(new_blocks, 4)

    def test_new_weight(self):
        old_blocks_weight = self.block_model.get_total_weight()
        self.block_model.reblock(self.rx, self.ry, self.rz)
        new_blocks_weight = self.block_model.get_total_weight()
        self.assertEqual(old_blocks_weight, new_blocks_weight)

    def test_new_mineral_percentage(self):
        old_mineral_weight = self.block_model.get_total_mineral_weight()
        self.block_model.reblock(self.rx, self.ry, self.rz)
        new_mineral_weight = self.block_model.get_total_mineral_weight()
        self.assertEqual(old_mineral_weight, new_mineral_weight)
Example #5
0
class TestsBlockModel(unittest.TestCase):
    def setUp(self):
        name = "v1"
        mineral_deposit = "Zuck small"
        headers = [
            "id", "x", "y", "z", "cost", "value", "rock_tonnes", "ore_tonnes"
        ]
        data_map = {
            "x": "x",
            "y": "y",
            "z": "z",
            "weight": "rock_tonnes",
            "grade": {
                "Au": "ore_tonnes"
            }
        }
        self.block_model = BlockModel(name, mineral_deposit, headers, data_map,
                                      19, 25, 0)
        blocks = [{
            "_id": {
                "$oid": "5cb0f608b766f9aa245cb3f0"
            },
            "mineral_deposit": "Zuck small",
            "block_model": "v1",
            "id": 9369,
            "x": 19,
            "y": 25,
            "z": 0,
            "cost": 56592,
            "value": 135786.28,
            "rock_tonnes": 62880,
            "ore_tonnes": 0.25572519083969464
        }, {
            "_id": {
                "$oid": "5cb0f608b766f9aa245cb3f1"
            },
            "mineral_deposit": "Zuck small",
            "block_model": "v1",
            "id": 9370,
            "x": 0,
            "y": 1,
            "z": 0,
            "cost": 56592,
            "value": 115580.184,
            "rock_tonnes": 0,
            "ore_tonnes": 0
        }]
        self.block_model.add_blocks(blocks)

        self.block_model_1 = BlockModel(name, mineral_deposit, headers,
                                        data_map, 19, 25, 0)
        blocks = [{
            "_id": {
                "$oid": "5cb0f608b766f9aa245cb3f0"
            },
            "mineral_deposit": "Zuck small",
            "block_model": "v1",
            "id": 9369,
            "x": 19,
            "y": 25,
            "z": 0,
            "cost": 56592,
            "value": 135786.28,
            "rock_tonnes": 0,
            "ore_tonnes": 0
        }, {
            "_id": {
                "$oid": "5cb0f608b766f9aa245cb3f1"
            },
            "mineral_deposit": "Zuck small",
            "block_model": "v1",
            "id": 9370,
            "x": 0,
            "y": 1,
            "z": 0,
            "cost": 56592,
            "value": 115580.184,
            "rock_tonnes": 0,
            "ore_tonnes": 0
        }]
        self.block_model_1.add_blocks(blocks)

    def test_get_block_by_coordinates(self):
        expected_result = self.block_model.blocks[1]
        block = self.block_model.get_block_by_coordinates(0, 1, 0)
        self.assertEqual(block, expected_result,
                         "The returned block doesn't match the coordinates")

    def test_count_blocks(self):
        number_of_blocks = self.block_model.count_blocks()
        self.assertEqual(
            number_of_blocks, 2,
            "Count of blocks does not corresponds to the actual number ")

    def test_get_total_weight(self):
        total_weight = self.block_model.get_total_weight()
        self.assertEqual(total_weight, 62880,
                         "Total weight of blocks is incorrect")

    def test_get_total_mineral_weight(self):
        mineral_weight = self.block_model.get_total_mineral_weight()
        self.assertEqual(
            mineral_weight, 62880 * 0.25572519083969464,
            "Total mineral weight of blocks in block model is incorrect")

    def test_get_air_percentage(self):
        air_percentage = self.block_model.get_air_percentage()
        self.assertEqual(air_percentage, 0.5,
                         "Air percentage of block model is incorrect")

    def test_get_total_weight_of_border_case(self):
        total_weight = self.block_model_1.get_total_weight()
        self.assertEqual(total_weight, 0,
                         "Total weight of blocks is incorrect")

    def test_get_total_mineral_weight_of_border_case(self):
        mineral_weight = self.block_model_1.get_total_mineral_weight()
        self.assertEqual(
            mineral_weight, 0,
            "Total mineral weight of blocks in block model is incorrect")

    def test_get_air_percentage_of_border_case(self):
        air_percentage = self.block_model_1.get_air_percentage()
        self.assertEqual(air_percentage, 1,
                         "Air percentage of block model is incorrect")

    def test_max_values(self):
        max_x = self.block_model.max_x
        max_y = self.block_model.max_y
        max_z = self.block_model.max_z
        max_found_x = max([block.x for block in self.block_model.blocks])
        max_found_y = max([block.y for block in self.block_model.blocks])
        max_found_z = max([block.z for block in self.block_model.blocks])

        self.assertEqual((max_x, max_y, max_z), (
            max_found_x, max_found_y, max_found_z
        ), "Maximum values of coordinates x, y, z doesnt match the blocks of the block model"
                         )
Example #6
0
class Container:
    def __init__(self):
        self.mineral_deposit = None
        self.block_model = None
        self.db_manager = Manager()

    def set_mineral_deposit(self, mineral_deposit):
        self.mineral_deposit = MineralDeposit(mineral_deposit['name'], None)

    def set_block_model(self, block_model, blocks):
        name = block_model['name']
        mineral_deposit = block_model['mineral_deposit_name']
        headers = block_model['headers']
        data_map = block_model['data_map']
        max_x, max_y, max_z = self.db_manager.get_max_x_y_z_value(
            mineral_deposit, name)
        self.block_model = BlockModel(name, mineral_deposit, headers, data_map,
                                      max_x, max_y, max_z)
        self.block_model.add_blocks(blocks)

    def interact_with_user(self):
        # self.present_self()
        metrics = [
            'Search by coordinates', 'Number of blocks',
            'Total weight of the mineral deposit',
            'Total mineral weight of the mineral deposit',
            'Percentage of "Air" blocks'
        ]
        print("Choose a metric: ")
        for index in range(len(metrics)):
            print("\t{}: {}".format(index + 1, metrics[index]))
        response = int(input("\t")) - 1
        if metrics[response] == "Search by coordinates":
            print(self.get_block_by_coordinates())
        elif metrics[response] == "Number of blocks":
            print("This block model has {} blocks in it.".format(
                self.get_number_of_blocks()))
        elif metrics[response] == 'Total weight of the mineral deposit':
            print("The total weight of {} is {}.".format(
                self.mineral_deposit.name,
                self.get_total_weight_of_mineral_deposit()))
        elif metrics[
                response] == 'Total mineral weight of the mineral deposit':
            print("The total mineral weight of {} is {}.".format(
                self.mineral_deposit.name,
                self.get_total_mineral_weight_of_mineral_deposit()))
        elif metrics[response] == 'Percentage of "Air" blocks':
            print("The air blocks percentage of {} is {}.".format(
                self.mineral_deposit.name,
                self.get_air_blocks_percentage_of_mineral_deposit()))

    def generate_action(self, response, coordinates):
        # self.present_self()
        metrics = [
            'Search by coordinates', 'Number of blocks',
            'Total weight of the mineral deposit',
            'Total mineral weight of the mineral deposit',
            'Percentage of "Air" blocks'
        ]

        if metrics[response] == "Search by coordinates":
            x, y, z = coordinates
            return str(self.get_block_by_coordinates(x, y, z))
        elif metrics[response] == "Number of blocks":
            return "This block model has {} blocks in it.".format(
                self.get_number_of_blocks())
        elif metrics[response] == 'Total weight of the mineral deposit':
            return "The total weight of {} is {}.".format(
                self.mineral_deposit.name,
                self.get_total_weight_of_mineral_deposit())
        elif metrics[
                response] == 'Total mineral weight of the mineral deposit':
            return "The total mineral weight of {} is {}.".format(
                self.mineral_deposit.name,
                self.get_total_mineral_weight_of_mineral_deposit())
        elif metrics[response] == 'Percentage of "Air" blocks':
            return "The air blocks percentage of {} is {}.".format(
                self.mineral_deposit.name,
                self.get_air_blocks_percentage_of_mineral_deposit())

    def present_to_user_the_options(self):
        print("Welcome to the mining block monitor system.")
        if self.mineral_deposit is None:
            db_manager = Manager()
            mineral_deposit_name = input(
                "It seems that you didn't provide a mineral deposit name.\nPlease indicate the name of the one would you like to use: "
            )
            db_result = db_manager.fetch_mineral_deposit(mineral_deposit_name)
            self.set_mineral_deposit(db_result)

    def get_block_by_coordinates(self, x, y, z):
        return self.block_model.get_block_by_coordinates(x, y, z)

    def get_number_of_blocks(self):
        return self.block_model.count_blocks()

    def get_total_weight_of_mineral_deposit(self):
        return self.block_model.get_total_weight()

    def get_total_mineral_weight_of_mineral_deposit(self):
        return self.block_model.get_total_mineral_weight()

    def get_air_blocks_percentage_of_mineral_deposit(self):
        return self.block_model.get_air_percentage()