From 437ca39b0224ea2096112f7893ec6ad96ba7318c Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Wed, 24 May 2023 09:58:06 +0200 Subject: [PATCH 1/2] implemented assets_debts route in backend --- backend/api/assets_debts.py | 21 +++++++++++++++++++++ stockingly.py | 6 ++++++ 2 files changed, 27 insertions(+) create mode 100644 backend/api/assets_debts.py diff --git a/backend/api/assets_debts.py b/backend/api/assets_debts.py new file mode 100644 index 0000000..c0f5598 --- /dev/null +++ b/backend/api/assets_debts.py @@ -0,0 +1,21 @@ +import pandas as pd +import numpy as np +import os + +ROOT_PATH: str = os.path.join(os.path.dirname(__file__), '..', '..') + + +def compare_balance_sheets(ticker_list: list): + df_ret = pd.DataFrame(columns=['total_assets', 'current_assets', 'total_debt', 'current_debt']) + + for i, ticker in enumerate(ticker_list): + assets_debt = pd.read_csv(ROOT_PATH + r'/Companies_Data/' + ticker + '_Data/' + ticker + '_balance_sheet_4Y+4Q.csv') + selected_data = assets_debt[['TotalAssets', 'TotalDebt', 'CurrentAssets', 'CurrentDebt']] + + df_ret.loc[ticker, 'total_assets'] = selected_data.iloc[0]['TotalAssets'] + df_ret.loc[ticker, 'current_assets'] = selected_data.iloc[0]['TotalDebt'] + df_ret.loc[ticker, 'total_debt'] = selected_data.iloc[0]['CurrentAssets'] + df_ret.loc[ticker, 'current_debt'] = selected_data.iloc[0]['CurrentDebt'] + + df_ret.index.name = 'ticker' + return df_ret.reset_index(drop=False).replace({ np.nan: None }).to_dict('records') \ No newline at end of file diff --git a/stockingly.py b/stockingly.py index 525c499..bebb8b7 100644 --- a/stockingly.py +++ b/stockingly.py @@ -4,6 +4,7 @@ from backend.utils.build_frontend import build_frontend from backend.api.companies import get_companies from backend.api.closing_price import get_closing_price_hist from backend.api.employees import get_employees +from backend.api.assets_debts import compare_balance_sheets import os import sys import subprocess @@ -40,6 +41,11 @@ def price_history(tickers: Optional[str]) -> object: return jsonify(get_closing_price_hist(tickers.split('/'))) +@app.route('/assets_debts/', methods=['GET']) +def assets_debts(tickers: Optional[str]) -> object: + return jsonify(compare_balance_sheets(tickers.split('/'))) + + @app.route('/companies/logos/') def get_company_logo(ticker: str): logo_dir: str = os.path.join(ROOT_DIR, 'scraper', 'logos', 'logos') From 37775e650db4458e7bf016a2beb5a2edb487b33d Mon Sep 17 00:00:00 2001 From: Tommaso Verzegnassi Date: Mon, 29 May 2023 10:51:16 +0200 Subject: [PATCH 2/2] Implemented assets/debts chart --- backend/api/assets_debts.py | 3 + stockingly-frontend/src/api/index.ts | 11 ++ stockingly-frontend/src/api/loader.ts | 1 - .../src/components/BalanceSheet.vue | 130 ++++++++++++++++++ .../src/components/EmployeesChart.vue | 3 +- stockingly-frontend/src/views/Comparison.vue | 12 +- 6 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 stockingly-frontend/src/components/BalanceSheet.vue diff --git a/backend/api/assets_debts.py b/backend/api/assets_debts.py index c0f5598..5e8ad44 100644 --- a/backend/api/assets_debts.py +++ b/backend/api/assets_debts.py @@ -17,5 +17,8 @@ def compare_balance_sheets(ticker_list: list): df_ret.loc[ticker, 'total_debt'] = selected_data.iloc[0]['CurrentAssets'] df_ret.loc[ticker, 'current_debt'] = selected_data.iloc[0]['CurrentDebt'] + df_ret.loc[:, 'old_assets'] = df_ret['total_assets'].copy() - df_ret['current_assets'].copy() + df_ret.loc[:, 'old_debt'] = df_ret['total_debt'].copy() - df_ret['current_debt'].copy() + df_ret.index.name = 'ticker' return df_ret.reset_index(drop=False).replace({ np.nan: None }).to_dict('records') \ No newline at end of file diff --git a/stockingly-frontend/src/api/index.ts b/stockingly-frontend/src/api/index.ts index 520f861..146e14a 100644 --- a/stockingly-frontend/src/api/index.ts +++ b/stockingly-frontend/src/api/index.ts @@ -30,6 +30,14 @@ export interface PriceHistory { [ticker: string]: string | number; // really just number } +export interface BalanceSheet { + ticker: string; + current_assets: number; + current_debt: number; + total_assets: number; + total_debt: number; +} + export const getCompanies = (tickers?: string[]): Promise => fetch(BACKEND_URL + '/companies' + (tickers ? ('/' + tickers.join('/')) : '')) .then(r => r.json()) @@ -43,3 +51,6 @@ export const getEmployees = (tickers: string[]): Promise => export const getPriceHistory = (tickers: string[]): Promise => fetch(BACKEND_URL + '/price_history/' + tickers.join('/').toUpperCase()).then(r => r.json()) + +export const getBalanceSheet = (tickers: string[]): Promise => + fetch(BACKEND_URL + '/assets_debts/' + tickers.join('/')).then(r=>r.json()) diff --git a/stockingly-frontend/src/api/loader.ts b/stockingly-frontend/src/api/loader.ts index fbd421c..0dd90e7 100644 --- a/stockingly-frontend/src/api/loader.ts +++ b/stockingly-frontend/src/api/loader.ts @@ -12,6 +12,5 @@ export const defineLoader = (apiCall: () => Promise) => re alert('Error loading data'); // don't do this for the final product } this.loading = false; - console.log(this.data, this.loading); } }) \ No newline at end of file diff --git a/stockingly-frontend/src/components/BalanceSheet.vue b/stockingly-frontend/src/components/BalanceSheet.vue new file mode 100644 index 0000000..a010211 --- /dev/null +++ b/stockingly-frontend/src/components/BalanceSheet.vue @@ -0,0 +1,130 @@ + + + \ No newline at end of file diff --git a/stockingly-frontend/src/components/EmployeesChart.vue b/stockingly-frontend/src/components/EmployeesChart.vue index a8713ab..88d1225 100644 --- a/stockingly-frontend/src/components/EmployeesChart.vue +++ b/stockingly-frontend/src/components/EmployeesChart.vue @@ -3,7 +3,7 @@ - Stock price over time + Employees over time @@ -85,7 +85,6 @@ const options = computed(() => { }); onMounted(() => { - console.log(JSON.parse(JSON.stringify(props))); employees.load(); }); \ No newline at end of file diff --git a/stockingly-frontend/src/views/Comparison.vue b/stockingly-frontend/src/views/Comparison.vue index 48dda4a..425802a 100644 --- a/stockingly-frontend/src/views/Comparison.vue +++ b/stockingly-frontend/src/views/Comparison.vue @@ -46,7 +46,10 @@ - + + + + @@ -62,6 +65,10 @@ width: 100%; height: 30em !important; } + +.v-row { + width: 100% !important; +}