Beispiel #1
0
  def __init__(self, name, func, seconds, plugin, **kwargs):
    """
    init the class

    time should be military time, "1430"

    """
    Event.__init__(self, name, plugin, func)
    self.seconds = seconds

    self.onetime = False
    if 'onetime' in kwargs:
      self.onetime = kwargs['onetime']

    self.enabled = True
    if 'enabled' in kwargs:
      self.enabled = kwargs['enabled']

    self.time = None
    if 'time' in kwargs:
      self.time = kwargs['time']

    self.log = True
    if 'log' in kwargs:
      self.log = kwargs['log']

    self.nextcall = self.getnext() or -1
Beispiel #2
0
  def __init__(self, name, func, seconds, plugin, **kwargs):
    """
    init the class

    time should be military time, "1430"

    """
    Event.__init__(self, name, plugin, func)
    self.seconds = seconds

    self.onetime = False
    if 'onetime' in kwargs:
      self.onetime = kwargs['onetime']

    self.enabled = True
    if 'enabled' in kwargs:
      self.enabled = kwargs['enabled']

    self.time = None
    if 'time' in kwargs:
      self.time = kwargs['time']

    self.log = True
    if 'log' in kwargs:
      self.log = kwargs['log']

    self.nextcall = self.getnext() or -1
Beispiel #3
0
 def run(self):
     if not self.stochastic:
         inter_arrival_time_list, base_station_list, duration_list, speed_list = InputAnalyzer.get_input_from_file(
         )
         total_event_count = len(inter_arrival_time_list)
     else:
         inter_arrival_time_list = [
             RNG.generate_inter_arrival_time()
             for _ in range(no_events_total)
         ]
         base_station_list = [
             RNG.generate_base_station() for _ in range(no_events_total)
         ]
         duration_list = [
             RNG.generate_duration() for _ in range(no_events_total)
         ]
         speed_list = [RNG.generate_speed() for _ in range(no_events_total)]
         total_event_count = no_events_total
     # Add the first event
     idx = 0
     event = Event(event_type="INITIALIZATION",
                   arrival_time=self.clock + inter_arrival_time_list[idx],
                   station=base_station_list[idx],
                   duration=duration_list[idx],
                   position=RNG.generate_position(),
                   speed=speed_list[idx],
                   direction=RNG.generate_direction())
     heapq.heappush(self.event_list, event)
     while len(self.event_list) > 0:
         idx += 1
         # Deque event from list until it is empty
         self.handle_event(heapq.heappop(self.event_list))
         # Add next initialization event
         if idx < total_event_count:
             # Set system clock to arrival time of the last initialized call
             self.clock = event.arrival_time
             event = Event(event_type="INITIALIZATION",
                           arrival_time=self.clock +
                           inter_arrival_time_list[idx],
                           station=base_station_list[idx],
                           duration=duration_list[idx],
                           position=RNG.generate_position(),
                           speed=speed_list[idx],
                           direction=RNG.generate_direction())
             heapq.heappush(self.event_list, event)
     # Update analyzer
     output_analyzer.update_data(self.index, self.drop_rate_list,
                                 self.block_rate_list)
     print("{} blocked, {} dropped, {} terminated".format(
         self.no_blocked_call, self.no_dropped_call,
         self.no_terminated_call))
     drop_rate = (self.no_dropped_call -
                  self.no_dropped_call_list[self.warm_up_events]) / float(
                      self.no_call_created - self.warm_up_events) * 100
     block_rate = (self.no_blocked_call -
                   self.no_blocked_call_list[self.warm_up_events]) / float(
                       self.no_call_created - self.warm_up_events) * 100
     return drop_rate, block_rate
Beispiel #4
0
 def handle_handover(self, time: float, speed: float, station: int,
                     duration: float, direction: str):
     self.clock = time
     if direction == "LEFT":
         last_station = station + 1
         next_station = station - 1
     elif direction == "RIGHT":
         last_station = station - 1
         next_station = station + 1
     else:
         raise Exception("Unknown direction")
     # Free the channel from used station
     self.no_free_channel[last_station] += 1
     if self.no_free_channel[station] == 0:
         # If no free channel, drop the call
         self.no_dropped_call += 1
         return
     # Allocate a channel from current station
     self.no_free_channel[station] -= 1
     # Plan the next handover
     time_to_handover = 2 / speed * 3600  # Hour to second
     # Decide whether to terminate the call
     if duration <= time_to_handover:
         # Finishing call
         heapq.heappush(
             self.event_list,
             Event(event_type="TERMINATION",
                   arrival_time=self.clock + duration,
                   station=station,
                   duration=0,
                   direction=direction,
                   speed=speed))
         return
     elif next_station == 0 or next_station == 21:
         # Leaving highway
         heapq.heappush(
             self.event_list,
             Event(event_type="TERMINATION",
                   arrival_time=self.clock + time_to_handover,
                   station=station,
                   duration=0,
                   direction=direction,
                   speed=speed))
         return
     # Schedule the next handover
     heapq.heappush(
         self.event_list,
         Event(
             event_type="HANDOVER",
             arrival_time=self.clock + time_to_handover,
             station=next_station,
             duration=duration - time_to_handover,
             direction=direction,
             speed=speed,
         ))
Beispiel #5
0
 def handle_initialization(self, time: float, speed: float, station: int,
                           position: float, duration: float,
                           direction: str):
     # Update system clock
     self.clock = time
     self.no_call_created += 1
     # Check available channel from current station
     if self.no_free_channel[station] - self.no_reserved <= 0:
         # If no available channel, the call is blocked
         self.no_blocked_call += 1
         return
     # Allocate that channel
     self.no_free_channel[station] -= 1
     if direction == "LEFT":
         time_to_handover = position / speed * 3600  # Hour to second
         next_station = station - 1
     elif direction == "RIGHT":
         time_to_handover = (2 - position) / speed * 3600  # Hour to second
         next_station = station + 1
     else:
         raise Exception("Unknown direction")
     # Decide whether to terminate the call
     if duration <= time_to_handover:
         # Finishing call
         heapq.heappush(
             self.event_list,
             Event(event_type="TERMINATION",
                   arrival_time=self.clock + duration,
                   station=station,
                   duration=0,
                   direction=direction,
                   speed=speed))
         return
     elif next_station == 0 or next_station == 21:
         # Leaving highway
         heapq.heappush(
             self.event_list,
             Event(event_type="TERMINATION",
                   arrival_time=self.clock + time_to_handover,
                   station=station,
                   duration=0,
                   direction=direction,
                   speed=speed))
         return
     # Schedule the next handover
     heapq.heappush(
         self.event_list,
         Event(
             event_type="HANDOVER",
             arrival_time=self.clock + time_to_handover,
             station=next_station,
             duration=duration - time_to_handover,
             direction=direction,
             speed=speed,
         ))
Beispiel #6
0
 def __init__(self, **kwargs):
     """
     :param event:
     :type even: dict
     """
     self.files: FileManager = FileManager(**kwargs)
     self.events: Events = Event(**kwargs)
     self.ticker: Ticker = Ticker(**kwargs)
def get_ticker_information(state: State):
    """
    Call financial scrapper

    :param state: state
    :return: end of the script
    """
    # state.output["current_price"] = None
    # state.output[state.output['symbol'] == "BCOW"]["current_price"] = 3
    # print(state.output[state.output['symbol'] == "BCOW"])
    #
    # exit(1)
    for index, row in state.output.iterrows():
        symbol = row["symbol"]
        manager_financial_scrapper(state=state, symbol=symbol)

        state.output.at[index, 'current_price'] = state.ticker.current_price
        state.output.at[
            index,
            'current_price_to_book_date'] = state.ticker.current_price_to_book_date
        state.output.at[
            index,
            'current_price_to_book'] = state.ticker.current_price_to_book
        state.output.at[index,
                        'price_to_book_q1'] = state.ticker.price_to_book_q1
        state.output.at[index,
                        'price_to_book_q2'] = state.ticker.price_to_book_q2
        state.output.at[index,
                        'price_to_book_q3'] = state.ticker.price_to_book_q3
        state.output.at[index,
                        'price_to_book_q4'] = state.ticker.price_to_book_q4

        state.event = Event()
    # for attribut in vars(state.ticker):
    #         delattr(state.ticker, attribut)

    state.output.to_csv(f"{PATH}/data/output.csv")

    return state