-
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.
Merge branch 'streamlit' into develop
- Loading branch information
Showing
29 changed files
with
713 additions
and
139 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "Python 3", | ||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile | ||
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye", | ||
"customizations": { | ||
"codespaces": { | ||
"openFiles": [ | ||
"README.md", | ||
"streamlit_app.py" | ||
] | ||
}, | ||
"vscode": { | ||
"settings": {}, | ||
"extensions": [ | ||
"ms-python.python", | ||
"ms-python.vscode-pylance" | ||
] | ||
} | ||
}, | ||
"updateContentCommand": "[ -f packages.txt ] && sudo apt update && sudo apt upgrade -y && sudo xargs apt install -y <packages.txt; [ -f requirements.txt ] && pip3 install --user -r requirements.txt; pip3 install --user streamlit; echo '✅ Packages installed and Requirements met'", | ||
"postAttachCommand": { | ||
"server": "streamlit run streamlit_app.py --server.enableCORS false --server.enableXsrfProtection false" | ||
}, | ||
"portsAttributes": { | ||
"8501": { | ||
"label": "Application", | ||
"onAutoForward": "openPreview" | ||
} | ||
}, | ||
"forwardPorts": [ | ||
8501 | ||
] | ||
} |
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
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
|
||
# Personal files | ||
parameters.py | ||
*.dump | ||
|
||
# Python runtime | ||
*.pyc | ||
|
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
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,9 @@ | ||
FROM postgres | ||
|
||
# Install dependencies | ||
RUN apt-get update | ||
RUN apt-get install -y nfs-common | ||
RUN apt-get install rpcbind | ||
|
||
# Copy the shell script into the image | ||
COPY db_init.sh /docker-entrypoint-initdb.d/init-user-db.sh |
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,7 @@ | ||
#!/bin/bash | ||
|
||
# Creates an empty stocks database | ||
psql -U postgres -c "CREATE DATABASE stocks;" | ||
|
||
# Restore the data into the stocks database | ||
pg_restore -U postgres -d stocks /nfs/db.dump |
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,64 @@ | ||
version: '3' | ||
|
||
# Microservices | ||
services: | ||
# Postgresql database container | ||
db: | ||
build: ./db_dir | ||
container_name: stocks-postgres | ||
privileged: true | ||
ports: | ||
- 5433:5432 | ||
environment: | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=123456 | ||
volumes: | ||
- nfs-volume:/nfs | ||
networks: | ||
- stocks-network | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready -h stocks-postgres -U postgres -p 5432 | grep 'accepting connections'"] | ||
interval: 5s | ||
timeout: 5s | ||
retries: 5 | ||
|
||
# Core container | ||
core: | ||
build: ./src | ||
container_name: core-modules | ||
ports: | ||
- 5000:5000 | ||
volumes: | ||
- ./src:/usr/workspace | ||
networks: | ||
- stocks-network | ||
depends_on: | ||
db: | ||
condition: service_healthy | ||
|
||
# Streamlit app container | ||
web: | ||
build: ./streamlit | ||
container_name: streamlit-container | ||
ports: | ||
- 8501:8501 | ||
volumes: | ||
- ./streamlit:/app | ||
networks: | ||
- stocks-network | ||
depends_on: | ||
- core | ||
|
||
# Volume for NFS | ||
volumes: | ||
nfs-volume: | ||
driver: local | ||
driver_opts: | ||
type: "nfs" | ||
o: "addr=${HOST_IP},nolock,soft,rw,nfsvers=4" | ||
device: ":${PWD}/network_directory" | ||
|
||
# Shared network for microservices | ||
networks: | ||
stocks-network: | ||
name: stocks-network |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,15 +1,57 @@ | ||
This part of the project documentation focuses on an | ||
**understanding-oriented** approach. You'll get a | ||
chance to read about the background of the project, | ||
as well as reasoning about how it was implemented. | ||
|
||
> **Note:** Expand this section by considering the | ||
> following points: | ||
- Give context and background on your library | ||
- Explain why you created it | ||
- Provide multiple examples and approaches of how | ||
to work with it | ||
- Help the reader make connections | ||
- Avoid writing instructions or technical descriptions | ||
here | ||
# StockTracker | ||
## Compatibility | ||
|
||
This project has been tested on: | ||
|
||
- WSL 2 on Windows running Ubuntu 22.04 | ||
- Ubuntu 22.04 | ||
|
||
## Motivation | ||
|
||
The motivation behind this project is to improve the developer's financial literacy and learn software engineering best practices. | ||
|
||
## Project Structure | ||
|
||
The main components of this project are: | ||
|
||
- *Web app*: Built using Python Streamlit | ||
- *Business logic*: Implemented using Python and Flask | ||
- *Database*: PostgreSQL | ||
|
||
## Technologies Used | ||
|
||
- Python 3.10 | ||
- Flask | ||
- Plotly | ||
- Pandas | ||
- psycopg2-binary | ||
- Streamlit | ||
- yfinance | ||
- PostgreSQL | ||
|
||
## User Interface | ||
|
||
### User Interface | ||
![alt text](./assets/user-interface-diagram.png) | ||
|
||
The image above illustrates what a user would see if the project is set up successfully. | ||
|
||
## Architecture | ||
|
||
### Architecture Diagram | ||
|
||
![alt text](./assets/architecture-diagram.png) | ||
|
||
The idea behind the project is to split each microservice into respective containers: | ||
|
||
- Web app container | ||
- Business logic container | ||
- Database container | ||
|
||
An ***NFS server*** is set up to allow sharing of PostgreSQL backup files (*.dump*) with the PostgreSQL ***database container***, which acts as the *NFS client*. Any user interactions with the ***web app container*** will send requests via *RESTful API* to the ***business logic container***, which in turn sends the requests to the ***database container*** via the *database connection*. | ||
|
||
## Demo | ||
|
||
A version of the web app that contains part of the database has been deployed. Feel free to give that a go. | ||
|
||
[Demo link](https://wleong1-stocktracker.streamlit.app/) |
Oops, something went wrong.