From 208e22943eee261a37208cf39891ab015655710b Mon Sep 17 00:00:00 2001 From: Sarey Hamarneh Date: Tue, 18 Apr 2017 17:22:35 -0400 Subject: [PATCH 1/6] Add cash balance file --- .../rough draft-checkpoint.ipynb | 172 +++++++++++ bpengine | 1 + bpfin/financials/cash_Balanace.py | 22 ++ rough draft.ipynb | 267 ++++++++++++++++++ 4 files changed, 462 insertions(+) create mode 100644 .ipynb_checkpoints/rough draft-checkpoint.ipynb create mode 160000 bpengine create mode 100644 bpfin/financials/cash_Balanace.py create mode 100644 rough draft.ipynb diff --git a/.ipynb_checkpoints/rough draft-checkpoint.ipynb b/.ipynb_checkpoints/rough draft-checkpoint.ipynb new file mode 100644 index 0000000..3353fe1 --- /dev/null +++ b/.ipynb_checkpoints/rough draft-checkpoint.ipynb @@ -0,0 +1,172 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 66, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "from datetime import date\n", + "import numpy as np\n", + "import statsmodels.api as sm\n", + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def daily_average_use_or_charge(from_date, to_date, total_utility_use_or_charge):\n", + " fromdate = []\n", + " todate = []\n", + " for date in from_date:\n", + " fromdate.append(date)\n", + " for date in to_date:\n", + " todate.append(date)\n", + " interstore = [list(x) for x in zip(fromdate, todate)]\n", + " finalstore = []\n", + " for value in interstore:\n", + " difference = (value[1] - value[0])\n", + " finalstore.append(difference.days)\n", + "\n", + " bill_daily_average = [x / y for x, y in zip(total_utility_use_or_charge, finalstore)]\n", + " perbill_useorcharge = []\n", + " for number in bill_daily_average:\n", + " perbill_useorcharge.append(number)\n", + " return perbill_useorcharge" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "input_from_date = [date(1995, 10, 1), date(1996, 11, 1), date(1997, 12, 1)]\n", + "input_to_date = [date(1996, 10, 1), date(1997, 11, 1), date(1998, 12, 1)]\n", + "input_total_utility_use_or_charge = [10, 10, 10]" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[0.0273224043715847, 0.0273972602739726, 0.0273972602739726]" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "daily_average_use_or_charge(input_from_date, input_to_date, input_total_utility_use_or_charge)" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def regression_coefficients(x_list, y_list, is_intercept):\n", + "# \"\"\"Regress two lists of values.\n", + "\n", + "# Args:\n", + "# x_list: list of base x values for regression\n", + "# y_list: list of base y values for regression\n", + "# is_intercept (boolean): it is true that we want an intercept value in our regression\n", + "# Returns:\n", + "# tuple: x and y coefficients from regression\n", + "# \"\"\"\n", + " x_values = x_list\n", + " y_values = y_list\n", + " if is_intercept is True:\n", + " x_values = sm.add_constant(x_values)\n", + " model = sm.OLS(y_values, x_values)\n", + " results = model.fit()\n", + " coefficients = results.params\n", + " return coefficients" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([ -3.77475828e-15, 2.00000000e+00])" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "regression_coefficients([15,30,45],[30,60,90],True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "best = {date(2010,10,1):(1000,True),date()}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/bpengine b/bpengine new file mode 160000 index 0000000..070ded0 --- /dev/null +++ b/bpengine @@ -0,0 +1 @@ +Subproject commit 070ded05633b0d51e1cb71f141e7c0f5ff6e3268 diff --git a/bpfin/financials/cash_Balanace.py b/bpfin/financials/cash_Balanace.py new file mode 100644 index 0000000..b82a7e7 --- /dev/null +++ b/bpfin/financials/cash_Balanace.py @@ -0,0 +1,22 @@ + + +def cash_balance(cash_dictionary): + + cash_balance_dictionary = {} + + bank_statement = {} + + for date,value_tuple in dictionary.items(): + if value_tuple[1] is True: + cash_balance_dictionary[date.year] = value_tuple[0] + else: + #check if year (key) not is present in bank_statement + if date.year not in bank_statement: + bank_statement[date.year] = [] + bank_statement[date.year].append(value_tuple[0]) + + for year, value in bank_statement.items(): + if year not in cash_balance_dictionary: + cash_balance_dictionary[year] = sum(value)/len(value) + + return cash_balance_dictionary diff --git a/rough draft.ipynb b/rough draft.ipynb new file mode 100644 index 0000000..41e6a60 --- /dev/null +++ b/rough draft.ipynb @@ -0,0 +1,267 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 66, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "from datetime import date\n", + "import numpy as np\n", + "import statsmodels.api as sm\n", + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def daily_average_use_or_charge(from_date, to_date, total_utility_use_or_charge):\n", + " fromdate = []\n", + " todate = []\n", + " for date in from_date:\n", + " fromdate.append(date)\n", + " for date in to_date:\n", + " todate.append(date)\n", + " interstore = [list(x) for x in zip(fromdate, todate)]\n", + " finalstore = []\n", + " for value in interstore:\n", + " difference = (value[1] - value[0])\n", + " finalstore.append(difference.days)\n", + "\n", + " bill_daily_average = [x / y for x, y in zip(total_utility_use_or_charge, finalstore)]\n", + " perbill_useorcharge = []\n", + " for number in bill_daily_average:\n", + " perbill_useorcharge.append(number)\n", + " return perbill_useorcharge" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "input_from_date = [date(1995, 10, 1), date(1996, 11, 1), date(1997, 12, 1)]\n", + "input_to_date = [date(1996, 10, 1), date(1997, 11, 1), date(1998, 12, 1)]\n", + "input_total_utility_use_or_charge = [10, 10, 10]" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[0.0273224043715847, 0.0273972602739726, 0.0273972602739726]" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "daily_average_use_or_charge(input_from_date, input_to_date, input_total_utility_use_or_charge)" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def regression_coefficients(x_list, y_list, is_intercept):\n", + "# \"\"\"Regress two lists of values.\n", + "\n", + "# Args:\n", + "# x_list: list of base x values for regression\n", + "# y_list: list of base y values for regression\n", + "# is_intercept (boolean): it is true that we want an intercept value in our regression\n", + "# Returns:\n", + "# tuple: x and y coefficients from regression\n", + "# \"\"\"\n", + " x_values = x_list\n", + " y_values = y_list\n", + " if is_intercept is True:\n", + " x_values = sm.add_constant(x_values)\n", + " model = sm.OLS(y_values, x_values)\n", + " results = model.fit()\n", + " coefficients = results.params\n", + " return coefficients" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([ -3.77475828e-15, 2.00000000e+00])" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "regression_coefficients([15,30,45],[30,60,90],True)" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (, line 1)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m best = {(date(2011,10,1):(1000,False)),(date(2012,12,31):(600,True)),(date(2012,6,15):(820,False)),(date(2012,1,30):(740:False))}\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" + ] + } + ], + "source": [ + "best = {(date(2011,10,1):(1000,False)),(date(2012,12,31):(600,True)),(date(2012,6,15):(820,False)),(date(2012,1,30):(740:False))}" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "best = {date(2011,10,1):(1000,False),date(2012,12,31):(600,True),date(2012,6,15):(820,False)}" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def cash_balance(dict_need):\n", + "\n", + " day = []\n", + " month = []\n", + " year = []\n", + " \n", + " for i in dict_need:\n", + " day.append(i.day)\n", + " month.append(i.month)\n", + " year.append(i.year)\n", + " \n", + " keys = [(x, y, z) for x, y, z in zip(year, month, day)]\n", + " \n", + " \n", + " \n", + "# for one,two in dict_need:\n", + "# if two[1] is True:\n", + "# return friend" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "cash_balance(best)" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "ename": "ValueError", + "evalue": "too many values to unpack (expected 2)", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mdict_need\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m'hey'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m23\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mtwo\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdict_need\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtwo\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m\"hello\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mValueError\u001b[0m: too many values to unpack (expected 2)" + ] + } + ], + "source": [ + "dict_need = {'hey':(23,True)}\n", + "\n", + "for one,two in dict_need:\n", + " if two[1] is True:\n", + " print (\"hello\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} -- GitLab From d5ba12782dd637db557b34e8abb45ca343cbaa28 Mon Sep 17 00:00:00 2001 From: Sarey Hamarneh Date: Tue, 18 Apr 2017 17:44:31 -0400 Subject: [PATCH 2/6] Merge remote-tracking branch 'origin/master' into cash-balance Merging with new change. --- bpfin/tests/test_utilbills/test_bill_lib.py | 8 +- .../test_month_normalize_rough.py | 84 ++++++++++-------- bpfin/utilbills/bill_month_normalize_rough.py | 87 +++++++------------ 3 files changed, 81 insertions(+), 98 deletions(-) diff --git a/bpfin/tests/test_utilbills/test_bill_lib.py b/bpfin/tests/test_utilbills/test_bill_lib.py index a5c6aec..46a379e 100644 --- a/bpfin/tests/test_utilbills/test_bill_lib.py +++ b/bpfin/tests/test_utilbills/test_bill_lib.py @@ -1,12 +1,12 @@ -from bpfin.utilbills.0bill_lib import add_list +from bpfin.utilbills.bill_lib import add_list def test_add_list(): - input = [1, 2] + input_list = [1, 2] output = [3, 4] - result = add_list(input, 2) + result = add_list(input_list, 2) - for i in result: + for i in range(len(result)): assert result[i] == output[i] diff --git a/bpfin/tests/test_utilbills/test_month_normalize_rough.py b/bpfin/tests/test_utilbills/test_month_normalize_rough.py index 63d7ee1..6cb619c 100644 --- a/bpfin/tests/test_utilbills/test_month_normalize_rough.py +++ b/bpfin/tests/test_utilbills/test_month_normalize_rough.py @@ -1,39 +1,51 @@ -import bpfin.utilbills.bill_month_normalize_rough as ub +from bpfin.utilbills.bill_month_normalize_rough import bill_month_normalize_rough import datetime -test_raw_bill = {} - -test_raw_bill['date_from'] = [ - datetime.date(2014, 4, 17), datetime.date(2014, 5, 16), datetime.date(2014, 6, 17), - datetime.date(2014, 7, 17), datetime.date(2014, 8, 15), datetime.date(2014, 9, 16), - datetime.date(2014, 10, 16), datetime.date(2014, 11, 14), datetime.date(2014, 12, 17), - datetime.date(2015, 1, 16), datetime.date(2015, 2, 18), datetime.date(2015, 3, 19), - datetime.date(2015, 4, 17), datetime.date(2015, 5, 18), datetime.date(2015, 6, 17), - datetime.date(2015, 7, 17), datetime.date(2015, 8, 17), datetime.date(2015, 9, 16), - datetime.date(2015, 10, 16), datetime.date(2015, 11, 16), datetime.date(2015, 12, 17), - datetime.date(2016, 1, 19), datetime.date(2016, 2, 18), datetime.date(2016, 3, 18)] - -test_raw_bill['date_to'] = [ - datetime.date(2014, 5, 16), datetime.date(2014, 6, 17), datetime.date(2014, 7, 17), - datetime.date(2014, 8, 15), datetime.date(2014, 9, 16), datetime.date(2014, 10, 16), - datetime.date(2014, 11, 14), datetime.date(2014, 12, 17), datetime.date(2015, 1, 16), - datetime.date(2015, 2, 18), datetime.date(2015, 3, 19), datetime.date(2015, 4, 17), - datetime.date(2015, 5, 18), datetime.date(2015, 6, 17), datetime.date(2015, 7, 17), - datetime.date(2015, 8, 17), datetime.date(2015, 9, 16), datetime.date(2015, 10, 16), - datetime.date(2015, 11, 16), datetime.date(2015, 12, 17), datetime.date(2016, 1, 19), - datetime.date(2016, 2, 18), datetime.date(2016, 3, 18), datetime.date(2016, 4, 18)] - -test_raw_bill['charge'] = [ - 2601.6289696969693, 2642.1740261508003, 3437.551946607342, 2930.5070588449826, - 2514.1242835094554, 2804.4448749999997, 3237.7359972191325, 3289.4155027808674, - 2796.5700000000002, 2463.5113047830923, 2370.0007392051775, 2479.081440860215] - -test_raw_bill['usage'] = [ - 0.094265231101663627, 0.10175446346513953, 0.12248981352003527, 0.11229655777596657, - 0.092170964664193167, 0.094173672324921492, 0.095187070309577237, 0.097177529967719486, - 0.095676831493476874, 0.091583582602530869, 0.089122740090923164, 0.091516956021057888] - -test_raw_bill['utility_type'] = 'electricity' - -print(ub.bill_month_normalize_rough(test_raw_bill)) +def test_month_normalization_rough(): + test_raw_bill = {} + test_raw_bill['utility_type'] = 'electricity' + test_raw_bill['date_from'] = [ + datetime.date(2014, 4, 17), datetime.date(2014, 5, 16), datetime.date(2014, 6, 17), + datetime.date(2014, 7, 17), datetime.date(2014, 8, 15), datetime.date(2014, 9, 16), + datetime.date(2014, 10, 16), datetime.date(2014, 11, 14), datetime.date(2014, 12, 17), + datetime.date(2015, 1, 16), datetime.date(2015, 2, 18), datetime.date(2015, 3, 19), + datetime.date(2015, 4, 17), datetime.date(2015, 5, 18), datetime.date(2015, 6, 17), + datetime.date(2015, 7, 17), datetime.date(2015, 8, 17), datetime.date(2015, 9, 16), + datetime.date(2015, 10, 16), datetime.date(2015, 11, 16), datetime.date(2015, 12, 17), + datetime.date(2016, 1, 19), datetime.date(2016, 2, 18), datetime.date(2016, 3, 18)] + test_raw_bill['date_to'] = [ + datetime.date(2014, 5, 16), datetime.date(2014, 6, 17), datetime.date(2014, 7, 17), + datetime.date(2014, 8, 15), datetime.date(2014, 9, 16), datetime.date(2014, 10, 16), + datetime.date(2014, 11, 14), datetime.date(2014, 12, 17), datetime.date(2015, 1, 16), + datetime.date(2015, 2, 18), datetime.date(2015, 3, 19), datetime.date(2015, 4, 17), + datetime.date(2015, 5, 18), datetime.date(2015, 6, 17), datetime.date(2015, 7, 17), + datetime.date(2015, 8, 17), datetime.date(2015, 9, 16), datetime.date(2015, 10, 16), + datetime.date(2015, 11, 16), datetime.date(2015, 12, 17), datetime.date(2016, 1, 19), + datetime.date(2016, 2, 18), datetime.date(2016, 3, 18), datetime.date(2016, 4, 18)] + test_raw_bill['charge'] = [ + 2601.6289696969693, 2642.1740261508003, 3437.551946607342, 2930.5070588449826, + 2514.1242835094554, 2804.4448749999997, 3237.7359972191325, 3289.4155027808674, + 2796.5700000000002, 2463.5113047830923, 2370.0007392051775, 2479.081440860215] + test_raw_bill['usage'] = [ + 0.094265231101663627, 0.10175446346513953, 0.12248981352003527, 0.11229655777596657, + 0.092170964664193167, 0.094173672324921492, 0.095187070309577237, 0.097177529967719486, + 0.095676831493476874, 0.091583582602530869, 0.089122740090923164, 0.091516956021057888] + + input_dict = test_raw_bill + output_dict = { + 'monthly_usage': [ + 0.092656544646156233, 0.081407077375199768, 0.096259845999318444, 0.095904698506193486, + 0.09970580811571926, 0.10713597790787066, 0.12362302566814179, 0.10416990876794137, + 0.090033196083726619, 0.099460650112727964, 0.093068756936307756, 0.094710339831841669], + 'monthly_charge': [ + 2611.2818658104966, 2180.2694934775395, 2578.5859081110675, 2619.5021069201466, + 2673.9005752806534, 2893.2607949224612, 3362.6736487267954, 2772.8416549504082, + 2565.8030834213941, 3170.3949663777121, 3157.9130867351737, 2999.6133802204467], + 'monthly_price': [ + 28182.379083772827, 26782.308906986349, 26787.762657851385, 27313.595138938686, + 26817.901843564676, 27005.501339712977, 27201.030152373722, 26618.451410257541, + 28498.41164180508, 31875.872144254135, 33930.968787907128, 31671.445647289031]} + result_dict = bill_month_normalize_rough(input_dict) + + assert result_dict == output_dict diff --git a/bpfin/utilbills/bill_month_normalize_rough.py b/bpfin/utilbills/bill_month_normalize_rough.py index 07d0772..ccf9d9b 100644 --- a/bpfin/utilbills/bill_month_normalize_rough.py +++ b/bpfin/utilbills/bill_month_normalize_rough.py @@ -2,76 +2,47 @@ import datetime # import sys import bpfin.lib.other as lib -# sys.path.append('C:/Users/zheng/Documents/BlocPower_Work_File/7. Python/') - - -# class Bill(): -# def __init__(self, raw_bill): -# self.billstart = lib.convert_timestamp_date(raw_bill['date_from']) -# self.billend = lib.convert_timestamp_date(raw_bill['date_to']) -# self.usage = raw_bill['usage'] -# self.charge = raw_bill['charge'] -# self.utility_type = raw_bill['utility_type'] - -# def normalize_rough(self): -# if self.billstart != []: -# monthmatrix = lib.form_month_matrix(self.billstart, self.billend) -# # self.hist_daily_usage = lib.division(self.usage, lib.date_diff(self.billstart, self.billend)) -# # self.hist_daily_charge = lib.division(self.charge, lib.date_diff(self.billstart, self.billend)) -# # self.hist_monthly_usage = lib.monthly_average(self.hist_daily_usage, monthmatrix) -# # self.hist_monthly_charge = lib.monthly_average(self.hist_daily_charge, monthmatrix) -# # self.hist_monthly_price = lib.division(self.hist_monthly_charge, self.hist_monthly_usage) - -# daily_usage = lib.division(self.usage, lib.date_diff(self.billstart, self.billend)) -# daily_charge = lib.division(self.charge, lib.date_diff(self.billstart, self.billend)) -# month_norm_usage = lib.monthly_average(daily_usage, monthmatrix) -# month_norm_charge = lib.monthly_average(daily_charge, monthmatrix) -# month_norm_price = lib.division(month_norm_charge, month_norm_usage) -# else: -# month_norm_usage = [0] * 12 -# month_norm_charge = [0] * 12 -# month_norm_price = [0] * 12 - -# result_dict = { -# 'monthly_usage': month_norm_usage, -# 'monthly_charge': month_norm_charge, -# 'monthly_price': month_norm_price} -# return result_dict - - # def prior(self, FinancialDict): - # [self.prior_billstart, self.prior_billend] = form_bill_calendar(FinancialDict['ProForma_Start'], - # FinancialDict['ProForma_Duration']) - # self.prior_monthly_usage = duplicate2terms(self.hist_monthly_usage, self.prior_billend) - # self.prior_monthly_price = form_inflated_item(self.hist_monthly_price, self.prior_billend, - # FinancialDict['inflation_coeff_dict'], - # FinancialDict['present_date']) - # self.prior_monthly_charge = product2list(self.prior_monthly_usage, self.prior_monthly_price) - def bill_month_normalize_rough(raw_bill): - print('\n let the normalization starts') - print(raw_bill) - - billstart = lib.convert_timestamp_date(raw_bill['date_from']) - billend = lib.convert_timestamp_date(raw_bill['date_to']) + """ take raw bill as input, normalize the date from random dates to beg/end of a month + math calculation is rough, by determining daily usage, daily price to calculate monthly usage and average price + NOT using reggression neither BlocPower's disaggeration method + inputs are at least 12 months of bills + outcome are 12 months of values. If the raw bill covers more than 12 months, then an average will be taken + + Args: + raw_bill (dictionary): dictionary of lists. Elements are + 'date_from: list of datetime, + 'date_to', list of datetime, + 'usage', list of float values, + 'charge', list of float, + 'utility_type', a char indicating utility type + Returns: + dictionary: dictionary of lists. Elements are + 'monthly_usage': a list of 12 float values, month normalized average energy usage + 'monthly_charge': a list of 12 float values, month normalized average energy charge + 'monthly_price': a list of 12 float values, month normalized average energy price + """ + + bill_start = lib.convert_timestamp_date(raw_bill['date_from']) + bill_end = lib.convert_timestamp_date(raw_bill['date_to']) usage = raw_bill['usage'] charge = raw_bill['charge'] - utility_type = raw_bill['utility_type'] + # utility_type = raw_bill['utility_type'] - if billstart != []: - monthmatrix = lib.form_month_matrix(billstart, billend) - daily_usage = lib.division(usage, lib.date_diff(billstart, billend)) - daily_charge = lib.division(charge, lib.date_diff(billstart, billend)) + if bill_start != []: + month_matrix = lib.form_month_matrix(bill_start, bill_end) + daily_usage = lib.division(usage, lib.date_diff(bill_start, bill_end)) + daily_charge = lib.division(charge, lib.date_diff(bill_start, bill_end)) - month_norm_usage = lib.monthly_average(daily_usage, monthmatrix) - month_norm_charge = lib.monthly_average(daily_charge, monthmatrix) + month_norm_usage = lib.monthly_average(daily_usage, month_matrix) + month_norm_charge = lib.monthly_average(daily_charge, month_matrix) month_norm_price = lib.division(month_norm_charge, month_norm_usage) else: month_norm_usage = [0] * 12 month_norm_charge = [0] * 12 month_norm_price = [0] * 12 - print("\n It goes ok") return {'monthly_usage': month_norm_usage, 'monthly_charge': month_norm_charge, 'monthly_price': month_norm_price} -- GitLab From cfb09f499e83b995bbd2a4783f917362bfd1a306 Mon Sep 17 00:00:00 2001 From: Sarey Hamarneh Date: Tue, 18 Apr 2017 17:45:21 -0400 Subject: [PATCH 3/6] Create __init__ file --- bpfin/tests/test_financials/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 bpfin/tests/test_financials/__init__.py diff --git a/bpfin/tests/test_financials/__init__.py b/bpfin/tests/test_financials/__init__.py new file mode 100644 index 0000000..e69de29 -- GitLab From cd0afe99a5b3cc1ece5de60265da98c4081122c2 Mon Sep 17 00:00:00 2001 From: Sarey Hamarneh Date: Tue, 18 Apr 2017 17:49:22 -0400 Subject: [PATCH 4/6] Update cash_balance to import datetime module and rename file to make all lowercase. --- bpfin/financials/cash_Balanace.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bpfin/financials/cash_Balanace.py b/bpfin/financials/cash_Balanace.py index b82a7e7..e35a5db 100644 --- a/bpfin/financials/cash_Balanace.py +++ b/bpfin/financials/cash_Balanace.py @@ -1,4 +1,4 @@ - +from datetime import date def cash_balance(cash_dictionary): -- GitLab From b7fb6c4b8edb2d1a525ca07efa5c8422790d780b Mon Sep 17 00:00:00 2001 From: Sarey Hamarneh Date: Tue, 18 Apr 2017 18:41:39 -0400 Subject: [PATCH 5/6] Add cash balance --- bpengine | 1 - .../BPFINPATH => financials/__init__.py} | 0 bpfin/financials/cash_Balanace.py | 22 ------------------- bpfin/financials/cash_balance.py | 19 ++++++++++++++++ .../test_financials/test_cash_balance.py | 15 +++++++++++++ 5 files changed, 34 insertions(+), 23 deletions(-) delete mode 160000 bpengine rename bpfin/{utilbills/BPFINPATH => financials/__init__.py} (100%) delete mode 100644 bpfin/financials/cash_Balanace.py create mode 100644 bpfin/financials/cash_balance.py create mode 100644 bpfin/tests/test_financials/test_cash_balance.py diff --git a/bpengine b/bpengine deleted file mode 160000 index 070ded0..0000000 --- a/bpengine +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 070ded05633b0d51e1cb71f141e7c0f5ff6e3268 diff --git a/bpfin/utilbills/BPFINPATH b/bpfin/financials/__init__.py similarity index 100% rename from bpfin/utilbills/BPFINPATH rename to bpfin/financials/__init__.py diff --git a/bpfin/financials/cash_Balanace.py b/bpfin/financials/cash_Balanace.py deleted file mode 100644 index e35a5db..0000000 --- a/bpfin/financials/cash_Balanace.py +++ /dev/null @@ -1,22 +0,0 @@ -from datetime import date - -def cash_balance(cash_dictionary): - - cash_balance_dictionary = {} - - bank_statement = {} - - for date,value_tuple in dictionary.items(): - if value_tuple[1] is True: - cash_balance_dictionary[date.year] = value_tuple[0] - else: - #check if year (key) not is present in bank_statement - if date.year not in bank_statement: - bank_statement[date.year] = [] - bank_statement[date.year].append(value_tuple[0]) - - for year, value in bank_statement.items(): - if year not in cash_balance_dictionary: - cash_balance_dictionary[year] = sum(value)/len(value) - - return cash_balance_dictionary diff --git a/bpfin/financials/cash_balance.py b/bpfin/financials/cash_balance.py new file mode 100644 index 0000000..f8759ea --- /dev/null +++ b/bpfin/financials/cash_balance.py @@ -0,0 +1,19 @@ +def cash_balance(cash_dictionary): + + cash_balance_dictionary = {} + + bank_statement = {} + + for my_date, value_tuple in cash_dictionary.items(): + if value_tuple[1] is True: + cash_balance_dictionary[my_date.year] = value_tuple[0] + else: + # check if year (key) not is present in bank_statement + if my_date.year not in bank_statement: + bank_statement[my_date.year] = [] + bank_statement[my_date.year].append(value_tuple[0]) + + for year, value in bank_statement.items(): + if year not in cash_balance_dictionary: + cash_balance_dictionary[year] = sum(value)/len(value) + return cash_balance_dictionary diff --git a/bpfin/tests/test_financials/test_cash_balance.py b/bpfin/tests/test_financials/test_cash_balance.py new file mode 100644 index 0000000..9a33d9a --- /dev/null +++ b/bpfin/tests/test_financials/test_cash_balance.py @@ -0,0 +1,15 @@ +from bpfin.financials.cash_balance import cash_balance +from datetime import date + + +def test_cash_balance(): + input_dictionary = { + date(2014, 11, 1): (500, False), + date(2015, 12, 31): (600, True), + date(2016, 11, 11): (500, False), + date(2016, 10, 10): (400, False) + } + output_cash_balance = {2014: 500.0, 2015: 600, 2016: 450.0} + result = cash_balance(input_dictionary) + + assert result == output_cash_balance -- GitLab From 5b6e3211dfc44a75a8cafbdf0f26592ed29f88ac Mon Sep 17 00:00:00 2001 From: Sarey Hamarneh Date: Wed, 19 Apr 2017 18:13:52 -0400 Subject: [PATCH 6/6] Delete strange ipynb leftover docs --- .../rough draft-checkpoint.ipynb | 172 ----------- rough draft.ipynb | 267 ------------------ 2 files changed, 439 deletions(-) delete mode 100644 .ipynb_checkpoints/rough draft-checkpoint.ipynb delete mode 100644 rough draft.ipynb diff --git a/.ipynb_checkpoints/rough draft-checkpoint.ipynb b/.ipynb_checkpoints/rough draft-checkpoint.ipynb deleted file mode 100644 index 3353fe1..0000000 --- a/.ipynb_checkpoints/rough draft-checkpoint.ipynb +++ /dev/null @@ -1,172 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 66, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "from datetime import date\n", - "import numpy as np\n", - "import statsmodels.api as sm\n", - "import pandas as pd" - ] - }, - { - "cell_type": "code", - "execution_count": 69, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "def daily_average_use_or_charge(from_date, to_date, total_utility_use_or_charge):\n", - " fromdate = []\n", - " todate = []\n", - " for date in from_date:\n", - " fromdate.append(date)\n", - " for date in to_date:\n", - " todate.append(date)\n", - " interstore = [list(x) for x in zip(fromdate, todate)]\n", - " finalstore = []\n", - " for value in interstore:\n", - " difference = (value[1] - value[0])\n", - " finalstore.append(difference.days)\n", - "\n", - " bill_daily_average = [x / y for x, y in zip(total_utility_use_or_charge, finalstore)]\n", - " perbill_useorcharge = []\n", - " for number in bill_daily_average:\n", - " perbill_useorcharge.append(number)\n", - " return perbill_useorcharge" - ] - }, - { - "cell_type": "code", - "execution_count": 73, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "input_from_date = [date(1995, 10, 1), date(1996, 11, 1), date(1997, 12, 1)]\n", - "input_to_date = [date(1996, 10, 1), date(1997, 11, 1), date(1998, 12, 1)]\n", - "input_total_utility_use_or_charge = [10, 10, 10]" - ] - }, - { - "cell_type": "code", - "execution_count": 74, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "[0.0273224043715847, 0.0273972602739726, 0.0273972602739726]" - ] - }, - "execution_count": 74, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "daily_average_use_or_charge(input_from_date, input_to_date, input_total_utility_use_or_charge)" - ] - }, - { - "cell_type": "code", - "execution_count": 70, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "def regression_coefficients(x_list, y_list, is_intercept):\n", - "# \"\"\"Regress two lists of values.\n", - "\n", - "# Args:\n", - "# x_list: list of base x values for regression\n", - "# y_list: list of base y values for regression\n", - "# is_intercept (boolean): it is true that we want an intercept value in our regression\n", - "# Returns:\n", - "# tuple: x and y coefficients from regression\n", - "# \"\"\"\n", - " x_values = x_list\n", - " y_values = y_list\n", - " if is_intercept is True:\n", - " x_values = sm.add_constant(x_values)\n", - " model = sm.OLS(y_values, x_values)\n", - " results = model.fit()\n", - " coefficients = results.params\n", - " return coefficients" - ] - }, - { - "cell_type": "code", - "execution_count": 65, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([ -3.77475828e-15, 2.00000000e+00])" - ] - }, - "execution_count": 65, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "regression_coefficients([15,30,45],[30,60,90],True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "best = {date(2010,10,1):(1000,True),date()}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.0" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/rough draft.ipynb b/rough draft.ipynb deleted file mode 100644 index 41e6a60..0000000 --- a/rough draft.ipynb +++ /dev/null @@ -1,267 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 66, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "from datetime import date\n", - "import numpy as np\n", - "import statsmodels.api as sm\n", - "import pandas as pd" - ] - }, - { - "cell_type": "code", - "execution_count": 69, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "def daily_average_use_or_charge(from_date, to_date, total_utility_use_or_charge):\n", - " fromdate = []\n", - " todate = []\n", - " for date in from_date:\n", - " fromdate.append(date)\n", - " for date in to_date:\n", - " todate.append(date)\n", - " interstore = [list(x) for x in zip(fromdate, todate)]\n", - " finalstore = []\n", - " for value in interstore:\n", - " difference = (value[1] - value[0])\n", - " finalstore.append(difference.days)\n", - "\n", - " bill_daily_average = [x / y for x, y in zip(total_utility_use_or_charge, finalstore)]\n", - " perbill_useorcharge = []\n", - " for number in bill_daily_average:\n", - " perbill_useorcharge.append(number)\n", - " return perbill_useorcharge" - ] - }, - { - "cell_type": "code", - "execution_count": 73, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "input_from_date = [date(1995, 10, 1), date(1996, 11, 1), date(1997, 12, 1)]\n", - "input_to_date = [date(1996, 10, 1), date(1997, 11, 1), date(1998, 12, 1)]\n", - "input_total_utility_use_or_charge = [10, 10, 10]" - ] - }, - { - "cell_type": "code", - "execution_count": 74, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "[0.0273224043715847, 0.0273972602739726, 0.0273972602739726]" - ] - }, - "execution_count": 74, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "daily_average_use_or_charge(input_from_date, input_to_date, input_total_utility_use_or_charge)" - ] - }, - { - "cell_type": "code", - "execution_count": 70, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "def regression_coefficients(x_list, y_list, is_intercept):\n", - "# \"\"\"Regress two lists of values.\n", - "\n", - "# Args:\n", - "# x_list: list of base x values for regression\n", - "# y_list: list of base y values for regression\n", - "# is_intercept (boolean): it is true that we want an intercept value in our regression\n", - "# Returns:\n", - "# tuple: x and y coefficients from regression\n", - "# \"\"\"\n", - " x_values = x_list\n", - " y_values = y_list\n", - " if is_intercept is True:\n", - " x_values = sm.add_constant(x_values)\n", - " model = sm.OLS(y_values, x_values)\n", - " results = model.fit()\n", - " coefficients = results.params\n", - " return coefficients" - ] - }, - { - "cell_type": "code", - "execution_count": 65, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "array([ -3.77475828e-15, 2.00000000e+00])" - ] - }, - "execution_count": 65, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "regression_coefficients([15,30,45],[30,60,90],True)" - ] - }, - { - "cell_type": "code", - "execution_count": 76, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "ename": "SyntaxError", - "evalue": "invalid syntax (, line 1)", - "output_type": "error", - "traceback": [ - "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m best = {(date(2011,10,1):(1000,False)),(date(2012,12,31):(600,True)),(date(2012,6,15):(820,False)),(date(2012,1,30):(740:False))}\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" - ] - } - ], - "source": [ - "best = {(date(2011,10,1):(1000,False)),(date(2012,12,31):(600,True)),(date(2012,6,15):(820,False)),(date(2012,1,30):(740:False))}" - ] - }, - { - "cell_type": "code", - "execution_count": 81, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "best = {date(2011,10,1):(1000,False),date(2012,12,31):(600,True),date(2012,6,15):(820,False)}" - ] - }, - { - "cell_type": "code", - "execution_count": 92, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "def cash_balance(dict_need):\n", - "\n", - " day = []\n", - " month = []\n", - " year = []\n", - " \n", - " for i in dict_need:\n", - " day.append(i.day)\n", - " month.append(i.month)\n", - " year.append(i.year)\n", - " \n", - " keys = [(x, y, z) for x, y, z in zip(year, month, day)]\n", - " \n", - " \n", - " \n", - "# for one,two in dict_need:\n", - "# if two[1] is True:\n", - "# return friend" - ] - }, - { - "cell_type": "code", - "execution_count": 93, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "cash_balance(best)" - ] - }, - { - "cell_type": "code", - "execution_count": 99, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "ename": "ValueError", - "evalue": "too many values to unpack (expected 2)", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mdict_need\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m'hey'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m23\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mone\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mtwo\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdict_need\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtwo\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m\"hello\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mValueError\u001b[0m: too many values to unpack (expected 2)" - ] - } - ], - "source": [ - "dict_need = {'hey':(23,True)}\n", - "\n", - "for one,two in dict_need:\n", - " if two[1] is True:\n", - " print (\"hello\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.0" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} -- GitLab