neurostats-API 0.0.7__tar.gz → 0.0.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/PKG-INFO +6 -5
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/README.md +5 -4
- neurostats_API-0.0.8/neurostats_API/__init__.py +1 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/fetchers/balance_sheet.py +44 -31
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/fetchers/cash_flow.py +7 -4
- neurostats_API-0.0.8/neurostats_API/fetchers/finance_overview.py +648 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/fetchers/profit_lose.py +11 -1
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/tools/finance_overview_dict.yaml +15 -8
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/tools/seasonal_data_field_dict.txt +1 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/utils/data_process.py +28 -2
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API.egg-info/PKG-INFO +6 -5
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/setup.py +1 -1
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/test/test_fetchers.py +2 -0
- neurostats_API-0.0.7/neurostats_API/__init__.py +0 -1
- neurostats_API-0.0.7/neurostats_API/fetchers/finance_overview.py +0 -501
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/MANIFEST.in +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/cli.py +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/fetchers/__init__.py +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/fetchers/base.py +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/fetchers/month_revenue.py +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/fetchers/tech.py +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/fetchers/value_invest.py +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/main.py +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/tools/balance_sheet.yaml +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/tools/cash_flow_percentage.yaml +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/tools/profit_lose.yaml +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/utils/__init__.py +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/utils/datetime.py +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/utils/db_client.py +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API/utils/fetcher.py +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API.egg-info/SOURCES.txt +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API.egg-info/dependency_links.txt +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/neurostats_API.egg-info/top_level.txt +0 -0
- {neurostats_API-0.0.7 → neurostats_API-0.0.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: neurostats_API
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.8
|
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.
|
81
|
+
0.0.8
|
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.
|
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
|
-
|
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.
|
71
|
+
0.0.8
|
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.
|
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
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
57
|
+
},
|
58
|
+
"sortBy": {
|
59
|
+
"year": -1
|
60
|
+
} # 按 year 降序排序
|
61
|
+
}
|
53
62
|
}
|
54
63
|
}
|
55
|
-
}
|
56
|
-
})
|
64
|
+
})
|
57
65
|
|
58
66
|
return pipeline
|
59
67
|
|
@@ -93,20 +101,26 @@ class BalanceSheetFetcher(StatsFetcher):
|
|
93
101
|
|
94
102
|
time_index = f"{year}Q{target_season}"
|
95
103
|
|
96
|
-
|
104
|
+
# 蒐集整體的keys
|
97
105
|
index_names += list(data['balance_sheet'].keys())
|
98
106
|
balance_sheet = data['balance_sheet']
|
99
107
|
|
100
108
|
for index_name, value_dict in balance_sheet.items():
|
101
109
|
for item_name, item in value_dict.items():
|
102
|
-
try:
|
103
|
-
|
110
|
+
try: # table_dict[項目][(2020Q1, '%')]
|
111
|
+
if (item_name == 'percentage'):
|
112
|
+
if (isinstance(item, (float, int))):
|
113
|
+
item = np.round(item, 2)
|
114
|
+
if ("YoY" in item_name):
|
115
|
+
if (isinstance(item, (float, int))):
|
116
|
+
item = np.round(item * 100, 2)
|
117
|
+
table_dict[index_name][(time_index, item_name)] = item
|
104
118
|
|
105
119
|
except KeyError:
|
106
120
|
if (index_name not in table_dict.keys()):
|
107
121
|
table_dict[index_name] = dict()
|
108
122
|
|
109
|
-
table_dict[index_name][(time_index,item_name)] = item
|
123
|
+
table_dict[index_name][(time_index, item_name)] = item
|
110
124
|
|
111
125
|
total_table = pd.DataFrame.from_dict(table_dict, orient='index')
|
112
126
|
total_table.columns = pd.MultiIndex.from_tuples(total_table.columns)
|
@@ -118,5 +132,4 @@ class BalanceSheetFetcher(StatsFetcher):
|
|
118
132
|
target_index=setting['target_index']
|
119
133
|
if "target_index" in setting.keys() else None)
|
120
134
|
|
121
|
-
print(f"{name}: {return_dict[name].columns}")
|
122
135
|
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
|
@@ -127,8 +128,9 @@ class CashFlowFetcher(StatsFetcher):
|
|
127
128
|
'value']
|
128
129
|
if (value['value']):
|
129
130
|
table_dict[time_index][index_name][
|
130
|
-
'percentage'] =
|
131
|
-
|
131
|
+
'percentage'] = np.round(
|
132
|
+
(value['value'] / cash_flow[
|
133
|
+
main_cash_flow_name]['value']) * 100, 2)
|
132
134
|
else:
|
133
135
|
table_dict[time_index][index_name][
|
134
136
|
'percentage'] = None
|
@@ -141,8 +143,9 @@ class CashFlowFetcher(StatsFetcher):
|
|
141
143
|
'value']
|
142
144
|
if (value['value']):
|
143
145
|
table_dict[time_index][index_name][
|
144
|
-
'percentage'] =
|
145
|
-
|
146
|
+
'percentage'] = np.round(
|
147
|
+
(value['value'] / cash_flow[
|
148
|
+
main_cash_flow_name]['value']) * 100, 2)
|
146
149
|
else:
|
147
150
|
table_dict[time_index][index_name][
|
148
151
|
'percentage'] = None
|