def __get_graph__(self,
                      ticker_id: str,
                      refresh_interval: int,
                      limit: int = 0):
        period = self.sys_config.period
        aggregation = self.sys_config.period_aggregation
        graph_cache_id = self.sys_config.graph_cache.get_cache_id(
            ticker_id, period, aggregation, limit)
        graph = self.sys_config.graph_cache.get_cached_object_by_key(
            graph_cache_id)
        if graph is not None:
            return graph, graph_cache_id

        if period == PRD.DAILY and self._recommender_table.selected_index != INDICES.CRYPTO_CCY:
            self.sys_config.data_provider.from_db = True
        else:
            self.sys_config.data_provider.from_db = False
        date_start = MyDate.adjust_by_days(MyDate.get_datetime_object().date(),
                                           -limit)
        and_clause = "Date > '{}'".format(date_start)
        graph_title = self.sys_config.graph_cache.get_cache_title(
            ticker_id, period, aggregation, limit)
        detector = self._pattern_controller.get_detector_for_fibonacci_and_pattern(
            self.sys_config, ticker_id, and_clause, limit)
        graph_api = DccGraphApi(graph_cache_id, graph_title)
        graph_api.ticker_id = ticker_id
        graph_api.df = detector.pdh.pattern_data.df
        graph = self.__get_dcc_graph_element__(detector, graph_api)
        cache_api = self.sys_config.graph_cache.get_cache_object_api(
            graph_cache_id, graph, period, refresh_interval)
        self.sys_config.graph_cache.add_cache_object(cache_api)
        return graph, graph_cache_id
Exemple #2
0
 def __add_cache_object_for_ticker_to_graph_first_cache__(self, ticker: str, and_clause=''):
     graph_id = self._graph_first_cache.graph_id
     cache_key = self._graph_first_cache.get_cache_key(ticker, 0)
     if self._graph_first_cache.get_cached_object_by_key(cache_key) is None:
         aggregation = self.sys_config.period_aggregation
         graph_title = self.__get_graph_title__(ticker, self.sys_config.period, aggregation)
         detector = self._pattern_controller.get_detector_for_dash(self.sys_config, ticker, and_clause)
         pattern_data = detector.pdh.pattern_data
         graph_api = DccGraphApi(graph_id, graph_title)
         graph_api.ticker_id = ticker
         graph_api.df = detector.pdh.pattern_data.df
         graph = self.__get_dcc_graph_element__(detector, graph_api)
         cache_api = self.__get_cache_api__(cache_key, graph, detector, pattern_data)
         self._graph_first_cache.add_cache_object(cache_api)
         print('{}: Cached into graph_first_cache: {}'.format(MyDate.get_time_str_from_datetime(), cache_key))
     else:
         print('{}: Already cached by graph_first_cache: {}'.format(MyDate.get_time_str_from_datetime(), cache_key))
 def __add_calculated_graph_to_cache__(self, graph_cache_id: str,
                                       ticker_id: str, period: str,
                                       aggregation: int, limit: int,
                                       indicator: str,
                                       refresh_interval: int):
     date_start = MyDate.adjust_by_days(MyDate.get_datetime_object().date(),
                                        -limit)
     and_clause = "Date > '{}'".format(date_start)
     graph_title = self.sys_config.graph_cache.get_cache_title(
         ticker_id, period, aggregation, limit)
     detector = self._pattern_controller.get_detector_for_fibonacci_and_pattern(
         self.sys_config, ticker_id, and_clause, limit)
     graph_api = DccGraphApi(graph_cache_id, graph_title)
     graph_api.ticker_id = ticker_id
     graph_api.indicator = None if indicator == INDI.NONE else indicator
     graph_api.df = detector.pdh.pattern_data.df
     graph = self.__get_dcc_graph_element__(detector, graph_api)
     cache_api = self.sys_config.graph_cache.get_cache_object_api(
         graph_cache_id, graph, period, refresh_interval)
     self.sys_config.graph_cache.add_cache_object(cache_api)
     return graph