From 709440c1dd0dc35948a04321f897544d4feb2b47 Mon Sep 17 00:00:00 2001 From: Pietro Rodolfo Masera Date: Wed, 24 May 2023 11:56:28 +0200 Subject: [PATCH] Employees graph done --- backend/api/employees.py | 21 +++++ stockingly-frontend/src/api/index.ts | 10 +- .../src/components/CompanyCard.vue | 7 +- .../src/components/EmployeesChart.vue | 91 +++++++++++++++++++ stockingly-frontend/src/views/Comparison.vue | 11 ++- stockingly.py | 6 ++ 6 files changed, 137 insertions(+), 9 deletions(-) create mode 100644 backend/api/employees.py create mode 100644 stockingly-frontend/src/components/EmployeesChart.vue diff --git a/backend/api/employees.py b/backend/api/employees.py new file mode 100644 index 0000000..56304d8 --- /dev/null +++ b/backend/api/employees.py @@ -0,0 +1,21 @@ +import os +import pandas as pd +import numpy as np + +ROOT_PATH: str = os.path.join(os.path.dirname(__file__), '..', '..') + + +def get_employees(tickers: list[str]) -> list[dict]: + employees_df = pd.read_csv(ROOT_PATH + '/Elaborated_Data/employees_over_time.csv', index_col=[0]) + + s_tickers = pd.Series(tickers) + employees_df = employees_df.loc[employees_df['Ticker'].isin(s_tickers), :] + + dates = [str(date) + '-01-01' for date in range(2012, 2023 + 1)] + + for i, date in enumerate(dates): + employees_df[date] = employees_df['Employees_over_time'].copy().apply(lambda x: int(eval(str(x))[i])) + + employees_df = pd.melt(employees_df, id_vars=['Ticker'], value_vars=dates, var_name='year').reset_index(drop=True) + employees_df = employees_df.pivot(index='year', columns='Ticker', values='value').reset_index(drop=False) + return employees_df.replace({ np.nan: None }).to_dict('records') diff --git a/stockingly-frontend/src/api/index.ts b/stockingly-frontend/src/api/index.ts index 4ede11c..520f861 100644 --- a/stockingly-frontend/src/api/index.ts +++ b/stockingly-frontend/src/api/index.ts @@ -20,6 +20,11 @@ export interface Company { 'Past Performance': number; } +export interface EmployeeCount { + year: string; + [ticker: string]: string | number; // really just number +} + export interface PriceHistory { date: string; [ticker: string]: string | number; // really just number @@ -33,5 +38,8 @@ export const getCompanies = (tickers?: string[]): Promise => logoSrc: `${BACKEND_URL}/companies/logos/${e.ticker}` }))); +export const getEmployees = (tickers: string[]): Promise => + fetch(BACKEND_URL + '/employees/' + tickers.join('/').toUpperCase()).then(r => r.json()) + export const getPriceHistory = (tickers: string[]): Promise => - fetch(BACKEND_URL + '/price_history/' + tickers.join('/').toUpperCase()).then(r => r.json()) \ No newline at end of file + fetch(BACKEND_URL + '/price_history/' + tickers.join('/').toUpperCase()).then(r => r.json()) diff --git a/stockingly-frontend/src/components/CompanyCard.vue b/stockingly-frontend/src/components/CompanyCard.vue index 4dac3bf..1510fc7 100644 --- a/stockingly-frontend/src/components/CompanyCard.vue +++ b/stockingly-frontend/src/components/CompanyCard.vue @@ -15,9 +15,6 @@ -

- {{ company.description }} -

{{ m.title }} @@ -120,7 +117,6 @@ const metricsData = reactive([ minValue: 0, maxValue: 200, value: c => c['Estimated Growth'], - symbol: ' %', scale: [ { gt: 8, color: COLORS.good }, { gt: 0, color: COLORS.warning }, @@ -132,7 +128,6 @@ const metricsData = reactive([ minValue: -100, maxValue: 200, value: c => c['Past Performance'], - symbol: ' %', scale: [ { gt: 5, color: COLORS.good }, { gt: -5, color: COLORS.warning }, @@ -149,7 +144,7 @@ type ExtendedMetric = Metric & { const metrics = computed(() => metricsData.map(e => ({ ...e, percentage: (c: Company) => (e.value(c) - e.minValue) * 100 / (e.maxValue - e.minValue), - value: (c: Company) => roundTo(e.value(c), e.decimals ?? 2), + value: (c: Company) => roundTo(e.value(c), e.decimals ?? 0), color: (c: Company) => { const value = e.value(c); for (const s of e.scale) { diff --git a/stockingly-frontend/src/components/EmployeesChart.vue b/stockingly-frontend/src/components/EmployeesChart.vue new file mode 100644 index 0000000..a8713ab --- /dev/null +++ b/stockingly-frontend/src/components/EmployeesChart.vue @@ -0,0 +1,91 @@ + + + \ No newline at end of file diff --git a/stockingly-frontend/src/views/Comparison.vue b/stockingly-frontend/src/views/Comparison.vue index 779763d..48dda4a 100644 --- a/stockingly-frontend/src/views/Comparison.vue +++ b/stockingly-frontend/src/views/Comparison.vue @@ -44,6 +44,11 @@ + + + + + @@ -62,7 +67,7 @@