neurostats-API 0.0.21b0__py3-none-any.whl → 0.0.23b0__py3-none-any.whl
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/__init__.py +1 -1
- neurostats_API/fetchers/balance_sheet.py +138 -111
- neurostats_API/fetchers/base.py +89 -74
- neurostats_API/fetchers/cash_flow.py +120 -111
- neurostats_API/fetchers/finance_overview.py +2 -2
- neurostats_API/fetchers/month_revenue.py +1 -1
- neurostats_API/fetchers/profit_lose.py +188 -113
- neurostats_API/fetchers/tech.py +175 -42
- neurostats_API/fetchers/tej_finance_report.py +230 -335
- neurostats_API/tools/company_list/tw.json +2175 -0
- neurostats_API/tools/tej_db/tej_db_skip_index.yaml +3 -1
- neurostats_API/tools/tej_db/tej_db_thousand_index.yaml +0 -1
- neurostats_API/utils/__init__.py +0 -1
- neurostats_API/utils/calculate_value.py +99 -1
- neurostats_API/utils/data_process.py +43 -15
- {neurostats_API-0.0.21b0.dist-info → neurostats_API-0.0.23b0.dist-info}/METADATA +2 -2
- neurostats_API-0.0.23b0.dist-info/RECORD +34 -0
- neurostats_API/utils/fetcher.py +0 -1056
- neurostats_API-0.0.21b0.dist-info/RECORD +0 -34
- /neurostats_API/tools/{balance_sheet.yaml → twse/balance_sheet.yaml} +0 -0
- /neurostats_API/tools/{cash_flow_percentage.yaml → twse/cash_flow_percentage.yaml} +0 -0
- /neurostats_API/tools/{finance_overview_dict.yaml → twse/finance_overview_dict.yaml} +0 -0
- /neurostats_API/tools/{profit_lose.yaml → twse/profit_lose.yaml} +0 -0
- /neurostats_API/tools/{seasonal_data_field_dict.txt → twse/seasonal_data_field_dict.txt} +0 -0
- {neurostats_API-0.0.21b0.dist-info → neurostats_API-0.0.23b0.dist-info}/WHEEL +0 -0
- {neurostats_API-0.0.21b0.dist-info → neurostats_API-0.0.23b0.dist-info}/top_level.txt +0 -0
neurostats_API/utils/__init__.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
from .data_process import StatsProcessor
|
1
2
|
class YoY_Calculator:
|
2
3
|
def __init__(self):
|
3
4
|
pass
|
@@ -23,4 +24,101 @@ class YoY_Calculator:
|
|
23
24
|
if (isinstance(YoY, complex)): # 年化成長率有複數問題
|
24
25
|
return None
|
25
26
|
|
26
|
-
return YoY
|
27
|
+
return YoY
|
28
|
+
@classmethod
|
29
|
+
def calculate_growth(cls, this_value, last_value, delta):
|
30
|
+
try:
|
31
|
+
return YoY_Calculator.cal_growth(
|
32
|
+
this_value, last_value, delta
|
33
|
+
) * 100
|
34
|
+
except Exception:
|
35
|
+
return None
|
36
|
+
|
37
|
+
@classmethod
|
38
|
+
def cal_YoY(
|
39
|
+
cls, data_dict: dict
|
40
|
+
):
|
41
|
+
year_shifts = [1, 3, 5, 10]
|
42
|
+
return_dict = {}
|
43
|
+
|
44
|
+
for time_index in data_dict.keys():
|
45
|
+
year, season = map(int, time_index.split("Q"))
|
46
|
+
|
47
|
+
year_data = data_dict.get(f"{year}Q{season}", {}).copy()
|
48
|
+
if not year_data:
|
49
|
+
continue
|
50
|
+
|
51
|
+
for key, data in list(year_data.items()):
|
52
|
+
if key in ["year", "season"]:
|
53
|
+
continue
|
54
|
+
|
55
|
+
if (isinstance(data, dict)):
|
56
|
+
temp_dict = data
|
57
|
+
value = data.get("value", None)
|
58
|
+
else:
|
59
|
+
temp_dict = {"value": data}
|
60
|
+
value = data
|
61
|
+
|
62
|
+
this_value = StatsProcessor.process_str_to_float(value)
|
63
|
+
|
64
|
+
for shift in year_shifts:
|
65
|
+
past_value = data_dict.get(f"{year - shift}Q{season}", {}).get(key, {})
|
66
|
+
if (isinstance(past_value, dict)):
|
67
|
+
past_value = past_value.get('value', None)
|
68
|
+
past_value = StatsProcessor.process_str_to_float(
|
69
|
+
past_value
|
70
|
+
)
|
71
|
+
|
72
|
+
growth = cls.calculate_growth(this_value, past_value, shift) if past_value else None
|
73
|
+
|
74
|
+
temp_dict[
|
75
|
+
f"YoY_{shift}"
|
76
|
+
] = f"{growth:.2f}%" if growth else None
|
77
|
+
|
78
|
+
year_data[key] = temp_dict
|
79
|
+
return_dict[f"{year}Q{season}"] = year_data
|
80
|
+
return return_dict
|
81
|
+
@classmethod
|
82
|
+
def cal_QoQ(cls, data_dict):
|
83
|
+
return_dict = {}
|
84
|
+
|
85
|
+
for time_index, this_data in data_dict.items():
|
86
|
+
year, season = map(int, time_index.split("Q"))
|
87
|
+
last_year, last_season = (
|
88
|
+
year - 1, 4
|
89
|
+
) if season == 1 else (year, season - 1)
|
90
|
+
|
91
|
+
for key in list(this_data.keys()):
|
92
|
+
if key == "season":
|
93
|
+
continue
|
94
|
+
|
95
|
+
|
96
|
+
value = this_data.get(key, None)
|
97
|
+
|
98
|
+
if (isinstance(value, dict)):
|
99
|
+
temp_dict = value
|
100
|
+
this_value = value.get("value", None)
|
101
|
+
else:
|
102
|
+
temp_dict = {"value": value}
|
103
|
+
this_value = value
|
104
|
+
|
105
|
+
this_value = StatsProcessor.process_str_to_float(this_data[key])
|
106
|
+
|
107
|
+
last_value = data_dict.get(
|
108
|
+
f"{last_year}Q{last_season}",{}
|
109
|
+
).get(key, {})
|
110
|
+
|
111
|
+
if (isinstance(last_value, dict)):
|
112
|
+
last_value = last_value.get("value", None)
|
113
|
+
|
114
|
+
last_value = StatsProcessor.process_str_to_float(last_value)
|
115
|
+
growth = cls.calculate_growth(
|
116
|
+
this_value, last_value, 1
|
117
|
+
) if last_value is not None else None
|
118
|
+
temp_dict['growth'] = (f"{growth:.2f}%" if growth else None)
|
119
|
+
|
120
|
+
this_data[key] = temp_dict
|
121
|
+
|
122
|
+
return_dict[time_index] = this_data
|
123
|
+
|
124
|
+
return return_dict
|
@@ -36,6 +36,14 @@ class StatsProcessor:
|
|
36
36
|
data = yaml.safe_load(f)
|
37
37
|
|
38
38
|
return data
|
39
|
+
|
40
|
+
@classmethod
|
41
|
+
def load_json(cls, filename):
|
42
|
+
yaml_path = files('neurostats_API.tools').joinpath(filename)
|
43
|
+
with open(yaml_path, 'r', encoding='utf-8') as f:
|
44
|
+
data = json.load(f)
|
45
|
+
|
46
|
+
return data
|
39
47
|
|
40
48
|
@classmethod
|
41
49
|
def expand_value_percentage(cls, dataframe):
|
@@ -52,6 +60,23 @@ class StatsProcessor:
|
|
52
60
|
expanded_df = pd.concat(expanded_columns.values(), axis=1)
|
53
61
|
|
54
62
|
return expanded_df
|
63
|
+
|
64
|
+
@classmethod
|
65
|
+
def slice_old_table(
|
66
|
+
cls,
|
67
|
+
total_table,
|
68
|
+
target_index,
|
69
|
+
):
|
70
|
+
"""
|
71
|
+
對舊格式的轉換
|
72
|
+
對只有單層column的table,切出想要的index
|
73
|
+
"""
|
74
|
+
|
75
|
+
if (target_index):
|
76
|
+
target_index = target_index.split()
|
77
|
+
return total_table.loc[target_index, :]
|
78
|
+
else:
|
79
|
+
return total_table
|
55
80
|
|
56
81
|
@classmethod
|
57
82
|
def slice_table(
|
@@ -61,30 +86,24 @@ class StatsProcessor:
|
|
61
86
|
target_index=None, # None or Str, 要特別抓哪個index
|
62
87
|
):
|
63
88
|
"""
|
64
|
-
total_table: column應為 <時間>_
|
65
|
-
對只有單層column的table,切出想要的index
|
89
|
+
total_table: column應為 <時間>_<季>
|
66
90
|
"""
|
67
|
-
times = [
|
68
|
-
column.split("_")[0] for column in total_table.columns.unique()
|
69
|
-
] #取出timeIndex
|
70
91
|
try:
|
71
92
|
target_metrics = target_metric_dict[mode]
|
72
93
|
except KeyError as e:
|
73
|
-
|
74
|
-
|
75
|
-
desired_order = [
|
76
|
-
f"{time}_{value_name}" for time in times
|
77
|
-
for value_name in target_metrics
|
78
|
-
]
|
94
|
+
raise ValueError(f"mode Error: Get mode should be {list(target_metric_dict.keys())} but get {mode}")
|
79
95
|
|
80
96
|
if (target_index):
|
81
|
-
target_index = target_index.split()
|
82
|
-
|
97
|
+
target_index = [index_name.strip() for index_name in target_index.split()]
|
98
|
+
desired_order = []
|
99
|
+
for index_name in target_index:
|
100
|
+
desired_order += [f"{index_name}_{metric_name}" for metric_name in target_metrics]
|
101
|
+
sliced_table = total_table.loc[desired_order, :].T
|
83
102
|
|
84
103
|
return sliced_table.T
|
85
104
|
|
86
105
|
else:
|
87
|
-
return total_table
|
106
|
+
return total_table
|
88
107
|
|
89
108
|
@classmethod
|
90
109
|
def slice_multi_col_table(
|
@@ -275,4 +294,13 @@ class StatsProcessor:
|
|
275
294
|
pop_key = delimeter.join(pop_keys)
|
276
295
|
return_dict[pop_key] = data[data_key]
|
277
296
|
|
278
|
-
return return_dict
|
297
|
+
return return_dict
|
298
|
+
|
299
|
+
@classmethod
|
300
|
+
def process_str_to_float(cls, value):
|
301
|
+
if isinstance(value, str) and "%" in value:
|
302
|
+
value = value.replace("%", "")
|
303
|
+
try:
|
304
|
+
return float(value)
|
305
|
+
except (ValueError, TypeError):
|
306
|
+
return None
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: neurostats_API
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.23b0
|
4
4
|
Summary: The service of NeuroStats website
|
5
5
|
Home-page: https://github.com/NeurowattStats/NeuroStats_API.git
|
6
6
|
Author: JasonWang@Neurowatt
|
@@ -89,7 +89,7 @@ pip install neurostats-API
|
|
89
89
|
```Python
|
90
90
|
>>> import neurostats_API
|
91
91
|
>>> print(neurostats_API.__version__)
|
92
|
-
0.0.
|
92
|
+
0.0.23b
|
93
93
|
```
|
94
94
|
|
95
95
|
### 得到最新一期的評價資料與歷年評價
|
@@ -0,0 +1,34 @@
|
|
1
|
+
neurostats_API/__init__.py,sha256=ItIYqBMTp2EHBeBahEWCKKGa-JIzQO2ykdQy3A-LNZY,289
|
2
|
+
neurostats_API/cli.py,sha256=UJSWLIw03P24p-gkBb6JSEI5dW5U12UvLf1L8HjQD-o,873
|
3
|
+
neurostats_API/main.py,sha256=QcsfmWivg2Dnqw3MTJWiI0QvEiRs0VuH-BjwQHFCv00,677
|
4
|
+
neurostats_API/fetchers/__init__.py,sha256=KCw-yRSDFa3fw83u73LJ9OVop7gRl_YQYlQq-cITxuo,511
|
5
|
+
neurostats_API/fetchers/balance_sheet.py,sha256=RgiX5wp9UoS7HcXHqwO_NMAFr2ESJSWJenyCwJj6rxU,6060
|
6
|
+
neurostats_API/fetchers/base.py,sha256=BcGpwlA0TD8y-Uped68xPf-cZYHP9PB4UyDWgPcURe4,7155
|
7
|
+
neurostats_API/fetchers/cash_flow.py,sha256=0it4hnKLKRLAFgrxrsrK2rk7dom7HvQi96z5LXh2w_c,7013
|
8
|
+
neurostats_API/fetchers/finance_overview.py,sha256=dDe6THJg1UJffnJ25xwXd4K99s2DBTdGaxmCT3O-xdA,27763
|
9
|
+
neurostats_API/fetchers/institution.py,sha256=UrcBc6t7u7CnEwUsf6YmLbbJ8VncdWpq8bCz17q2dgs,11168
|
10
|
+
neurostats_API/fetchers/margin_trading.py,sha256=lQImtNdvaBoSlKhJvQ3DkH3HjSSgKRJz4ZZpyR5-Z4I,10433
|
11
|
+
neurostats_API/fetchers/month_revenue.py,sha256=DZeOblfSz7NhQXVvL5xfMHZ1rv2B8pgqu-U-o_gcAuc,6323
|
12
|
+
neurostats_API/fetchers/profit_lose.py,sha256=ZvSG4vx4gBrWMKmcyuSaoNyW6JGiOtIpFxRIeyCAeDY,7705
|
13
|
+
neurostats_API/fetchers/tech.py,sha256=LvgWhcHdruTGJE_1_z8rrArJs3s7X5AbE3LtuR4zwIM,18051
|
14
|
+
neurostats_API/fetchers/tej_finance_report.py,sha256=5ERpg1kq2wSPdLMBYXX5MUWRxOrwwFHSBXNidSKeuRo,11233
|
15
|
+
neurostats_API/fetchers/value_invest.py,sha256=b_x2Dpgs8VBU5HdG8ocKtfIEkqhU-Q0S5n6RxuFuM2g,7467
|
16
|
+
neurostats_API/tools/company_list/tw.json,sha256=VWaDFvd0ACCVSWItcHHpmVuM_RzP71jLZl9RBHztu-0,51332
|
17
|
+
neurostats_API/tools/tej_db/tej_db_index.yaml,sha256=lu-cmbB6dhx0eUlBSkyzXWqPKlwRtEvqlMTAh2y0oHs,969
|
18
|
+
neurostats_API/tools/tej_db/tej_db_percent_index.yaml,sha256=-rBSdOoYs5UB9H6Y3FE5PTqV9meXEFZD2KhSlAQ_4Eg,323
|
19
|
+
neurostats_API/tools/tej_db/tej_db_skip_index.yaml,sha256=nSbrflaJrWCIjL5WeHT3UDKZyN0WegVElUKVYA4YSa0,169
|
20
|
+
neurostats_API/tools/tej_db/tej_db_thousand_index.yaml,sha256=S1k4PFZ7NsjGUgeCb89dyaojkOcvGPRdBr45hz3wlWY,507
|
21
|
+
neurostats_API/tools/twse/balance_sheet.yaml,sha256=6XygNG_Ybb1Xkk1e39LMLKr7ATvaCP3xxuwFbgNl6dA,673
|
22
|
+
neurostats_API/tools/twse/cash_flow_percentage.yaml,sha256=fk2Z4eb1JjGFvP134eJatHacB7BgTkBenhDJr83w8RE,1345
|
23
|
+
neurostats_API/tools/twse/finance_overview_dict.yaml,sha256=B9nV75StXkrF3yv2-eezzitlJ38eEK86RD_VY6588gQ,2884
|
24
|
+
neurostats_API/tools/twse/profit_lose.yaml,sha256=iyp9asYJ04vAxk_HBUDse_IBy5oVvYHpwsyACg5YEeg,3029
|
25
|
+
neurostats_API/tools/twse/seasonal_data_field_dict.txt,sha256=X8yc_el6p8BH_3FikTqBVFGsvWdXT6MHXLfKfi44334,8491
|
26
|
+
neurostats_API/utils/__init__.py,sha256=uZk08lGPvVIc7MKAvRdZ2FJzgfa8GzsWG_hWAhF6C5U,152
|
27
|
+
neurostats_API/utils/calculate_value.py,sha256=Zc5DG_qXnHZLkCjUYdoMWka3KVXu2o9AmDnEYixiXYQ,4197
|
28
|
+
neurostats_API/utils/data_process.py,sha256=LdDmhQMGBg1UI6cIWCdsj9YTkixtf1cyrN1xq2JZmPo,9971
|
29
|
+
neurostats_API/utils/datetime.py,sha256=XJya4G8b_-ZOaBbMXgQjWh2MC4wc-o6goQ7EQJQMWrQ,773
|
30
|
+
neurostats_API/utils/db_client.py,sha256=OYe6yazcR4Aa6jYmy47JrryUeh2NnKGqY2K_lSZe6i8,455
|
31
|
+
neurostats_API-0.0.23b0.dist-info/METADATA,sha256=433KG3-zXJJeDPaZcmxBBIsamFrZziYqmGNoNG-Oz5E,31621
|
32
|
+
neurostats_API-0.0.23b0.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
|
33
|
+
neurostats_API-0.0.23b0.dist-info/top_level.txt,sha256=nSlQPMG0VtXivJyedp4Bkf86EOy2TpW10VGxolXrqnU,15
|
34
|
+
neurostats_API-0.0.23b0.dist-info/RECORD,,
|