Ejegg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/177158
Change subject: More efficient initialization and refresh
......................................................................
More efficient initialization and refresh
Make some variables local, do some stuff with loops instead of
$.each, and get rid of some unused variables. Also, make
reloadBigEnglish just reload the data, not the page.
Change-Id: I5c9898496d412fd5cbe1a0908d66b0a53cf4e12a
---
M src/components/boards/bigEnglish/bigEnglishBoard.js
1 file changed, 35 insertions(+), 44 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/dash
refs/changes/58/177158/1
diff --git a/src/components/boards/bigEnglish/bigEnglishBoard.js
b/src/components/boards/bigEnglish/bigEnglishBoard.js
index 0bb7718..03d0b99 100644
--- a/src/components/boards/bigEnglish/bigEnglishBoard.js
+++ b/src/components/boards/bigEnglish/bigEnglishBoard.js
@@ -15,15 +15,6 @@
return moment().format( "dddd, MMMM Do YYYY, h:mm:ss a"
);
});
- // Reload the page
- self.reloadBigEnglish = function(){
- console.log('reloading');
- location.reload();
- };
- // Do it every 5 minutes as well
- setTimeout(self.reloadBigEnglish, 300000);
-
- // TODO: these two will come from the passed in data response
self.goal = ko.observable(20000000);
self.raised = ko.observable(0);
@@ -40,10 +31,8 @@
return numeral(trtd).format('$0,0');
});
- self.decemberData = [];
- self.dailyDonationLabels = [];
self.secondsByHourDonationData = ['Donations Per Second'];
- self.dailyDonationData = {};
+
//initialize day/hour data
self.dayObj = [];
self.dailyDataArray = ['Daily Total'];
@@ -59,47 +48,49 @@
// Only recalculate child boards once per half second
self.dataChanged.extend( { rateLimit: 500 } );
- $.get( '/data/big-english' , function ( dataget ) {
- self.decemberData = dataget.results;
+ self.loadData = function ( decemberData ) {
var runningTotal = 0;
for (var d = 1; d < 32; d++) {
self.dailyDataArray[d] = 0;
- self.dayObj[d] = Array(25);
- self.dayObj[d][0] = 'Hourly Totals';
- for (var h = 1; h < 25; h++) {
- self.dayObj[d][h] = 0;
- self.secondsByHourDonationData[(d - 1)
* 24 + h] = 0;
+ if (!self.dayObj[d]) {
+ self.dayObj[d] = Array(25);
+ self.dayObj[d][0] = 'Hourly Totals';
+ for (var h = 1; h < 25; h++) {
+ self.dayObj[d][h] = 0;
+
self.secondsByHourDonationData[(d - 1) * 24 + h] = 0;
+ }
}
}
- $.each(self.decemberData, function(el, i){
- var d = self.decemberData[el].day, h =
self.decemberData[el].hour;
- self.dayObj[d][h + 1] =
self.decemberData[el].usd_total;
+
+ var dataCount = decemberData.length;
+ for (var i = 0; i < dataCount; i++ ) {
+
+ var el = decemberData[i],
+ d = el.day,
+ h = el.hour,
+ total = el.usd_total;
+ self.dayObj[d][h + 1] = total;
+
//get all seconds into seconds array
- self.secondsByHourDonationData[(d - 1) * 24 +
h+1] = self.decemberData[el].usd_per_second;
- runningTotal += self.decemberData[el].usd_total;
- });
+ self.secondsByHourDonationData[(d - 1) * 24 +
h+1] = el.usd_per_second;
- $.each(self.decemberData, function(i, el){
+ runningTotal += total;
+ self.dailyDataArray[d] += total;
+ };
- //get labels from chart based on where we are
in December.
- if (self.dailyDonationLabels.indexOf(el.day) <
0){
- self.dailyDonationLabels.push(el.day);
- }
-
- //get data slice for days: donation amt
- if(self.dailyDonationData[el.day]){
- self.dailyDonationData[el.day] +=
el.usd_total;
- } else {
- self.dailyDonationData[el.day] =
el.usd_total;
- }
-
- });
-
- $.each( self.dailyDonationData, function(el, i){
- self.dailyDataArray[parseInt(el, 10)] =
self.dailyDonationData[el];
- });
self.raised(runningTotal);
- });
+ };
+
+ // Reload the data
+ self.reloadBigEnglish = function(){
+ $.get( '/data/big-english' , function ( dataget ) {
+ self.loadData( dataget.results );
+ });
+ };
+ // Do it every 5 minutes as well
+ setTimeout(self.reloadBigEnglish, 300000);
+
+ self.reloadBigEnglish();
}
return { viewModel: BigEnglishBoardViewModel, template: template };
--
To view, visit https://gerrit.wikimedia.org/r/177158
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5c9898496d412fd5cbe1a0908d66b0a53cf4e12a
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/dash
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits