Skip to content

Commit

Permalink
findfaster test
Browse files Browse the repository at this point in the history
  • Loading branch information
thesam73 committed Aug 3, 2014
1 parent 617bb07 commit 1eac5a0
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ standard-app-packages
autopublish
insecure
preserve-inputs
moment
find-faster
1 change: 0 additions & 1 deletion iou-meteor.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<script src="/js/Chart.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://dimplejs.org/dist/dimple.v2.0.0.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.7.0/moment.min.js"></script>
</head>

<body>
Expand Down
98 changes: 49 additions & 49 deletions iou-meteor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function totalmonthCat(Items) {
var curr_month = ds.getMonth() + 1; //Months are zero based
var curr_date = curr_year + ',' + (curr_month <= 9 ? '0' + curr_month : curr_month);

//Items.find({timestamp: { $lt: new Date(), $gt: new Date(curr_date+','+curr_month) }});
//Items.findFaster({timestamp: { $lt: new Date(), $gt: new Date(curr_date+','+curr_month) }});

var total = 0;
Items.forEach(function (item) {
Expand Down Expand Up @@ -37,7 +37,7 @@ function monthlytotalCat(cat) {
var endmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-31';
curr_month = curr_month - 1;
var startlastmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-01';
return totalCat(Depenses.find({
return totalCat(Depenses.findFaster({
category: cat,
timestamp: {
$gte: startmonth,
Expand All @@ -54,7 +54,7 @@ function previousmonthmonthlytotalCat(cat) {
var endmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-31';
curr_month = curr_month - 1;
var startlastmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-01';
return totalCat(Depenses.find({
return totalCat(Depenses.findFaster({
category: cat,
timestamp: {
$gte: startlastmonth,
Expand All @@ -64,7 +64,7 @@ function previousmonthmonthlytotalCat(cat) {
}

function anymonthmonthlytotalCat(cat, startmonth, endmonth) {
return totalCat(Depenses.find({
return totalCat(Depenses.findFaster({
category: cat,
timestamp: {
$gte: startmonth,
Expand All @@ -82,22 +82,22 @@ function monthlyratioCat(cat) {
curr_month = curr_month - 1;
var startlastmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-01';
//get older value en set first day of month
if (Depenses.find().count() > 0) {
if (Depenses.findFaster().count() > 0) {
//if (Session.get("active")) {
var firstmonth_start = Depenses.find({}, {
var firstmonth_start = Depenses.findFaster({}, {
sort: {
timestamp: 1
}
}).fetch()[0].timestamp.slice(0, -2) + '01';
var firstmonth_end = Depenses.find({}, {
var firstmonth_end = Depenses.findFaster({}, {
sort: {
timestamp: 1
}
}).fetch()[0].timestamp.slice(0, -2) + '31';
var m_month_start = moment(firstmonth_start, "YYYY-MM-DD");
var m_firstmonth = moment(firstmonth_start, "YYYY-MM-DD");
var m_month_end = moment(firstmonth_end, "YYYY-MM-DD");
var lasttmonth_start = Depenses.find({}, {
var lasttmonth_start = Depenses.findFaster({}, {
sort: {
timestamp: -1
}
Expand All @@ -108,7 +108,7 @@ function monthlyratioCat(cat) {
for (i = 0; i < howmanymonth; i++) {
var month_start = m_month_start.add('M', i).format("YYYY-MM-DD");
var month_end = m_month_end.add('M', i).format("YYYY-MM-DD");
monthlyPrevious[i] = totalCat(Depenses.find({
monthlyPrevious[i] = totalCat(Depenses.findFaster({
category: cat,
timestamp: {
$gte: month_start,
Expand All @@ -117,13 +117,13 @@ function monthlyratioCat(cat) {
}, {fields: {amount: 1}}));
}
// console.log(monthlyPrevious);
// var previous = totalCat(Depenses.find({
// var previous = totalCat(Depenses.findFaster({
// category: cat,
// timestamp: {$gte: startlastmonth, $lte: startmonth}
// }));
var previous = average(monthlyPrevious);
//console.log(cat + ":cat, " + previous);
var current = totalCat(Depenses.find({
var current = totalCat(Depenses.findFaster({
category: cat,
timestamp: {
$gte: startmonth,
Expand All @@ -147,14 +147,14 @@ function monthlyMratioCat(cat) {
var endmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-31';
curr_month = curr_month - 1;
var startlastmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-01';
var current = totalCat(Depenses.find({
var current = totalCat(Depenses.findFaster({
category: cat,
timestamp: {
$gte: startmonth,
$lte: endmonth
}
}, {fields: {amount: 1}}));
var total = totalCat(Depenses.find({
var total = totalCat(Depenses.findFaster({
timestamp: {
$gte: startmonth,
$lte: endmonth
Expand All @@ -166,7 +166,7 @@ function monthlyMratioCat(cat) {
}

function drawChartCurrent() {
//if (Depenses.find().count() > 0) {
//if (Depenses.findFaster().count() > 0) {
$('#chartContainer').html('');
// var d = new Date();
// var curr_month = d.getMonth() + 1; //Months are zero based
Expand All @@ -177,9 +177,9 @@ function drawChartCurrent() {
// var startlastmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-01';
// var endlastmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-31';

var firstmonth_start = Depenses.find({}, {sort: {timestamp: 1}}).fetch()[0].timestamp.slice(0, -2) + '01';
var lasttmonth_start = Depenses.find({}, {sort: {timestamp: -1}}).fetch()[0].timestamp.slice(0, -2) + '01';
var lasttmonth_end = Depenses.find({}, {sort: {timestamp: -1}}).fetch()[0].timestamp.slice(0, -2) + '31';
var firstmonth_start = Depenses.findFaster({}, {sort: {timestamp: 1}}).fetch()[0].timestamp.slice(0, -2) + '01';
var lasttmonth_start = Depenses.findFaster({}, {sort: {timestamp: -1}}).fetch()[0].timestamp.slice(0, -2) + '01';
var lasttmonth_end = Depenses.findFaster({}, {sort: {timestamp: -1}}).fetch()[0].timestamp.slice(0, -2) + '31';
var m_firstmonth = moment(firstmonth_start, "YYYY-MM-DD");
var m_lasttmonth = moment(lasttmonth_start, "YYYY-MM-DD");
var m_lasttmonth_end = moment(lasttmonth_end, "YYYY-MM-DD");
Expand Down Expand Up @@ -295,43 +295,43 @@ function drawChartCurrent() {
myChart.draw();
y.titleShape.remove();
x.titleShape.remove();
//$('.dimple-legend').find('text').attr("transform", "translate(0,10)");
//$('.dimple-legend').findFaster('text').attr("transform", "translate(0,10)");
//}
}

// function drawChart() {
// var data = [{
// value: totalCat(Depenses.find({
// value: totalCat(Depenses.findFaster({
// category: 'rent'
// })),
// color: "#7f8c8d"
// }, {
// value: totalCat(Depenses.find({
// value: totalCat(Depenses.findFaster({
// category: 'bills'
// })),
// color: "#2ecc71"
// }, {
// value: totalCat(Depenses.find({
// value: totalCat(Depenses.findFaster({
// category: 'food'
// })),
// color: "#3498db"
// }, {
// value: totalCat(Depenses.find({
// value: totalCat(Depenses.findFaster({
// category: 'supermarket'
// })),
// color: "#00CCC1"
// }, {
// value: totalCat(Depenses.find({
// value: totalCat(Depenses.findFaster({
// category: 'shopping'
// })),
// color: "#9b59b6"
// }, {
// value: totalCat(Depenses.find({
// value: totalCat(Depenses.findFaster({
// category: 'activity'
// })),
// color: "#e67e22"
// }, {
// value: totalCat(Depenses.find({
// value: totalCat(Depenses.findFaster({
// category: 'car'
// })),
// color: "#34495e"
Expand Down Expand Up @@ -363,7 +363,7 @@ function groupBy(input, xCol, yCol) {
}

function drawChartMonthly() {
var depenses = Depenses.find().fetch();
var depenses = Depenses.findFasterFaster().fetch();
// var groupedDates = _.groupBy(_.pluck(customers, 'timestamp'), function (date) {return date.split("-",2);});
var monthlyDepenses = _.groupBy(depenses, function (depense) {
return depense.timestamp.split("-", 2);
Expand Down Expand Up @@ -452,8 +452,8 @@ if (Meteor.isClient) {
// });

Template.depenses.depenses = function () {
//console.log(Depenses.find({}, {sort: {timestamp: -1}}));
return Depenses.find({}, {
//console.log(Depenses.findFaster({}, {sort: {timestamp: -1}}));
return Depenses.findFaster({}, {
sort: {
timestamp: -1
}
Expand All @@ -479,7 +479,7 @@ if (Meteor.isClient) {
var endmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-31';
curr_month = curr_month - 1;
var startlastmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-01';
var current = totalCat(Depenses.find({
var current = totalCat(Depenses.findFaster({
timestamp: {
$gte: startmonth,
$lte: endmonth
Expand All @@ -495,13 +495,13 @@ if (Meteor.isClient) {
var endmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-31';
curr_month = curr_month - 1;
var startlastmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-01';
var previous = totalCat(Depenses.find({
var previous = totalCat(Depenses.findFaster({
timestamp: {
$gte: startlastmonth,
$lte: startmonth
}
}, {fields: {amount: 1}}));
var current = totalCat(Depenses.find({
var current = totalCat(Depenses.findFaster({
timestamp: {
$gte: startmonth,
$lte: endmonth
Expand Down Expand Up @@ -572,7 +572,7 @@ if (Meteor.isClient) {
var endmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-31';
curr_month = curr_month - 1;
var startlastmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-01';
return totalCat(Depenses.find({
return totalCat(Depenses.findFaster({
timestamp: {
$gte: startmonth,
$lte: endmonth
Expand Down Expand Up @@ -609,22 +609,22 @@ if (Meteor.isClient) {
var endmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-31';
curr_month = curr_month - 1;
var startlastmonth = curr_year + '-' + (curr_month <= 9 ? '0' + curr_month : curr_month) + '-01';
if (Depenses.find().count() > 0) {
if (Depenses.findFaster().count() > 0) {
//if (Session.get("active")) {
var firstmonth_start = Depenses.find({}, {
var firstmonth_start = Depenses.findFaster({}, {
sort: {
timestamp: 1
}
}).fetch()[0].timestamp.slice(0, -2) + '01';
var firstmonth_end = Depenses.find({}, {
var firstmonth_end = Depenses.findFaster({}, {
sort: {
timestamp: 1
}
}).fetch()[0].timestamp.slice(0, -2) + '31';
var m_month_start = moment(firstmonth_start, "YYYY-MM-DD");
var m_firstmonth = moment(firstmonth_start, "YYYY-MM-DD");
var m_month_end = moment(firstmonth_end, "YYYY-MM-DD");
var lasttmonth_start = Depenses.find({}, {
var lasttmonth_start = Depenses.findFaster({}, {
sort: {
timestamp: -1
}
Expand All @@ -635,15 +635,15 @@ if (Meteor.isClient) {
for (i = 0; i < howmanymonth; i++) {
var month_start = m_month_start.add('M', i).format("YYYY-MM-DD");
var month_end = m_month_end.add('M', i).format("YYYY-MM-DD");
monthlyPrevious[i] = totalCat(Depenses.find({
monthlyPrevious[i] = totalCat(Depenses.findFaster({
timestamp: {
$gte: month_start,
$lte: month_end
}
}, {fields: {amount: 1}}));
}
var previous = average(monthlyPrevious);
var current = totalCat(Depenses.find({
var current = totalCat(Depenses.findFaster({
timestamp: {
$gte: startmonth,
$lte: endmonth
Expand All @@ -656,10 +656,10 @@ if (Meteor.isClient) {
else {
return [];
}
// var previous = totalCat(Depenses.find({
// var previous = totalCat(Depenses.findFaster({
// timestamp: {$gte: startlastmonth, $lte: startmonth}
// }));
// var current = totalCat(Depenses.find({
// var current = totalCat(Depenses.findFaster({
// timestamp: {$gte: startmonth, $lte: endmonth}
// }));
// var ratio = Math.round(current / previous * 100);
Expand Down Expand Up @@ -711,33 +711,33 @@ if (Meteor.isClient) {
}
Template.summaryall.rendered = function () {
//drawChartMonthly()
//var depenseloaded = Depenses.find({}, {sort: {timestamp: -1}});
//var depenseloaded = Depenses.findFaster({}, {sort: {timestamp: -1}});
//console.log(depenseloaded);
//
//if (Session.get("active")) {
// if (Depenses.find().count() > 0) {
// if (Depenses.findFaster().count() > 0) {
//drawChartCurrent();
// }
//};
}
Template.summaryall.Mdepenses = function () {
//return Depenses.find({}, {sort: {timestamp: -1}});
var depenses = Depenses.find().fetch();
//return Depenses.findFaster({}, {sort: {timestamp: -1}});
var depenses = Depenses.findFaster().fetch();
var monthlyDepenses = _.groupBy(depenses, function (depense) {
return depense.timestamp.split("-", 2);
});
//console.log(monthlyDepenses);
}

Template.action.amountDebt = function () {
var samItems = Depenses.find({
var samItems = Depenses.findFaster({
payeur: 'sam'
});
var samSum = 0;
samItems.forEach(function (item) {
samSum += Math.round(item.amount);
})
var marionItems = Depenses.find({
var marionItems = Depenses.findFaster({
payeur: 'marion'
});
var marionSum = 0;
Expand All @@ -752,14 +752,14 @@ if (Meteor.isClient) {
}
}
Template.action.nameDebt = function () {
var samItems = Depenses.find({
var samItems = Depenses.findFaster({
payeur: 'sam'
});
var samSum = 0;
samItems.forEach(function (item) {
samSum += Math.round(item.amount);
})
var marionItems = Depenses.find({
var marionItems = Depenses.findFaster({
payeur: 'marion'
});
var marionSum = 0;
Expand Down Expand Up @@ -827,7 +827,7 @@ if (Meteor.isClient) {
'click #updatedebt': function () {
var c = confirm("Reset debt?");
if (c == true) {
var Items = Depenses.find({
var Items = Depenses.findFaster({
payeur: {
$ne: 'both'
}
Expand Down
2 changes: 2 additions & 0 deletions packages/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/moment
/find-faster
6 changes: 6 additions & 0 deletions smart.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"packages": {
"moment": {},
"find-faster": {}
}
}
Loading

0 comments on commit 1eac5a0

Please sign in to comment.