analyser_hj3415 2.9.9__py3-none-any.whl → 2.9.11__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
analyser_hj3415/cli.py CHANGED
@@ -2,9 +2,9 @@ import argparse
2
2
  import os
3
3
  import pprint
4
4
 
5
- from utils_hj3415 import noti, utils
5
+ from utils_hj3415 import utils
6
6
  from utils_hj3415.helpers import SettingsManager
7
- from db_hj3415 import myredis, mypeewee
7
+ from db_hj3415 import myredis, mymongo
8
8
 
9
9
  class AnalyserSettingsManager(SettingsManager):
10
10
  DEFAULT_SETTINGS = {
@@ -33,8 +33,6 @@ class AnalyserSettingsManager(SettingsManager):
33
33
  print(f"{title}이 기본값 ({self.DEFAULT_SETTINGS[title]}) 으로 초기화 되었습니다.")
34
34
 
35
35
 
36
- log_cli = mypeewee.LogManager('cli')
37
-
38
36
  def analyser_manager():
39
37
  settings_manager = AnalyserSettingsManager()
40
38
  expect_earn_from_setting = settings_manager.get_value('EXPECT_EARN')
@@ -151,10 +149,10 @@ def analyser_manager():
151
149
 
152
150
  # 원래 저장되었던 기대수익률로 다시 복원
153
151
  eval.Red.expect_earn = ee_orig
154
- log_cli.save('INFO', f'run >> analyser red get {args.code}')
152
+ mymongo.Logs.save('cli','INFO', f'run >> analyser red get {args.code}')
155
153
 
156
154
  elif args.command == 'ranking':
157
- log_cli.save('INFO', 'run >> analyser red ranking')
155
+ mymongo.Logs.save('cli','INFO', 'run >> analyser red ranking')
158
156
  result = eval.Red.ranking(expect_earn=args.expect_earn, refresh=args.refresh)
159
157
  print(result)
160
158
 
@@ -172,7 +170,7 @@ def analyser_manager():
172
170
  mil = eval.Mil(args.code)
173
171
  print(f"*** Mil - {mil} ***")
174
172
  pprint.pprint(mil.get(args.refresh))
175
- log_cli.save('INFO', f'run >> analyser mil get {args.code}')
173
+ mymongo.Logs.save('cli','INFO', f'run >> analyser mil get {args.code}')
176
174
 
177
175
  elif args.type == 'blue':
178
176
  if args.command == 'get':
@@ -188,7 +186,7 @@ def analyser_manager():
188
186
  blue = eval.Blue(args.code)
189
187
  print(f"*** Blue - {blue} ***")
190
188
  pprint.pprint(blue.get(args.refresh))
191
- log_cli.save('INFO', f'run >> analyser blue get {args.code}')
189
+ mymongo.Logs.save('cli','INFO', f'run >> analyser blue get {args.code}')
192
190
 
193
191
  elif args.type == 'growth':
194
192
  if args.command == 'get':
@@ -204,29 +202,27 @@ def analyser_manager():
204
202
  growth = eval.Growth(args.code)
205
203
  print(f"*** growth - {growth} ***")
206
204
  pprint.pprint(growth.get(args.refresh))
207
- log_cli.save('INFO', f'run >> analyser growth get {args.code}')
205
+ mymongo.Logs.save('cli','INFO', f'run >> analyser growth get {args.code}')
208
206
 
209
207
  elif args.type == 'prophet':
210
208
  if args.command == 'ranking':
211
209
  myprophet = tsa.MyProphet
212
- myprophet.expire_time_h = 72
213
- result = myprophet.ranking(refresh=args.refresh)
210
+ result = myprophet.ranking(refresh=args.refresh, expire_time_h=24)
214
211
  print(result)
215
- log_cli.save('INFO', 'run >> analyser prophet ranking')
212
+ mymongo.Logs.save('cli','INFO', 'run >> analyser prophet ranking')
216
213
 
217
214
  elif args.type == 'lstm':
218
215
  mylstm = tsa.MyLSTM
219
- mylstm.expire_time_h = 72
220
216
  if args.command == 'caching':
221
217
  if args.top:
222
- mylstm.caching_based_on_prophet_ranking(refresh=args.refresh, top=args.top)
218
+ mylstm.caching_based_on_prophet_ranking(refresh=args.refresh, expire_time_h=48, top=args.top)
223
219
  else:
224
- mylstm.caching_based_on_prophet_ranking(refresh=args.refresh)
225
- log_cli.save('INFO', f'run >> analyser lstm caching / top={args.top if args.top else 20})')
220
+ mylstm.caching_based_on_prophet_ranking(refresh=args.refresh, expire_time_h=48)
221
+ mymongo.Logs.save('cli','INFO', f'run >> analyser lstm caching / top={args.top if args.top else 20})')
226
222
  elif args.command == 'get':
227
223
  assert utils.is_6digit(args.code), "code 인자는 6자리 숫자이어야 합니다."
228
- result = mylstm(args.code).get_final_predictions(refresh=args.refresh)
229
- log_cli.save('INFO', f'run >> analyser lstm get {args.code}')
224
+ result = mylstm(args.code).get_final_predictions(refresh=args.refresh, expire_time_h=48)
225
+ mymongo.Logs.save('cli','INFO', f'run >> analyser lstm get {args.code}')
230
226
 
231
227
  elif args.type == 'setting':
232
228
  if args.command == 'set':
@@ -239,5 +235,3 @@ def analyser_manager():
239
235
 
240
236
  else:
241
237
  parser.print_help()
242
-
243
- log_cli.close()
analyser_hj3415/tsa.py CHANGED
@@ -30,10 +30,8 @@ import logging
30
30
 
31
31
  tsa_logger = helpers.setup_logger('tsa_logger', logging.WARNING)
32
32
 
33
- expire_time = 3600 * 24
34
33
 
35
34
  class MyProphet:
36
- expire_time_h = 24
37
35
  def __init__(self, code: str):
38
36
  assert utils.is_6digit(code), f'Invalid value : {code}'
39
37
  self.scaler = StandardScaler()
@@ -195,7 +193,7 @@ class MyProphet:
195
193
  Exception("to 인자가 맞지 않습니다.")
196
194
 
197
195
  @classmethod
198
- def ranking(cls, refresh = False) -> OrderedDict:
196
+ def ranking(cls, refresh = False, expire_time_h = 24) -> OrderedDict:
199
197
  """
200
198
  가장 최근 날짜의 랭킹 분석
201
199
  :param refresh:
@@ -205,7 +203,7 @@ class MyProphet:
205
203
  redis_name = 'myprophet_ranking'
206
204
 
207
205
  print(
208
- f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {MyProphet.expire_time_h}h")
206
+ f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time_h}h")
209
207
 
210
208
  def fetch_ranking() -> dict:
211
209
  data = {}
@@ -224,7 +222,7 @@ class MyProphet:
224
222
  print(f"{i}.{p.code}/{p.name} date: {recent_date} 가격:{recent_price} 기대하한값:{yhat_lower} 편차:{deviation}")
225
223
  return data
226
224
 
227
- data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_ranking, timer=MyProphet.expire_time_h * 3600)
225
+ data_dict = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_ranking, timer=expire_time_h * 3600)
228
226
 
229
227
  return OrderedDict(sorted(data_dict.items(), key=lambda item: item[1], reverse=True))
230
228
 
@@ -265,7 +263,6 @@ class MyLSTM:
265
263
  """
266
264
  # 미래 몇일을 예측할 것인가?
267
265
  future_days = 30
268
- expire_time_h = 48
269
266
 
270
267
  def __init__(self, code: str):
271
268
  assert utils.is_6digit(code), f'Invalid value : {code}'
@@ -489,7 +486,7 @@ class MyLSTM:
489
486
  test_r2=test_r2,
490
487
  )
491
488
 
492
- def get_final_predictions(self, refresh, num=5) -> tuple:
489
+ def get_final_predictions(self, refresh: bool, expire_time_h: int, num=5) -> tuple:
493
490
  """
494
491
  미래 예측치를 레디스 캐시를 이용하여 반환함
495
492
  :param refresh:
@@ -500,7 +497,7 @@ class MyLSTM:
500
497
  redis_name = f'{self.code}_mylstm_predictions'
501
498
 
502
499
  print(
503
- f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {MyLSTM.expire_time_h}h")
500
+ f"redisname: '{redis_name}' / refresh : {refresh} / expire_time : {expire_time_h}h")
504
501
 
505
502
  def fetch_final_predictions(num_in) -> tuple:
506
503
  """
@@ -531,7 +528,7 @@ class MyLSTM:
531
528
 
532
529
  return future_dates_str, final_future_predictions.tolist()
533
530
 
534
- future_dates_str, final_future_predictions = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_final_predictions, num, timer=MyLSTM.expire_time_h * 3600)
531
+ future_dates_str, final_future_predictions = myredis.Base.fetch_and_cache_data(redis_name, refresh, fetch_final_predictions, num, timer=expire_time_h * 3600)
535
532
 
536
533
  # 문자열을 날짜 형식으로 변환
537
534
  future_dates = [datetime.strptime(date, '%Y-%m-%d') for date in future_dates_str]
@@ -541,14 +538,14 @@ class MyLSTM:
541
538
 
542
539
  return future_dates, final_future_predictions
543
540
 
544
- def export(self, refresh=False, to="str") -> Optional[str]:
541
+ def export(self, refresh=False, expire_time_h=24, to="str") -> Optional[str]:
545
542
  """
546
543
  prophet과 plotly로 그래프를 그려서 html을 문자열로 반환
547
544
  :param refresh:
548
545
  :param to: str, htmlfile, png
549
546
  :return:
550
547
  """
551
- future_dates, final_future_predictions = self.get_final_predictions(refresh=refresh)
548
+ future_dates, final_future_predictions = self.get_final_predictions(refresh=refresh, expire_time_h=expire_time_h)
552
549
  final_future_predictions = final_future_predictions.reshape(-1) # 차원을 하나 줄인다.
553
550
 
554
551
  # 데이터 준비
@@ -636,7 +633,7 @@ class MyLSTM:
636
633
  Exception("to 인자가 맞지 않습니다.")
637
634
 
638
635
  def visualization(self, refresh=True):
639
- future_dates, final_future_predictions = self.get_final_predictions(refresh=refresh)
636
+ future_dates, final_future_predictions = self.get_final_predictions(refresh=refresh, expire_time_h=1)
640
637
 
641
638
  # 시각화1
642
639
  plt.figure(figsize=(10, 6))
@@ -664,15 +661,15 @@ class MyLSTM:
664
661
  plt.show()"""
665
662
 
666
663
  @staticmethod
667
- def caching_based_on_prophet_ranking(refresh: bool, top=20):
668
- ranking_topn = OrderedDict(itertools.islice(MyProphet.ranking().items(), top))
664
+ def caching_based_on_prophet_ranking(refresh: bool, expire_time_h: int, top=20):
665
+ ranking_topn = OrderedDict(itertools.islice(MyProphet.ranking(refresh=False).items(), top))
669
666
  tsa_logger.info(ranking_topn)
670
667
  mylstm = MyLSTM('005930')
671
668
  print(f"*** LSTM prediction redis cashing top{top} items ***")
672
669
  for i, (code, _) in enumerate(ranking_topn.items()):
673
670
  mylstm.code = code
674
671
  print(f"{i+1}. {mylstm.code}/{mylstm.name}")
675
- mylstm.get_final_predictions(refresh=refresh, num=5)
672
+ mylstm.get_final_predictions(refresh=refresh, expire_time_h=expire_time_h, num=5)
676
673
 
677
674
 
678
675
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: analyser_hj3415
3
- Version: 2.9.9
3
+ Version: 2.9.11
4
4
  Summary: Stock analyser and database processing programs
5
5
  Requires-Python: >=3.6
6
6
  Description-Content-Type: text/markdown
@@ -1,13 +1,13 @@
1
1
  analyser_hj3415/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- analyser_hj3415/cli.py,sha256=CHdIdsPVzXRQoMazp0QJD-6-_DjlLTyJ4C1IBD3IQL8,12517
2
+ analyser_hj3415/cli.py,sha256=90i1haDFNGpTNf-lnQKUARsN0lPFJgv_qXFSIsl1Sa4,12541
3
3
  analyser_hj3415/eval.py,sha256=WWIvB4BebjW9GNGcF8rMd-MLL-lPXUBOH01_FpSq95I,38811
4
- analyser_hj3415/tsa.py,sha256=yNYeLpuUH7eGNAmSadvkbHQ91gz9Z1o_u9dGwntF4OI,26916
4
+ analyser_hj3415/tsa.py,sha256=8JSAdLLApcRDIjrTo8pveHliBUObzpGWlq-yxZNsIZw,26984
5
5
  analyser_hj3415/workroom/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  analyser_hj3415/workroom/mysklearn.py,sha256=wJXKz5MqqTzADdG2mqRMMzc_G9RzwYjj5_j4gyOopxQ,2030
7
7
  analyser_hj3415/workroom/mysklearn2.py,sha256=1lIy6EWEQHkOzDS-av8U0zQH6DuCLKWMI73dnJx5KRs,1495
8
8
  analyser_hj3415/workroom/score.py,sha256=P6nHBJYmyhigGtT4qna4BmNtvt4B93b7SKyzdstJK24,17376
9
9
  analyser_hj3415/workroom/trash.py,sha256=zF-W0piqkGr66UP6-iybo9EXh2gO0RP6R1FnIpsGkl8,12262
10
- analyser_hj3415-2.9.9.dist-info/entry_points.txt,sha256=ZfjPnJuH8SzvhE9vftIPMBIofsc65IAWYOhqOC_L5ck,65
11
- analyser_hj3415-2.9.9.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
12
- analyser_hj3415-2.9.9.dist-info/METADATA,sha256=vTdeO4MRJYOfIOpyiuBPYC0XafTIbPA0NllgE1UD9ow,6776
13
- analyser_hj3415-2.9.9.dist-info/RECORD,,
10
+ analyser_hj3415-2.9.11.dist-info/entry_points.txt,sha256=ZfjPnJuH8SzvhE9vftIPMBIofsc65IAWYOhqOC_L5ck,65
11
+ analyser_hj3415-2.9.11.dist-info/WHEEL,sha256=CpUCUxeHQbRN5UGRQHYRJorO5Af-Qy_fHMctcQ8DSGI,82
12
+ analyser_hj3415-2.9.11.dist-info/METADATA,sha256=LA5DUuaj3BQQaZ2fdw_Q7RYaKefyJHHbZXY0qgsaRkE,6777
13
+ analyser_hj3415-2.9.11.dist-info/RECORD,,