Browse Source

Frontend now only needs one set of data

Add README documenting data formats
pull/1/head
Chris Smith 13 years ago
parent
commit
a2fad42d97
3 changed files with 57 additions and 7 deletions
  1. 34
    0
      README.md
  2. 1
    2
      data.php
  3. 22
    5
      index.html

+ 34
- 0
README.md View File

@@ -0,0 +1,34 @@
1
+# Overview
2
+
3
+This project consists of a PHP backend which can parse CSV files containing
4
+bank account transaction information, and a JavaScript front-end which can
5
+analyse and display stats about the parsed data.
6
+
7
+# Data formats
8
+
9
+## Backend
10
+
11
+The backend expects a 'Statements' directory containing CSV files with the
12
+following fields:
13
+
14
+- Date (dd/mm/yy)
15
+- Amount
16
+- Description
17
+
18
+## Frontend
19
+
20
+The JS frontend uses a map containing one entry for each month's worth of
21
+transactions. At present it expects this map to be assigned to a variable
22
+called 'data'. Each month consists of an array of transactions, which are
23
+themselves objects containing the following properties:
24
+
25
+- Date - currently a serialisation of a PHP DateTime object, e.g. <br>
26
+`{"date":"2009-01-05 00:00:00","timezone_type":3,"timezone":"UTC"}`
27
+- Amount
28
+- Description - a user-friendly description of the transaction
29
+- RawDescription - the raw description from the statement (not used)
30
+- Category - user-defined category for the transaction (optional)
31
+- Type - user-defined type for the transaction (optional)
32
+
33
+If the category has the special value `(Ignored)`, it is excluded from
34
+certain calculates and graphs and showed as greyed out in tables.

+ 1
- 2
data.php View File

@@ -203,5 +203,4 @@
203 203
  });
204 204
 
205 205
 ?>
206
-var transData = <?PHP echo json_encode($transData); ?>;
207
-var monthData = <?PHP echo json_encode($rawmonths); ?>;
206
+var data = <?PHP echo json_encode($rawmonths); ?>;

+ 22
- 5
index.html View File

@@ -23,6 +23,23 @@
23 23
    }
24 24
 
25 25
    $(function() {
26
+    var transData = [{label: 'Income', data: []}, {label: 'Expense', data: []}];
27
+
28
+    $.each(data, function(month, entries) {
29
+     var split = month.split('-');
30
+     var timestamp = new Date(split[0], split[1] - 1).getTime();
31
+     var sum = [0, 0];
32
+
33
+     $.each(entries, function() {
34
+      if (this.Category == '(Ignored)') { return; }
35
+
36
+      sum[this.Amount < 0 ? 1 : 0] += this.Amount;
37
+     });
38
+
39
+     transData[0].data.push([timestamp, sum[0]]);
40
+     transData[1].data.push([timestamp, sum[1]]);
41
+    }); 
42
+
26 43
     $.plot($('#history'), transData, {
27 44
       xaxis: { mode: 'time', timeformat: '%y/%m'},
28 45
       series: {
@@ -67,7 +84,7 @@
67 84
 
68 85
       var pieData = {};
69 86
       var table = $('#historytable table');
70
-      $.each(monthData[date], function(index, trans) {
87
+      $.each(data[date], function(index, trans) {
71 88
        if (incoming != trans.Amount > 0) { return; }
72 89
 
73 90
        var tr = $('<tr/>').addClass('data').appendTo(table);
@@ -88,14 +105,14 @@
88 105
        }
89 106
       });
90 107
 
91
-      var data = [];
108
+      var seriesData = [];
92 109
       $.each(pieData, function(category, amount) {
93
-       data.push({ label: category + ' (' + Math.round(amount) + ')', data: amount });
110
+       seriesData.push({ label: category + ' (' + Math.round(amount) + ')', data: amount });
94 111
       });
95 112
 
96
-      data.sort(function(a, b) { return b.data - a.data; });
113
+      seriesData.sort(function(a, b) { return b.data - a.data; });
97 114
 
98
-      $.plot($('#expense'), data, {
115
+      $.plot($('#expense'), seriesData, {
99 116
         series: { pie: { show: true, innerRadius: 0.5 } }
100 117
       });
101 118
      }

Loading…
Cancel
Save