Skip to content

Commit

Permalink
v2.04 - Moved to TA-Lib-Precompiled (0.4.25), Progressbar for GUI
Browse files Browse the repository at this point in the history
- TA-Lib-Precompiled added instead of building from source for faster docker builds
- TA-Lib-Precompiled(v0.4.25) now replaces TA-Lib installation using source for test and build workflows, test workflow moved to ubuntu runner
- test runner downgraded to ubuntu-20.04
- OTA checking cached for every 1h to eliminate Github API quota
- progressbar added to GUI, counter shared from env vars
- progressbar errors handled
  • Loading branch information
pranjal-joshi committed Oct 6, 2023
1 parent fd9eb77 commit 45ace34
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/workflow-build-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ on:
jobs:

# Job for builing packages
Build-Executables:
name: Build Packages (Disabled onwards v2.03)
Build-Executables-(Disabled onwards v2.03):
name: Build Packages
#needs: Create-Release
runs-on: ${{ matrix.os }}
strategy:
Expand Down
17 changes: 1 addition & 16 deletions .github/workflows/workflow-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
# Test the source-code
Test-Source:

runs-on: windows-latest
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4
Expand All @@ -35,25 +35,10 @@ jobs:
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies for TA-Lib
run: |
python -m pip install --upgrade pip
cd .github/dependencies/
echo %cd%
pip install TA_Lib-0.4.19-cp39-cp39-win_amd64.whl
# - name: Install Numpy-MKL for Windows
# run: |
# echo Downloading Numpy-MKL (212MB), Please wait!
# powershell.exe -Command (new-object System.Net.WebClient).DownloadFile('https://download.lfd.uci.edu/pythonlibs/w4tscw6k/numpy-1.20.2+mkl-cp39-cp39-win_amd64.whl','numpy-1.20.2+mkl-cp39-cp39-win_amd64.whl')
# pip install numpy-1.20.2+mkl-cp39-cp39-win_amd64.whl

- name: Install dependencies using pip
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-mock
pip install numpy==1.21.0
pip install ta-lib
pip install -r requirements.txt
- name: Lint with flake8
Expand Down
15 changes: 8 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ WORKDIR /opt/program

RUN chmod +x *

WORKDIR /opt/program/.github/dependencies/
RUN tar -xzf ta-lib-0.4.0-src.tar.gz
# Removed build ta-lib from source as we're using [pip3 install TA-Lib-Precompiled] for faster docker build

WORKDIR /opt/program/.github/dependencies/ta-lib/
RUN ./configure --prefix=/usr --build=$(uname -m)-unknown-linux-gnu
RUN make
RUN make install
# WORKDIR /opt/program/.github/dependencies/
# RUN tar -xzf ta-lib-0.4.0-src.tar.gz

# WORKDIR /opt/program/.github/dependencies/ta-lib/
# RUN ./configure --prefix=/usr --build=$(uname -m)-unknown-linux-gnu
# RUN make
# RUN make install

WORKDIR /opt/program/
RUN python3 -m pip install --upgrade pip
# RUN pip3 install ta-lib==0.4.24

RUN pip3 install -r "requirements.txt"

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pytest-mock
pytoml
retrying
scipy==1.11.2
ta-lib
# ta-lib
TA-Lib-Precompiled
tabulate
yfinance==0.1.87
alive-progress==1.6.2
Expand Down
4 changes: 3 additions & 1 deletion src/screenipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ def main(testing=False, testBuild=False, downloadOnly=False, execute_inputs:list
for _ in range(multiprocessing.cpu_count()):
tasks_queue.put(None)
try:
numStocks = len(listStockCodes)
numStocks, totalStocks = len(listStockCodes), len(listStockCodes)
os.environ['SCREENIPY_TOTAL_STOCKS'] = str(totalStocks)
print(colorText.END+colorText.BOLD)
bar, spinner = Utility.tools.getProgressbarStyle()
with alive_bar(numStocks, bar=bar, spinner=spinner) as progressbar:
Expand All @@ -419,6 +420,7 @@ def main(testing=False, testBuild=False, downloadOnly=False, execute_inputs:list
saveResults = saveResults.append(
result[1], ignore_index=True)
numStocks -= 1
os.environ['SCREENIPY_SCREEN_COUNTER'] = str(int((totalStocks-numStocks)/totalStocks*100))
progressbar.text(colorText.BOLD + colorText.GREEN +
f'Found {screenResultsCounter.value} Stocks' + colorText.END)
progressbar()
Expand Down
58 changes: 48 additions & 10 deletions src/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import urllib
from time import sleep
from pathlib import Path
from threading import Thread
from time import sleep
import classes.ConfigManager as ConfigManager

st.set_page_config(layout="wide", page_title="Screeni-py", page_icon="📈")
Expand All @@ -25,7 +27,14 @@
except KeyError:
proxyServer = ""

isDevVersion, guiUpdateMessage = OTAUpdater.checkForUpdate(proxyServer, VERSION)
isDevVersion, guiUpdateMessage = None, None

@st.cache_data(ttl='1h', show_spinner=False)
def check_updates():
isDevVersion, guiUpdateMessage = OTAUpdater.checkForUpdate(proxyServer, VERSION)
return isDevVersion, guiUpdateMessage

isDevVersion, guiUpdateMessage = check_updates()

execute_inputs = []

Expand Down Expand Up @@ -64,15 +73,44 @@ def on_start_button_click():
global execute_inputs
if isDevVersion != None:
st.info(f'Received inputs (Debug only): {execute_inputs}')
with st.spinner('Screening stocks for you...'):
try:
screenipy_main(execute_inputs=execute_inputs)
except StopIteration:
pass
except requests.exceptions.RequestException as e:
st.error('Failed to reach Screeni-py server!', icon='🫤')
st.info('This issue is related with your Internet Service Provider (ISP) - Many **Jio** users faced this issue as the screeni-py data cache server appeared to be not reachable for them!\n\nPlease go through this thread carefully to resolve this error: https://github.com/pranjal-joshi/Screeni-py/issues/164', icon='ℹ️')
st.exception(e)

def dummy_call():
try:
screenipy_main(execute_inputs=execute_inputs)
except StopIteration:
pass
except requests.exceptions.RequestException:
os.environ['SCREENIPY_REQ_ERROR'] = "TRUE"

t = Thread(target=dummy_call)
t.start()

st.markdown("""
<style>
.stProgress p {
font-size: 17px;
}
</style>
""", unsafe_allow_html=True)

progress_text = "🚀 Preparing Screener, Please Wait! "
progress_bar = st.progress(0, text=progress_text)

os.environ['SCREENIPY_SCREEN_COUNTER'] = '0'
while int(os.environ.get('SCREENIPY_SCREEN_COUNTER')) < 100:
sleep(0.05)
cnt = int(os.environ.get('SCREENIPY_SCREEN_COUNTER'))
if cnt > 0:
progress_text = "🔍 Screening stocks for you... "
progress_bar.progress(cnt, text=progress_text + f"**:red[{cnt}%]** Done")
if os.environ.get('SCREENIPY_REQ_ERROR') and "TRUE" in os.environ.get('SCREENIPY_REQ_ERROR'):
st.error('Failed to reach Screeni-py server!', icon='🫤')
st.info('This issue is related with your Internet Service Provider (ISP) - Many **Jio** users faced this issue as the screeni-py data cache server appeared to be not reachable for them!\n\nTry with another ISP/Network or go through this thread carefully to resolve this error: https://github.com/pranjal-joshi/Screeni-py/issues/164', icon='ℹ️')
del os.environ['SCREENIPY_REQ_ERROR']
break

t.join()
progress_bar.empty()

def nifty_predict(col):
with col.container():
Expand Down

0 comments on commit 45ace34

Please sign in to comment.