Ejemplo n.º 1
0
 def inject(self, account_list, amount):
     # first credit the trust account with the sufficient amount of quids
     count = len(account_list)
     total_amount = count * amount
     self.account.credit(total_amount)
     #        self.inject_quids(total_amount)
     self.__do_transactions(account_list, amount)
     logger.info("Injected %d quids into %d accounts. Total: %d quids.", amount, count, total_amount)
Ejemplo n.º 2
0
    def _calc_total_quids_in_network(self):
        self.total_quids = 0

        for list in self.all_members:
            for i in list:
                self.total_quids += i.get_account().get_balance()

        logger.info("Total amount of quids in network: %d", self.total_quids)
Ejemplo n.º 3
0
    def run(self):
        while True:
            day = self.sim.now()
            logger.info("Simulation runs now day %d", day)
            self.scenario.run(day)

            # logger.info("Total quids in network: %d", total_quids_in_network.amount)
            self._calc_total_quids_in_network()
            yield hold, self, 1.0
Ejemplo n.º 4
0
 def pay_employees(self, employees):
     # pay wages of 10% in quids to employees
     for employee in employees:
         # timestamp
         tstamp = datetime.now()
         ta_amount = average_employee_wage
         ta = Transaction(employee.get_account(), self.account, ta_amount, tstamp)
         ta.commit()
     total_paid = len(employees) * ta_amount
     logger.info("Council paid 10%% of wages in quid to %d workers", len(employees))
     logger.info("Council paid %d quids for wages in total.", total_paid)
Ejemplo n.º 5
0
 def month(self, day):
     logger.info("Simulation now runs in month: %d", self.month_count)
     #The current scenario implies that for an initial period, businesses
     #get some quids injected for an initial period, after which no injectio
     #takes place anymore
     if (self.month_count < quid_injection_business_period):
         logger.info("Still in initial quids injection period for businesses --> Quids will be injected to businesses.")
         self.network.trust.inject(self.network.businesses, increase_step_for_businesses)
     #at the end of the month, the council pays its employees, partly in quids
     self.network.council.pay_employees(self.network.employees);              
     #increase month count
     self.month_count += 1
Ejemplo n.º 6
0
    def create_network(self):
        self.trust = LqnTrust(self.name + " Trust", self.sim)
        self.council = LqnCouncil("Kilkenny County Council", self.sim)
        self.sponsors.append(self.council)

        for i in range(num_of_members):
            self.members.append(LqnMember("Member-%d" % i, self.sim))

        for k in range(num_of_employees):
            self.employees.append(LqnCouncilEmployee("Employee-%d" % k, self.sim))

        for n in range(num_of_businesses):
            self.businesses.append(LqnBusiness("Business-%d" % n, self.sim))
        logger.info("Initial network members created")
        self.start()
Ejemplo n.º 7
0
    def apply_policy(self, data_accessor, list, policy):
        """
            Only the trust is allowed to apply the policy,
            so it needs to be done in this object, not in 
            scenario or elsewhere.
        """
        timestamp = datetime.now()
        quids_level = 0
        base = "Policy applied to all accounts."
        ending = ""

        for i in list:
            for member in i:
                quids_level += policy.apply(self.account, member.get_account(), data_accessor, timestamp)
        if quids_level > 0:
            ending = "Added %d quids in total.", quids_level
        elif quids_level < 0:
            ending = "Removed %d quids in total.", quids_level
        else:
            ending = "No changes in total quids."
        msg = base, ending
        logger.info(msg)
Ejemplo n.º 8
0
 def start(self):
     random.seed(random_seed)  # seeds the random number generator
     self.trust.create_initial_quids()
     logger.info("Initial quids supplied. Network can now start")
     self._calc_total_quids_in_network()
Ejemplo n.º 9
0
        """
            At the end of the day, in order to calculate mean average
            balances, we need to store the current balance per account
        """
        for list in self.all_members:
            for member in list:
                account = member.get_account()
                account.account_history.record_daily_balance(account.get_balance())


# Run the simulation
sim = Simulation()
sim.initialize()


logger.info("*************************************************")
logger.info("The Liquidity Network Simulation  - version 0.1.1")
logger.info("*************************************************")
logger.info("Starting Simulation.")
logger.info("Current time is %d", sim.now())

network = LqnNetwork("Kilkenny LQN", sim)
network.create_network()
sim.activate(network, network.run(), at=0.0)

total_quids_in_network = Level(
    name="total_quids_in_network",
    unitName="quids",
    capacity="unbounded",
    initialBuffered=0,
    monitored=True,