Пример #1
0
 def add_exchange_price(self, date_str, price):
     present_rate = self.__exchange_prices.get(date_str)
     if present_rate is not None:
         raise ValueError("Sir you are trying to redefine " + self.name + "on the day of " + date_str)
     else:
         self.__exchange_prices[date_str] = price
         if self.__earliest_date is None or dateConv.to_date(date_str) < self.__earliest_date:
             self.__earliest_date = dateConv.to_date(date_str)
Пример #2
0
 def get_exchange_rate(self, date_str):
     asked_rate = self.__exchange_rates.get(date_str)
     if dateConv.to_date(date_str) < self.__earliest_date:
         raise ValueError("Trying to obtain non existing data, Sir")
     if asked_rate is not None:
         return asked_rate
     else:
         new_date = dateConv.to_date(date_str) - timedelta(1)
         return self.get_exchange_rate(dateConv.to_str(new_date))
Пример #3
0
 def test_getCorrectEvents(self):
     symbol_table = SymbolsTable()
     symbol_table.add_currency('YUA')
     symbol_table.add_currency('USD')
     symbol_table.add_stock('CocaCola')
     symbol_table.add_stock('NukaCola')
     parsed_file = open("rule.txt")
     lexer = Lexer(parsed_file)
     controller = RealityController()
     controller.world.current_day = dC.to_date('2016.05.16')
     controller.world.add_currency(Currency('yuan', 'YUA', 0))
     controller.world.add_currency(Currency('usa dollar', 'USD', 1))
     controller.world.add_stock(Stock('CocaCola', 1, 0))
     controller.world.add_stock(Stock('NukaCola', 1, 1))
     controller.add_event(Event(EventType.CURRENCY, '2016.05.16', 0, 500))
     controller.add_event(Event(EventType.CURRENCY, '2016.05.15', 0, 400))
     controller.add_event(Event(EventType.STOCK, '2016.05.16', 0, 500))
     controller.add_event(Event(EventType.STOCK, '2016.05.15', 0, 400))
     controller.add_event(Event(EventType.STOCK, '2016.05.14', 0, 400))
     controller.add_event(Event(EventType.STOCK, '2016.05.13', 0, 400))
     Parser.RuleParser.parse_from_lexer(lexer, symbol_table, controller)
     rule = controller.rules.get(1)
     print(rule.priority)
Пример #4
0
 def set_start_date(self, start_date_str):
     self.current_day = dateConv.to_date(start_date_str)