neurostats-API 0.0.7__tar.gz → 0.0.9__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/PKG-INFO +6 -5
  2. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/README.md +5 -4
  3. neurostats_API-0.0.9/neurostats_API/__init__.py +1 -0
  4. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/fetchers/balance_sheet.py +53 -34
  5. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/fetchers/cash_flow.py +15 -7
  6. neurostats_API-0.0.9/neurostats_API/fetchers/finance_overview.py +656 -0
  7. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/fetchers/month_revenue.py +9 -3
  8. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/fetchers/profit_lose.py +19 -4
  9. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/fetchers/value_invest.py +14 -5
  10. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/tools/finance_overview_dict.yaml +15 -8
  11. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/tools/seasonal_data_field_dict.txt +1 -0
  12. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/utils/data_process.py +28 -2
  13. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/utils/datetime.py +8 -0
  14. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API.egg-info/PKG-INFO +6 -5
  15. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/setup.py +1 -1
  16. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/test/test_fetchers.py +2 -0
  17. neurostats_API-0.0.7/neurostats_API/__init__.py +0 -1
  18. neurostats_API-0.0.7/neurostats_API/fetchers/finance_overview.py +0 -501
  19. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/MANIFEST.in +0 -0
  20. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/cli.py +0 -0
  21. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/fetchers/__init__.py +0 -0
  22. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/fetchers/base.py +0 -0
  23. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/fetchers/tech.py +0 -0
  24. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/main.py +0 -0
  25. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/tools/balance_sheet.yaml +0 -0
  26. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/tools/cash_flow_percentage.yaml +0 -0
  27. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/tools/profit_lose.yaml +0 -0
  28. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/utils/__init__.py +0 -0
  29. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/utils/db_client.py +0 -0
  30. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API/utils/fetcher.py +0 -0
  31. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API.egg-info/SOURCES.txt +0 -0
  32. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API.egg-info/dependency_links.txt +0 -0
  33. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/neurostats_API.egg-info/top_level.txt +0 -0
  34. {neurostats_API-0.0.7 → neurostats_API-0.0.9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: neurostats_API
3
- Version: 0.0.7
3
+ Version: 0.0.9
4
4
  Summary: The service of NeuroStats website
5
5
  Home-page: https://github.com/NeurowattStats/NeuroStats_API.git
6
6
  Author: JasonWang@Neurowatt
@@ -78,7 +78,7 @@ pip install neurostats-API
78
78
  ```Python
79
79
  >>> import neurostats_API
80
80
  >>> print(neurostats_API.__version__)
81
- 0.0.6
81
+ 0.0.9
82
82
  ```
83
83
 
84
84
  ### 得到最新一期的評價資料與歷年評價
@@ -379,11 +379,12 @@ stats_fetcher.query_data()
379
379
 
380
380
  ### 現金流量表
381
381
  ``` Python
382
- from neurostats_API.utils import StatsFetcher, DBClient
382
+ from neurostats_API.fetchers import CashFlowFetcher
383
383
  db_client = DBClient("<連接的DB位置>").get_client()
384
- fetcher = StatsFetcher(db_client)
385
384
  ticker = 2330 # 換成tw50內任意ticker
386
- stats_fetcher.get_cash_flow(ticker)
385
+ fetcher = StatsFetcher(ticker, db_client)
386
+
387
+ stats_fetcher.query()
387
388
  ```
388
389
  #### 回傳
389
390
  ```Python
@@ -68,7 +68,7 @@ pip install neurostats-API
68
68
  ```Python
69
69
  >>> import neurostats_API
70
70
  >>> print(neurostats_API.__version__)
71
- 0.0.6
71
+ 0.0.9
72
72
  ```
73
73
 
74
74
  ### 得到最新一期的評價資料與歷年評價
@@ -369,11 +369,12 @@ stats_fetcher.query_data()
369
369
 
370
370
  ### 現金流量表
371
371
  ``` Python
372
- from neurostats_API.utils import StatsFetcher, DBClient
372
+ from neurostats_API.fetchers import CashFlowFetcher
373
373
  db_client = DBClient("<連接的DB位置>").get_client()
374
- fetcher = StatsFetcher(db_client)
375
374
  ticker = 2330 # 換成tw50內任意ticker
376
- stats_fetcher.get_cash_flow(ticker)
375
+ fetcher = StatsFetcher(ticker, db_client)
376
+
377
+ stats_fetcher.query()
377
378
  ```
378
379
  #### 回傳
379
380
  ```Python
@@ -0,0 +1 @@
1
+ __version__='0.0.8'
@@ -1,10 +1,12 @@
1
1
  from .base import StatsFetcher, StatsDateTime
2
2
  import json
3
+ import numpy as np
3
4
  import pandas as pd
4
5
  from ..utils import StatsDateTime, StatsProcessor
5
6
  import importlib.resources as pkg_resources
6
7
  import yaml
7
8
 
9
+
8
10
  class BalanceSheetFetcher(StatsFetcher):
9
11
  """
10
12
  對應iFa.ai -> 財務分析 -> 資產負債表
@@ -13,7 +15,7 @@ class BalanceSheetFetcher(StatsFetcher):
13
15
  def __init__(self, ticker, db_client):
14
16
  super().__init__(ticker, db_client)
15
17
  self.table_settings = StatsProcessor.load_yaml("balance_sheet.yaml")
16
-
18
+
17
19
  def prepare_query(self, target_year, target_season):
18
20
  pipeline = super().prepare_query()
19
21
 
@@ -24,36 +26,42 @@ class BalanceSheetFetcher(StatsFetcher):
24
26
  }
25
27
 
26
28
  pipeline.append({
27
- "$project": {
28
- "_id": 0,
29
- "ticker": 1,
30
- "company_name": 1,
31
- "balance_sheets": {
32
- "$sortArray": {
33
- "input": {
34
- "$map": {
35
- "input": {
36
- "$filter": {
37
- "input": "$seasonal_data",
38
- "as": "season",
39
- "cond": {
40
- "$eq": ["$$season.season", target_season]
29
+ "$project": {
30
+ "_id": 0,
31
+ "ticker": 1,
32
+ "company_name": 1,
33
+ "balance_sheets": {
34
+ "$sortArray": {
35
+ "input": {
36
+ "$map": {
37
+ "input": {
38
+ "$filter": {
39
+ "input": "$seasonal_data",
40
+ "as": "season",
41
+ "cond": {
42
+ "$eq":
43
+ ["$$season.season", target_season]
44
+ }
41
45
  }
46
+ },
47
+ "as": "target_season_data",
48
+ "in": {
49
+ "year":
50
+ "$$target_season_data.year",
51
+ "season":
52
+ "$$target_season_data.season",
53
+ "balance_sheet":
54
+ "$$target_season_data.balance_sheet"
42
55
  }
43
- },
44
- "as": "target_season_data",
45
- "in": {
46
- "year": "$$target_season_data.year",
47
- "season": "$$target_season_data.season",
48
- "balance_sheet": "$$target_season_data.balance_sheet"
49
56
  }
50
- }
51
- },
52
- "sortBy": { "year": -1 } # 按 year 降序排序
57
+ },
58
+ "sortBy": {
59
+ "year": -1
60
+ } # 按 year 降序排序
61
+ }
53
62
  }
54
63
  }
55
- }
56
- })
64
+ })
57
65
 
58
66
  return pipeline
59
67
 
@@ -67,10 +75,16 @@ class BalanceSheetFetcher(StatsFetcher):
67
75
  return fetched_data[-1]
68
76
 
69
77
  def query_data(self):
70
- today = StatsDateTime.get_today()
78
+ try:
79
+ latest_time = StatsDateTime.get_latest_time(
80
+ self.ticker, self.collection)['last_update_time']
81
+ year = latest_time['seasonal_data']['latest_year']
82
+ season = latest_time['seasonal_data']['latest_season']
83
+ except Exception as e:
84
+ today = StatsDateTime.get_today()
85
+ year = today.year - 1 if (today.season == 1) else today.year
86
+ season = 4 if (today.season == 1) else today.season - 1
71
87
 
72
- year = today.year - 1 if (today.season == 1) else today.year
73
- season = 4 if (today.season == 1) else today.season - 2
74
88
  fetched_data = self.collect_data(year, season)
75
89
 
76
90
  return self.process_data(season, fetched_data)
@@ -93,20 +107,26 @@ class BalanceSheetFetcher(StatsFetcher):
93
107
 
94
108
  time_index = f"{year}Q{target_season}"
95
109
 
96
- # 蒐集整體的keys
110
+ # 蒐集整體的keys
97
111
  index_names += list(data['balance_sheet'].keys())
98
112
  balance_sheet = data['balance_sheet']
99
113
 
100
114
  for index_name, value_dict in balance_sheet.items():
101
115
  for item_name, item in value_dict.items():
102
- try: # table_dict[項目][(2020Q1, '%')]
103
- table_dict[index_name][(time_index,item_name)] = item
116
+ try: # table_dict[項目][(2020Q1, '%')]
117
+ if (item_name == 'percentage'):
118
+ if (isinstance(item, (float, int))):
119
+ item = np.round(item, 2)
120
+ if ("YoY" in item_name):
121
+ if (isinstance(item, (float, int))):
122
+ item = np.round(item * 100, 2)
123
+ table_dict[index_name][(time_index, item_name)] = item
104
124
 
105
125
  except KeyError:
106
126
  if (index_name not in table_dict.keys()):
107
127
  table_dict[index_name] = dict()
108
128
 
109
- table_dict[index_name][(time_index,item_name)] = item
129
+ table_dict[index_name][(time_index, item_name)] = item
110
130
 
111
131
  total_table = pd.DataFrame.from_dict(table_dict, orient='index')
112
132
  total_table.columns = pd.MultiIndex.from_tuples(total_table.columns)
@@ -118,5 +138,4 @@ class BalanceSheetFetcher(StatsFetcher):
118
138
  target_index=setting['target_index']
119
139
  if "target_index" in setting.keys() else None)
120
140
 
121
- print(f"{name}: {return_dict[name].columns}")
122
141
  return return_dict
@@ -1,5 +1,6 @@
1
1
  from .base import StatsFetcher, StatsDateTime
2
2
  import json
3
+ import numpy as np
3
4
  import pandas as pd
4
5
  from ..utils import StatsDateTime, StatsProcessor
5
6
  import importlib.resources as pkg_resources
@@ -64,9 +65,14 @@ class CashFlowFetcher(StatsFetcher):
64
65
  return list(fetched_data)[0]
65
66
 
66
67
  def query_data(self):
67
- today = StatsDateTime.get_today()
68
-
69
- target_season = today.season - 1 if (today.season > 1) else 4
68
+
69
+ try:
70
+ latest_time = StatsDateTime.get_latest_time(self.ticker, self.collection)['last_update_time']
71
+ target_season = latest_time['seasonal_data']['latest_season']
72
+
73
+ except:
74
+ today = StatsDateTime.get_today()
75
+ target_season = today.season - 1 if (today.season > 1) else 4
70
76
 
71
77
  fetched_data = self.collect_data(target_season)
72
78
 
@@ -127,8 +133,9 @@ class CashFlowFetcher(StatsFetcher):
127
133
  'value']
128
134
  if (value['value']):
129
135
  table_dict[time_index][index_name][
130
- 'percentage'] = value['value'] / cash_flow[
131
- main_cash_flow_name]['value']
136
+ 'percentage'] = np.round(
137
+ (value['value'] / cash_flow[
138
+ main_cash_flow_name]['value']) * 100, 2)
132
139
  else:
133
140
  table_dict[time_index][index_name][
134
141
  'percentage'] = None
@@ -141,8 +148,9 @@ class CashFlowFetcher(StatsFetcher):
141
148
  'value']
142
149
  if (value['value']):
143
150
  table_dict[time_index][index_name][
144
- 'percentage'] = value['value'] / cash_flow[
145
- main_cash_flow_name]['value']
151
+ 'percentage'] = np.round(
152
+ (value['value'] / cash_flow[
153
+ main_cash_flow_name]['value']) * 100, 2)
146
154
  else:
147
155
  table_dict[time_index][index_name][
148
156
  'percentage'] = None