Skip to content

Commit

Permalink
Change timezone and show 48 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
milafrerichs committed Aug 13, 2015
1 parent ff29052 commit d0b8a6b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion public/javascripts/helpers/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ window.helper = {
var results = this.deviceDateResult(dates);
var resultLength = result.length;
var timeFormatGoogle = d3.time.format('%Y%m%d%H%M%Z');
var timeZone = "-0400"
var timeZone = "-0700"
for(var j=0;j<resultLength;j++) {
var currentResult = result[j];
var hour = currentResult[hourColumn],
Expand Down
5 changes: 2 additions & 3 deletions public/javascripts/traffic.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
return "/realtime?ids=ga:"+matrix.settings.profileId+"&metrics=rt:activeUsers&dimensions=rt:deviceCategory&max-results=10"
},
historic: function(){
return "/historic?ids=ga:"+matrix.settings.profileId+"&dimensions=ga%3AdeviceCategory,ga%3Adate,ga%3Ahour,ga%3Aminute&metrics=ga%3Asessions&start-date=yesterday&end-date=today&max-results=2000"
return "/historic?ids=ga:"+matrix.settings.profileId+"&dimensions=ga%3AdeviceCategory,ga%3Adate,ga%3Ahour,ga%3Aminute&metrics=ga%3Asessions&start-date=2daysAgo&end-date=today&max-results=4000"
},
parseResponse: function(data){
if(data && data.hasOwnProperty('rows')){
Expand Down Expand Up @@ -84,9 +84,8 @@
loadHistory: function() {
d3.json(traffic.historic(), function(error, json) {
if (error) return console.warn(error);
var timeFormat = d3.time.format('%Y-%m-%d%H%M%Z');
var startDate = timeFormat.parse(yesterday[0]+"0000-0400")
var endDate = new Date();
var startDate = d3.time.day.offset(endDate, -2);
traffic.counts = window.helper.deviceMinuteIntervalResults(json.rows, 30, startDate, endDate);
traffic.reload();
});
Expand Down
12 changes: 6 additions & 6 deletions tests/helperSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ describe("helper", function() {
describe("deviceMinuteIntervalResults", function() {
beforeEach(function() {
clock = sinon.useFakeTimers(Date.now());
var newYorkTimeZoneMidnight = 4;
var timeZoneOffSet = 7;
var yesterday = -(1000*60*60*24)
endDate = new Date();
var currentTimeZoneOffSet = endDate.getTimezoneOffset()/60;
currentTimeZoneNewYorkMidnight = newYorkTimeZoneMidnight-currentTimeZoneOffSet;
endDate.setHours(newYorkTimeZoneMidnight,0,0)
currentTimeZoneOffsetMidnight = timeZoneOffSet-currentTimeZoneOffSet;
clock.tick(yesterday);
startDate = new Date();
startDate.setHours(newYorkTimeZoneMidnight,0,0)
startDate.setHours(currentTimeZoneOffsetMidnight, 0,0);
endDate.setHours(currentTimeZoneOffsetMidnight, 0,0);
f = d3.time.format("%Y%m%d");
resultsMinuteDate = [["desktop",f(startDate),"00","02","1"],["desktop",f(startDate),"00","25","1"],["desktop",f(startDate),"00","29","2"],["desktop",f(startDate),"01","30","1"],["desktop",f(startDate),"01","31","1"]];
});
Expand All @@ -64,14 +64,14 @@ describe("helper", function() {
expect(Object.keys(subject.deviceMinuteIntervalResults(resultsMinuteDate, 30, startDate, endDate)).length).to.eql(49);
});
it("returns zero for results not in google results", function() {
var oneOClock = currentTimeZoneNewYorkMidnight+1;
var oneOClock = currentTimeZoneOffsetMidnight+1;
var d = new Date();
d.setHours(oneOClock,0,0);
expect(subject.deviceMinuteIntervalResults(resultsMinuteDate, 30, startDate, endDate)[d].desktop).to.eq(0);
});
it("returns result aggregated by 15 minutes and device", function() {
var d = new Date();
d.setHours(currentTimeZoneNewYorkMidnight,0,0);
d.setHours(currentTimeZoneOffsetMidnight,0,0);
expect(subject.deviceMinuteIntervalResults(resultsMinuteDate, 30, startDate, endDate)[d].desktop).to.eq(4);
});
});
Expand Down
2 changes: 1 addition & 1 deletion tests/trafficSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('traffic', function() {
clock.restore();
});
it('returns the path to the servers historic endpoint', function() {
expect(subject.historic()).to.eql('/historic?ids=ga:&dimensions=ga%3AdeviceCategory,ga%3Adate,ga%3Ahour,ga%3Aminute&metrics=ga%3Asessions&start-date=yesterday&end-date=today&max-results=2000');
expect(subject.historic()).to.eql('/historic?ids=ga:&dimensions=ga%3AdeviceCategory,ga%3Adate,ga%3Ahour,ga%3Aminute&metrics=ga%3Asessions&start-date=2daysAgo&end-date=today&max-results=4000');
});
});
describe('#init', function() {
Expand Down

0 comments on commit d0b8a6b

Please sign in to comment.