Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Commit

Permalink
Created Catagories model
Browse files Browse the repository at this point in the history
filtering against this model successful
need to implement this in getExpenses or a new function
to create the catagoryObj or something similar
  • Loading branch information
OGKevin committed Apr 7, 2017
2 parents 6de422f + 9947e8d commit 02ab002
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 13 deletions.
2 changes: 1 addition & 1 deletion BunqWebApp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
DEBUG = True

ALLOWED_HOSTS = ['.combunqweb.herokuapp.com', '.localhost']

Expand Down
3 changes: 3 additions & 0 deletions DataBase info/Manager_catagories.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"id","Naam","Rekening"
0,"Aliexpres","[u'DE60700111100250250061']"
3,"Gorilla","[u'DE60700111100250250061']"
3 changes: 2 additions & 1 deletion Manager/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

class GetNewData(forms.Form):
initialText = '"Datum";"Bedrag";"Rekening";"Tegenrekening";"Naam";"Omschrijving"\n"2017-03-31";"-0,01";"NL01BUNQ1234567890";"NL48ABNA0502830042";"Spotify by Adyen";"Payment description"\n"2017-03-31";"1,64";"NL01BUNQ1234567890";"NL01BUNQ1234567890";"bunq";"Slice heeft deze request verstuurd voor de groep Family."\n\n\n#Only dutch headers supported atm\n#Only Bunq CSV supported atm, or place 2 columns with headers \'Bedrag\'(ammount) and \'Naam\'(name)\n#Press \'via CSV text\' to see this example in action\n#Lines that begin with \'#\' wil be ignored'
JSONTransactions = forms.CharField(initial = initialText, widget = forms.Textarea, label='Update with data', max_length=600)
JSONTransactions = forms.CharField(initial = initialText, widget = forms.Textarea, label='', max_length=600)
# JSONTransactionsFile = forms.FileField(label='')
27 changes: 22 additions & 5 deletions Manager/master.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os
import sys
from models import transactions
from models import transactions, catagories

# NOTE: getting JSON from database
# need to chage this to not use global vars
Expand All @@ -10,7 +10,7 @@
def getInfo(method):

if method == 'database':
# print 'Method: ',method
print 'Method: ',method
data1 = list(transactions.objects.values_list('attrs', flat=True))
global data
data = data1[0]
Expand All @@ -19,14 +19,31 @@ def getInfo(method):
global catagory
catagory = catagory1[0]
# print catagory


# NOTE: testing databse catagory retrieval
catName = list(catagories.objects.filter(Rekening__contains = ['DE60700111100250250061']).values_list('Naam'))
catList = []
for x in catName:
# print 'catagoryNmae ',x[0]
catList.append(x[0])

print 'catagories found: ',catList
# NOTE: this should be implemented in getExpenses or a new fucntion createCatagory
# print type(catName)
# NOTE: endNote




return {'data':data, 'catagory' : catagory} # NOTE: the idea is that these get returned so that Global vars should be used
else:
# print 'Method: user input'
print 'Method: user input'
data1 = method
# print data1
global data
data = data1
print data
# print data
catagory1 = list(transactions.objects.values_list('catagory', flat=True))
global catagory
catagory = catagory1[0]
Expand Down Expand Up @@ -64,7 +81,7 @@ def getExpenses(begin, end):
elif x == len(catagory) - 1:
catagoryObj["Other"] += round(float(data[k]
["Bedrag"].replace(",", ".")), 2)
# print "not in catagory list"
print "not in catagory list"

if float(data[k]["Bedrag"].replace(",", ".")) < 0:
totalExpanses += float(data[k]["Bedrag"].replace(",", "."))
Expand Down
23 changes: 23 additions & 0 deletions Manager/migrations/0002_catagories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-04-07 10:03
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('Manager', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='catagories',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('Naam', models.CharField(max_length=10)),
('Rekening', models.CharField(max_length=34)),
],
),
]
21 changes: 21 additions & 0 deletions Manager/migrations/0003_auto_20170407_1027.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-04-07 10:27
from __future__ import unicode_literals

import django.contrib.postgres.fields.jsonb
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('Manager', '0002_catagories'),
]

operations = [
migrations.AlterField(
model_name='catagories',
name='Rekening',
field=django.contrib.postgres.fields.jsonb.JSONField(),
),
]
26 changes: 26 additions & 0 deletions Manager/migrations/0004_auto_20170407_1038.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-04-07 10:38
from __future__ import unicode_literals

import django.contrib.postgres.fields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('Manager', '0003_auto_20170407_1027'),
]

operations = [
migrations.RemoveField(
model_name='catagories',
name='Rekening',
),migrations.AddField(
model_name='catagories',
name= 'Rekening',
field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=34), blank=True, size=None),

)

]
10 changes: 9 additions & 1 deletion Manager/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
from __future__ import unicode_literals
from django.contrib.postgres.fields import JSONField
from django.contrib.postgres.fields import JSONField, ArrayField
from django.db import models

# Create your models here.
class transactions(models.Model):
"""docstring for transactions."""
attrs = JSONField()
catagory = JSONField()

class catagories(models.Model):
Naam = models.CharField(max_length=10)
Rekening = ArrayField(models.CharField(max_length = 34), blank = True)

def __str__(self):
return self.Naam


9 changes: 4 additions & 5 deletions Manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.template import loader
from . import master
import json
from models import transactions
from .forms import GetNewData
# Create your views here.

Expand All @@ -18,12 +17,12 @@ def Manager(request):
# print form
inputData = json.loads(request.POST['json'])
# print inputData
# print type(inputData)
# print master.getDate('','',inputData)
print type(inputData)
print master.getDate('','',inputData)
return HttpResponse(json.dumps(master.getDate('','',inputData)))
# print 'This should be the unser input',dict(inputData.lists())
# if form.is_valid():
# print "valed form"
if form.is_valid():
print "valed form"
else:
form = GetNewData()
# print form
Expand Down
58 changes: 58 additions & 0 deletions static/Manager/JS/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ $(function() {
// sendPost()

input = $("#id_JSONTransactions").val()
console.log('click');
console.log(input);
parseCSV(input)
});
$('#fileCSV').click(function(event) {
Expand Down Expand Up @@ -161,6 +163,8 @@ function getUserGraphs(results) {
function parseCSV(csv) {

complete = function(results, file) {
console.log('parse complete');
console.log(results.data);
sendPost(results);
};
Configuration = {
Expand Down Expand Up @@ -194,7 +198,9 @@ function sendPost(json) {
}
frm = $("#textCSVForm");
frm.submit(function(event) {
console.log('submiting before prevent ');
event.preventDefault()
console.log('submitting');
$.ajax({
url: frm.attr('action'),
type: frm.attr('method'),
Expand All @@ -209,13 +215,65 @@ frm.submit(function(event) {
}
})
.done(function(response) {
console.log(response);
console.log(typeof(response));
console.log(JSON.parse(response));
sortedJSON = JSON.parse(response);
getUserGraphs2(sortedJSON);

})
.fail(function() {})
.always(function() {
console.log('send');
});
});

}

function getUserGraphs2(data) {
income = [],
expenses = [];
for (var i = 0; i < data.length; i++) {
if (data[i][1] > 0) {
income.push({
'catName': data[i][0],
'ammount': data[i][1]
})

} else {
expenses.push({
'catName': data[i][0],
'ammount': data[i][1] * -1
})

}
}

var chart = AmCharts.makeChart("chartdiv4", {
"type": "pie",
"theme": "light",
"dataProvider": income,
"valueField": "ammount",
"titleField": "catName",
"balloon": {
"fixedPosition": true
},
"export": {
"enabled": false
}
});
var chart = AmCharts.makeChart("chartdiv3", {
"type": "pie",
"theme": "light",
"dataProvider": expenses,
"valueField": "ammount",
"titleField": "catName",
"balloon": {
"fixedPosition": true
},

"export": {
"enabled": false
}
});
}
1 change: 1 addition & 0 deletions templates/Manager/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ <h1>Whitout 'DB'</h1>
<div id="chartdiv3" class="chartdiv"></div>
<div id="chartdiv4" class="chartdiv"></div>
</div>
<h1>input data to DB categorized and back</h1>
<form id='textCSVForm' class="" action="" method="post">
{% csrf_token %}
{{from}}
Expand Down

0 comments on commit 02ab002

Please sign in to comment.