Created
February 2, 2014 20:05
-
-
Save kain88-de/8774012 to your computer and use it in GitHub Desktop.
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
{ | |
"metadata": { | |
"name": "" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"%matplotlib inline\n", | |
"import matplotlib as mpl\n", | |
"import matplotlib.pyplot as plt\n", | |
"import numpy as np" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import ledger\n", | |
"journal = ledger.read_journal('git/all.ledger')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"for el in journal.query(''):\n", | |
" print el.account" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"for el in journal.query('Expenses'):\n", | |
" print el.account\n", | |
" print el.account.name\n", | |
" print el.account.depth\n", | |
" print el.account.parent" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"exp_accs = []\n", | |
"for el in journal.query('Expenses'):\n", | |
" if el.account.parent != 'Expenses' and el.account.name not in exp_accs:\n", | |
" exp_accs.append(el.account.name)\n", | |
"exp_accs = list(set(exp_accs))" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print exp_accs" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"exp_accs[0]" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"dates = []\n", | |
"amount = []\n", | |
"summe = 0\n", | |
"#for el in journal.query(exp_accs[0]):\n", | |
" dates.append(el.date)\n", | |
" summe += float(el.amount.number())\n", | |
" amount.append(summe)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"plt.plot_date(mpl.dates.date2num(dates),amount)\n", | |
"plt.grid()\n", | |
"plt.xlim(mpl.dates.date2num(dates[0]) - 10,\n", | |
" mpl.dates.date2num(dates[-1]) + 10)\n", | |
"plt.ylim(min(amount) - 10, max(amount) + 10);" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"spending = [ 0. for i in range(12)]\n", | |
"\n", | |
"for el in journal.query('Expenses'):\n", | |
" month = el.date.month\n", | |
" amount = float(el.amount.number())\n", | |
" spending[month - 1] += amount\n", | |
" \n", | |
"print spending" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"plt.plot(spending)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"earning = [ 0. for i in range(12)]\n", | |
"\n", | |
"for el in journal.query('Income'):\n", | |
" month = el.date.month\n", | |
" amount = -float(el.amount.number())\n", | |
" earning[month - 1] += amount\n", | |
" \n", | |
"print earning" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"plt.plot(earning)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"print sum(spending)\n", | |
"print sum(earning)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment