-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d04f535
commit 549feaa
Showing
2 changed files
with
34 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
from typing import List | ||
|
||
from stocklake.core.base_preprocessor import BasePreprocessor | ||
from stocklake.nasdaqapi.entities import RawNasdaqApiSymbolData | ||
from stocklake.nasdaqapi.entities import NasdaqApiSymbolData, RawNasdaqApiSymbolData | ||
|
||
|
||
class NASDAQSymbolsPreprocessor(BasePreprocessor): | ||
def process( | ||
self, data: List[RawNasdaqApiSymbolData] | ||
) -> List[RawNasdaqApiSymbolData]: | ||
return data | ||
def process(self, data: List[RawNasdaqApiSymbolData]) -> List[NasdaqApiSymbolData]: | ||
processed_data: List[NasdaqApiSymbolData] = [] | ||
for data_dic in data: | ||
_data: NasdaqApiSymbolData = { | ||
"symbol": data_dic["symbol"], | ||
"name": data_dic["name"], | ||
"lastsale": float( | ||
data_dic["lastsale"].replace("$", "").replace(",", "") | ||
), | ||
"netchange": float(data_dic["netchange"]), | ||
"pctchange": float(data_dic["pctchange"].replace("%", "")), | ||
"marketCap": float(data_dic["marketCap"].replace(",", "")), | ||
"url": data_dic["url"], | ||
} | ||
processed_data.append(_data) | ||
return processed_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import json | ||
|
||
from stocklake.nasdaqapi.preprocessor import NASDAQSymbolsPreprocessor | ||
|
||
with open("./tests/nasdaqapi/sample_response.json") as f: | ||
mock_raw_data = json.load(f)["data"]["rows"] | ||
|
||
|
||
def test_process(): | ||
preprocessor = NASDAQSymbolsPreprocessor() | ||
data = preprocessor.process(mock_raw_data) | ||
for data_dic in data: | ||
for key, val in data_dic.items(): | ||
if key in ["lastsale", "netchange", "pctchange", "marketCap"]: | ||
assert isinstance(val, float) | ||
else: | ||
assert isinstance(val, str) |