Beispiel #1
0
    def agent__clear_accounts(self, args):
        import os
        from sample_agent import Agent
        from sample_config import Config  # needed for the bankDirectory

        text = "This test checks agent.clear_accounts \n"
        text = text + "  Checking if after the clear_accounts the total amount    \n"
        text = text + "  of transactions in zero.  \n"
        self.print_info(text)
        #
        # INITIALIZATION
        #
        environment_directory = str(args[0])
        identifier = str(args[1])
        log_directory = str(args[2])

        # Configure logging parameters so we get output while the program runs
        logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S',
                            filename=log_directory + identifier + ".log", level=logging.INFO)
        logging.info('START logging for test agent__clear_accounts in run: %s',
                     environment_directory + identifier + ".xml")

        # Construct firm filename
        config = Config()
        list_env = os.listdir(environment_directory)
        config.read_xml_config_file(environment_directory + list_env[0])
        # get the firm_directory from the environment
        firm_directory = config.firm_directory
        # and loop over all firms in the directory
        listing = os.listdir(firm_directory)
        firmFilename = firm_directory + listing[0]

        # generate an agent
        agent = Agent("baseagent id", {"test": "parameters"}, {"test": "variables"})
        agent.identifier = "test_agent"
        config.agents = []
        config.agents.append(agent)
        agent.get_parameters_from_file(firmFilename, config)

        #
        # TESTING
        #

        account = 0.0
        tranx = 0

        for transaction in agent.accounts:
            account = account + transaction.amount
            tranx = tranx + 1

        print(tranx)
        print(account)

        from sample_transaction import Transaction
        transaction = Transaction()
        transaction.this_transaction("deposits", "", agent.identifier,
                                     agent.identifier, 10.0,  0.09,  0, -1)
        # environment.firms[0] is only for testing purposes DO NOT USE IN PRODUCTION
        transaction.add_transaction(config)
        # environment.households[0:1][0] is only for testing purposes DO NOT USE IN PRODUCTION
        # what it does is is takes the first household in environment, but if there are no
        # households (which happens in testing) it doesn't break down

        account = 0.0
        tranx = 0

        for transaction in agent.accounts:
            account = account + transaction.amount
            tranx = tranx + 1

        print(tranx)
        print(account)

        agent.clear_accounts()

        account = 0.0
        tranx = 0

        for transaction in agent.accounts:
            account = account + transaction.amount
            tranx = tranx + 1

        print(tranx)
        print(account)