jenkins-bot has submitted this change and it was merged.

Change subject: Ignore bogus future donations.
......................................................................


Ignore bogus future donations.

Using timestamp from web server to determine 'future', so we're
assuming it's synchronized with the db server.
Changes time period grouping to include all larger units, not
just the immediately larger one.

Change-Id: I0ff958df1ddca79d8526b2a87b43a6b52e2926c7
---
M src/app/widgetBase.js
M src/components/widgets/x-by-y/x-by-y.js
2 files changed, 26 insertions(+), 11 deletions(-)

Approvals:
  Ssmith: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/app/widgetBase.js b/src/app/widgetBase.js
index 4a395d0..c8227c6 100644
--- a/src/app/widgetBase.js
+++ b/src/app/widgetBase.js
@@ -75,7 +75,7 @@
 
                };
 
-               self.processData = function(rawdata, timescale){
+               self.processData = function( rawdata, timescale, timestamp ){
 
                        var timeWord = ( timescale === 'Day' ? 'Dai' : 
timescale ) + 'ly',
                                totals = [ timeWord + ' Total'],
@@ -83,16 +83,28 @@
                                xs = [ 'x' ],
                                defaultYear = new Date().getFullYear(),
                                defaultMonth = new Date().getMonth() + 1,
-                               tempDate, timeFormat;
-
+                               tempDate, timeFormat, now = new Date( timestamp 
);
+               
+                       // coerce UTC into the default timezone.  Comparing 
offset values
+                       // so we only have to adjust 'now', not each data point
+                       now.setHours( now.getHours() + now.getTimezoneOffset() 
/ 60 );
                        $.each( rawdata, function( index, dataPoint ) {
+                               var year = dataPoint.Year || defaultYear,
+                                       month = dataPoint.Month || defaultMonth,
+                                       day = dataPoint.Day || 1,
+                                       hour = dataPoint.Hour || 0;
+
+                               // Filter bogons
+                               if ( year < 2004 || new Date( year, month - 1, 
day, hour ) > now ) {
+                                       return;
+                               }
                                totals.push( dataPoint.usd_total );
                                counts.push( dataPoint.donations );
 
-                               tempDate = ( dataPoint.Year || defaultYear ) + 
'-';
-                               tempDate += zeroPad( dataPoint.Month || 
defaultMonth ) + '-';
-                               tempDate += zeroPad( dataPoint.Day || 1 );
-                               tempDate += ' ' + zeroPad( dataPoint.Hour || 0 
);
+                               tempDate = year + '-';
+                               tempDate += zeroPad( month ) + '-';
+                               tempDate += zeroPad( day );
+                               tempDate += ' ' + zeroPad( hour );
 
                                xs.push( tempDate );
                        } );
@@ -124,12 +136,15 @@
 
                        var timeArray = ['Year', 'Month', 'Day', 'Hour'],
                                index = timeArray.indexOf( 
userChoices.timeBreakout ),
-                               query = 'group=' + userChoices.timeBreakout;
+                               query = 'group=' + userChoices.timeBreakout,
+                               levelDiff;
 
                        // If we're grouping by anything finer than year, add a 
filter and
-                       // also group by the next level up.
+                       // also group by the next levels up.
+                       for ( levelDiff = 1; index - levelDiff >= 0; 
levelDiff++ ) {
+                               query = query + '&group=' + timeArray[index - 
levelDiff];
+                       }
                        if ( index > 0 ) {
-                               query = query + '&group=' + timeArray[index - 
1];
                                query = query + '&$filter=' + timeArray[index - 
1] + 'sAgo lt \'1\'';
                        }
                        //groupStr = timeBreakout + '&group=' + 
userChoices.xSlice;
diff --git a/src/components/widgets/x-by-y/x-by-y.js 
b/src/components/widgets/x-by-y/x-by-y.js
index 7191519..3a7a6d6 100644
--- a/src/components/widgets/x-by-y/x-by-y.js
+++ b/src/components/widgets/x-by-y/x-by-y.js
@@ -180,7 +180,7 @@
                                self.displayedTimeChoice(self.timeChoice());
                                self.retrievedResults(dataArray.results);
 
-                               self.chartData = 
self.processData(self.retrievedResults(), self.timeChoice());
+                               self.chartData = self.processData( 
self.retrievedResults(), self.timeChoice(), dataArray.timestamp );
 
                                self.makeChart(self.chartData);
 

-- 
To view, visit https://gerrit.wikimedia.org/r/199752
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0ff958df1ddca79d8526b2a87b43a6b52e2926c7
Gerrit-PatchSet: 4
Gerrit-Project: wikimedia/fundraising/dash
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to