Change net income figure; Add table
This commit is contained in:
parent
7c75bd3c37
commit
e9a218bb88
@ -23,13 +23,24 @@ def _compute_total_balance(df: pd.DataFrame) -> pd.DataFrame:
|
||||
|
||||
|
||||
def _compute_net_income(df: pd.DataFrame) -> pd.DataFrame:
|
||||
stripped_df = pd.DataFrame({'t': df["t"], 'value': df["value"]})
|
||||
df.index = df['t']
|
||||
income_df = df.loc[df['value'] > 0]
|
||||
expenses_df = df.loc[df['value'] < 0]
|
||||
|
||||
stripped_df.index = stripped_df['t']
|
||||
gb = stripped_df.groupby(pd.Grouper(freq='M'))
|
||||
income_df = income_df.groupby(pd.Grouper(freq='M'))[
|
||||
'value'].sum().reset_index().round(decimals=2)
|
||||
expenses_df = expenses_df.groupby(pd.Grouper(freq='M'))[
|
||||
'value'].sum().reset_index().round(decimals=2)
|
||||
|
||||
result = gb["value"].sum().reset_index()
|
||||
return result
|
||||
t = income_df['t']
|
||||
income = income_df['value'].round(decimals=2)
|
||||
expenses = expenses_df['value'].round(decimals=2)
|
||||
net = (income + expenses).round(decimals=2)
|
||||
|
||||
result_df = pd.DataFrame(
|
||||
{'t': t, 'income': income, 'expenses': expenses, 'net': net})
|
||||
|
||||
return result_df
|
||||
|
||||
|
||||
def _compute_category_overview(df: pd.DataFrame) -> pd.DataFrame:
|
||||
@ -46,11 +57,12 @@ def _compute_category_overview(df: pd.DataFrame) -> pd.DataFrame:
|
||||
|
||||
category_overview_df = category_overview_df.sort_values('value',
|
||||
ascending=False)
|
||||
|
||||
return category_overview_df
|
||||
|
||||
|
||||
def _compute_expenses_by_category(complete_df: pd.DataFrame) -> pd.DataFrame:
|
||||
complete_df = complete_df.loc[complete_df['value'] < 0]
|
||||
complete_df = complete_df.loc[complete_df['value'] < 0].copy()
|
||||
complete_df['value'] = -complete_df['value']
|
||||
complete_df.index = complete_df['t']
|
||||
|
||||
|
||||
@ -38,13 +38,13 @@
|
||||
\newcommand{\slice}[6]{
|
||||
\pgfmathparse{0.5*#1+0.5*#2}
|
||||
\let\midangle\pgfmathresult
|
||||
|
||||
|
||||
% slice
|
||||
\fill[thick,color=#5] (0,0) -- (#1:1) arc (#1:#2+1:1) -- (0,0);
|
||||
|
||||
|
||||
% outer label
|
||||
\node[label=\midangle:#4] at (\midangle:1) {};
|
||||
|
||||
|
||||
% inner label
|
||||
\pgfmathparse{min((#2-#1-10)/110*(-0.3),0)}
|
||||
\let\temp\pgfmathresult
|
||||
@ -58,13 +58,13 @@
|
||||
\newcounter{pieSliceB}
|
||||
\newcommand{\pie}[1]{
|
||||
% Count elements
|
||||
\setcounter{pieElem}{0}%
|
||||
\setcounter{pieElem}{0}%
|
||||
\foreach\pieElem in {#1}{\stepcounter{pieElem}}%
|
||||
\edef\numElements{\arabic{pieElem}}
|
||||
|
||||
% Draw pie chart
|
||||
\setcounter{pieSliceA}{0}%
|
||||
\setcounter{pieSliceB}{0}%
|
||||
\setcounter{pieSliceA}{0}%
|
||||
\setcounter{pieSliceB}{0}%
|
||||
\foreach \xi/\t [count=\xk from 0] in {#1} {
|
||||
% Get colors
|
||||
\pgfmathparse{1000 / (\numElements - 1) * \xk}
|
||||
@ -81,16 +81,16 @@
|
||||
|
||||
\newcommand{\csvPie}[1]{
|
||||
% Count elements
|
||||
\setcounter{pieElem}{0}%
|
||||
\setcounter{pieElem}{0}%
|
||||
\csvreader[head to column names]{#1}{}{%
|
||||
\stepcounter{pieElem}
|
||||
}
|
||||
\edef\numElements{\arabic{pieElem}}
|
||||
|
||||
% Draw pie chart
|
||||
\setcounter{pieElem}{0}%
|
||||
\setcounter{pieSliceA}{0}%
|
||||
\setcounter{pieSliceB}{0}%
|
||||
\setcounter{pieElem}{0}%
|
||||
\setcounter{pieSliceA}{0}%
|
||||
\setcounter{pieSliceB}{0}%
|
||||
\csvreader[head to column names]{#1}{}{%
|
||||
% Get colors
|
||||
\pgfmathparse{1000 / (\numElements - 1) * \thepieElem}
|
||||
@ -157,7 +157,7 @@
|
||||
]
|
||||
% Dummy plot to set x axis ticks
|
||||
\addplot[draw=none]
|
||||
table[col sep=comma, x=t, y=value]
|
||||
table[col sep=comma, x=t, y=net]
|
||||
{net_income.csv};
|
||||
|
||||
% Dummy plot to set x axis scale
|
||||
@ -165,11 +165,17 @@
|
||||
table[col sep=comma, x=t, y expr=0]
|
||||
{detailed_balance.csv};
|
||||
|
||||
\addplot[ybar, color=scol2, fill=scol2, line width=1pt]
|
||||
table[col sep=comma, x=t, y=value, discard if lt={value}{0}]
|
||||
\addplot[ybar, bar width=0.4cm, draw=none, fill=scol2!30, line width=1pt]
|
||||
table[col sep=comma, x=t, y=income]
|
||||
{net_income.csv};
|
||||
\addplot[ybar, color=scol0, fill=scol0, line width=1pt]
|
||||
table[col sep=comma, x=t, y=value, discard if gt={value}{0}]
|
||||
\addplot[ybar, bar width=0.4cm, draw=none, fill=scol0!30, line width=1pt]
|
||||
table[col sep=comma, x=t, y=expenses]
|
||||
{net_income.csv};
|
||||
\addplot[ybar, bar width=0.3cm, draw=none, fill=scol0, line width=1pt]
|
||||
table[col sep=comma, x=t, y=net, discard if gt={net}{0}]
|
||||
{net_income.csv};
|
||||
\addplot[ybar, bar width=0.3cm, draw=none, fill=scol2, line width=1pt]
|
||||
table[col sep=comma, x=t, y=net, discard if lt={net}{0}]
|
||||
{net_income.csv};
|
||||
\end{axis}
|
||||
\end{tikzpicture}
|
||||
@ -211,6 +217,13 @@
|
||||
\caption{Development of account balance over time}
|
||||
\end{figure}
|
||||
|
||||
\begin{figure}
|
||||
\centering
|
||||
|
||||
|
||||
\csvautotabular{net_income.csv}
|
||||
\end{figure}
|
||||
|
||||
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
@ -218,7 +231,7 @@
|
||||
% Read table
|
||||
\pgfplotstableread[col sep=comma]{expenses_by_category.csv}\expbycattable
|
||||
\pgfplotstablegetcolsof{\expbycattable}
|
||||
\pgfmathtruncatemacro\NumCols{\pgfplotsretval-1}
|
||||
\pgfmathtruncatemacro\NumCols{\pgfplotsretval-1}
|
||||
|
||||
\begin{subfigure}[c]{\textwidth}
|
||||
\centering
|
||||
|
||||
Loading…
Reference in New Issue
Block a user