analyser_hj3415 2.10.6__py3-none-any.whl → 3.0.1__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,15 @@
1
- from db_hj3415 import myredis
2
- from utils_hj3415 import utils, helpers
1
+ import os
3
2
  import datetime
4
3
  from collections import OrderedDict
5
- from . import eval, tsa
6
4
 
7
- import logging
5
+ from db_hj3415 import myredis
6
+ from utils_hj3415 import tools, setup_logger
7
+
8
+ from analyser_hj3415.analyser import tsa
9
+ from analyser_hj3415.analyser import eval
8
10
 
9
- score_logger = helpers.setup_logger('score_logger', logging.WARNING)
11
+ mylogger = setup_logger(__name__,'WARNING')
12
+ expire_time = tools.to_int(os.getenv('DEFAULT_EXPIRE_TIME_H', 48)) * 3600
10
13
 
11
14
 
12
15
  def is_within_last_three_days(date_to_check: datetime.datetime.date) -> bool:
@@ -34,8 +37,8 @@ class Score:
34
37
 
35
38
  @code.setter
36
39
  def code(self, code: str):
37
- assert utils.is_6digit(code), f'Invalid value : {code}'
38
- score_logger.info(f'change code : {self.code} -> {code}')
40
+ assert tools.is_6digit(code), f'Invalid value : {code}'
41
+ mylogger.info(f'change code : {self.code} -> {code}')
39
42
  self._code = code
40
43
  self.c101.code = code
41
44
  self.name = self.c101.get_name()
@@ -46,7 +49,7 @@ class Score:
46
49
  self.lstm.code = code
47
50
  self.prophet.code = code
48
51
 
49
- def get(self, refresh=False, expire_time_h=24) -> dict:
52
+ def get(self, refresh=False) -> dict:
50
53
  """
51
54
  한 종목의 각분야 평가를 모아서 딕셔너리 형태로 반환함.
52
55
  redis_name = self.code + '_score'
@@ -65,13 +68,13 @@ class Score:
65
68
  print(f"{self.code}/{self.name}의 scoring을 시작합니다.")
66
69
  redis_name = self.code + '_score'
67
70
  print(
68
- f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time_h}h")
71
+ f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time/3600}h")
69
72
 
70
73
  def fetch_score() -> dict:
71
- score_logger.info("시가총액 데이터 추출중..")
72
- 시가총액 = utils.format_large_number(int(self.c101.get_recent()['시가총액']))
74
+ mylogger.info("시가총액 데이터 추출중..")
75
+ 시가총액 = tools.format_large_number(int(self.c101.get_recent()['시가총액']))
73
76
 
74
- score_logger.info("C108 최근 데이터 추출중..")
77
+ mylogger.info("C108 최근 데이터 추출중..")
75
78
  # c108이 최근에 업데이트 되었는지...
76
79
  c108_recent_date = self.c108.get_recent_date()
77
80
  # print('code - ', code, ' | c108 recent date - ', c108_recent_date.date())
@@ -80,19 +83,19 @@ class Score:
80
83
  else:
81
84
  is_update_c108 = is_within_last_three_days(c108_recent_date.date())
82
85
 
83
- score_logger.info("Red score 계산중..")
86
+ mylogger.info("Red score 계산중..")
84
87
  red_score = self.red.get(verbose=False).score
85
88
 
86
- score_logger.info("Mil data 계산중..")
89
+ mylogger.info("Mil data 계산중..")
87
90
  mil_data = self.mil.get(verbose=False)
88
91
 
89
- score_logger.info("Lstm 최근 데이터 조회중..")
92
+ mylogger.info("Lstm 최근 데이터 조회중..")
90
93
  if myredis.Base.exists(f'{self.code}_mylstm_predictions'):
91
94
  is_lstm_up = self.lstm.is_up()
92
95
  else:
93
96
  is_lstm_up = None
94
97
 
95
- score_logger.info("\tProphet 최근 데이터 조회중..")
98
+ mylogger.info("\tProphet 최근 데이터 조회중..")
96
99
  prophet_score = self.prophet.scoring()
97
100
 
98
101
  return {
@@ -105,19 +108,17 @@ class Score:
105
108
  'is_lstm_up': is_lstm_up,
106
109
  'prophet_score': prophet_score,
107
110
  }
108
- data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_score, timer=expire_time_h * 3600)
111
+ data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_score, timer=expire_time)
109
112
  return data_dict
110
113
 
111
114
  @classmethod
112
- def ranking(self, refresh=False, expire_time_h=24, top='all') -> OrderedDict:
115
+ def ranking(self, refresh=False, top='all') -> OrderedDict:
113
116
  """
114
117
  prophet score 기준으로 정렬하여 ordered dict로 반환함
115
118
 
116
119
  Parameters:
117
120
  refresh (bool): Specifies whether to refresh the ranking data. Defaults
118
121
  to `False`.
119
- expire_time_h (int): Time in hours after which the cached data should
120
- expire. Defaults to `24` hours.
121
122
  top (Union[str, int]): Determines how many top rankings to return.
122
123
  Defaults to `'all'`. If an integer is provided, it limits the
123
124
  ranking to the specified count.
@@ -134,7 +135,7 @@ class Score:
134
135
  redis_name = 'score_ranking'
135
136
 
136
137
  print(
137
- f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time_h}h")
138
+ f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time/3600}h")
138
139
 
139
140
  def fetch_ranking() -> dict:
140
141
  data = {}
@@ -143,13 +144,13 @@ class Score:
143
144
  try:
144
145
  s.code = code
145
146
  except ValueError:
146
- score_logger.error(f'score ranking error : {code}')
147
+ mylogger.error(f'score ranking error : {code}')
147
148
  continue
148
149
  score = s.get(refresh=refresh)
149
150
  data[code] = score
150
151
  return data
151
152
 
152
- data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_ranking, timer=expire_time_h * 3600)
153
+ data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_ranking, timer=expire_time)
153
154
 
154
155
  # prophet_score를 기준으로 정렬
155
156
  ranking = OrderedDict(sorted(data_dict.items(), key=lambda x: x[1]['prophet_score'], reverse=True))
@@ -0,0 +1,2 @@
1
+ from .lstm import *
2
+ from .prophet import *