Browse Source

feat(stock-market): update mock-stock-data-server

- change port to avoid conflicts with defaults on macos
- update .gitignore to exclude expanded stock data
- remove repeated if statement in utils.py
- remove comments
pull/2132/head
nprimo 1 year ago committed by Niccolò Primo
parent
commit
73a9b4660a
  1. 2
      subjects/mobile-dev/stock-market/resources/mock-stock-data-server/.gitignore
  2. 4
      subjects/mobile-dev/stock-market/resources/mock-stock-data-server/Makefile
  3. 6
      subjects/mobile-dev/stock-market/resources/mock-stock-data-server/README.md
  4. 4
      subjects/mobile-dev/stock-market/resources/mock-stock-data-server/app.py
  5. 15
      subjects/mobile-dev/stock-market/resources/mock-stock-data-server/utils.py

2
subjects/mobile-dev/stock-market/resources/mock-stock-data-server/.gitignore diff.vendored

@ -158,3 +158,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear # and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/ #.idea/
sample-stocks/

4
subjects/mobile-dev/stock-market/resources/mock-stock-data-server/Makefile

@ -1,6 +1,6 @@
IMAGE_NAME="stock-server" IMAGE_NAME="stock-server"
SERVER_PORT=5000 SERVER_PORT=5001
PUBLIC_PORT=5000 PUBLIC_PORT=5001
sample-stocks: sample-stocks:
tar xf sample-stocks.zip tar xf sample-stocks.zip

6
subjects/mobile-dev/stock-market/resources/mock-stock-data-server/README.md

@ -31,7 +31,7 @@ Below an example on how to use it (remember that the server needs to be running
locally). locally).
```shell ```shell
$ curl -s localhost:5000/stocks_list | jq | head $ curl -s localhost:5001/stocks_list | jq | head
[ [
"BRID", "BRID",
"WRB", "WRB",
@ -42,9 +42,9 @@ $ curl -s localhost:5000/stocks_list | jq | head
"UMBF", "UMBF",
"MTRN", "MTRN",
"UNT", "UNT",
$ curl localhost:5000/exchange_rate/WRB $ curl localhost:5001/exchange_rate/WRB
{"rate":0.12680993974208832,"symbol":"USD","timestamp":1691667858.912409} {"rate":0.12680993974208832,"symbol":"USD","timestamp":1691667858.912409}
$ curl localhost:5000/exchange_rate/BRID $ curl localhost:5001/exchange_rate/BRID
{"rate":0.38091352581977844,"symbol":"USD","timestamp":1691667862.3328483} {"rate":0.38091352581977844,"symbol":"USD","timestamp":1691667862.3328483}
$ $
``` ```

4
subjects/mobile-dev/stock-market/resources/mock-stock-data-server/app.py

@ -9,7 +9,7 @@ CORS(app)
start_time = time.time() start_time = time.time()
historical_data = load_historical_data() # Dictionary to store historical data historical_data = load_historical_data()
@app.route('/exchange_rate/<symbol>') @app.route('/exchange_rate/<symbol>')
def get_stock_data(symbol): def get_stock_data(symbol):
@ -32,4 +32,4 @@ def list_symbols():
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000) app.run(host='0.0.0.0', port=5001)

15
subjects/mobile-dev/stock-market/resources/mock-stock-data-server/utils.py

@ -7,14 +7,13 @@ def load_historical_data(directory_path='./sample-stocks/'):
file_list = [filename for filename in os.listdir(directory_path) if filename.endswith(".csv")] file_list = [filename for filename in os.listdir(directory_path) if filename.endswith(".csv")]
for filename in file_list: for filename in file_list:
if filename.endswith(".csv"): symbol = filename.replace(".csv", "")
symbol = filename.replace(".csv", "")
historical_data[symbol] = {}
historical_data[symbol] = {} file_path = os.path.join(directory_path, filename)
file_path = os.path.join(directory_path, filename) with open(file_path, 'r') as csv_file:
with open(file_path, 'r') as csv_file: csv_reader = csv.DictReader(csv_file)
csv_reader = csv.DictReader(csv_file) historical_data[symbol] = [row['Close'] for row in csv_reader]
historical_data[symbol] = [row['Close'] for row in csv_reader]
return historical_data return historical_data

Loading…
Cancel
Save