From 619899ccb240ced1e41a8a47f9d2aece4b054fb3 Mon Sep 17 00:00:00 2001 From: sideroad Date: Thu, 24 Jul 2014 23:52:59 +0900 Subject: [PATCH] Use response data instead of test info --- .gitignore | 1 + build/build.js | 82 +++++++++++++++++++++++++++++++++++++++++--------- index.html | 16 +++++----- index.js | 80 +++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 142 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index 3907b55..3e27ac2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ components node_modules +tests diff --git a/build/build.js b/build/build.js index 6836d5f..473cbe4 100644 --- a/build/build.js +++ b/build/build.js @@ -30737,13 +30737,13 @@ require.register("grunt-wpt-page/index.js", function(exports, require, module){ } }, contents: { - 'html': 'HTML', - 'css': 'CSS', - 'image': 'Image', - 'flash': 'Flash', - 'js': 'JavaScript', - 'font': 'Font', - 'other': 'Other' + html: 'HTML', + css: 'CSS', + image: 'Image', + flash: 'Flash', + js: 'JavaScript', + font: 'Font', + other: 'Other' } } }, @@ -30758,6 +30758,8 @@ require.register("grunt-wpt-page/index.js", function(exports, require, module){ .set('Content-Type', 'application/json') .end(function(res){ that.results = res.body; + var aaa = that.urls; + }); request.get('tests/locations.json') @@ -30766,6 +30768,7 @@ require.register("grunt-wpt-page/index.js", function(exports, require, module){ that.locations = res.body; that.location = _.chain(that.locations).keys().first().value(); that.url = _.chain(that.urls).keys().first().value(); + var aaa = that.urls; }); }, @@ -30775,6 +30778,11 @@ require.register("grunt-wpt-page/index.js", function(exports, require, module){ }, testIds: function(){ return this.urls[this.url]; + }, + allTestIds: function(){ + return _.chain(this.urls).map(function(val, key){ + return val; + }).flatten().value(); } }, filters: { @@ -30803,22 +30811,66 @@ require.register("grunt-wpt-page/index.js", function(exports, require, module){ } }, methods: { - renderGraph: function(){ + getTests: function(testIds){ var requests = [], that = this; _(this.testIds).each(function(testId){ - var dfd = Q.defer(); + var dfd = Q.defer(); request.get('tests/'+testId+'.json') .set('Content-Type', 'application/json') .end(function(res){ - dfd.resolve(res.body); + var data = res.body.response.data, + isExists = function(source, target){ + return _.every(source, function(val){ + return _.contains(target, val); + }); + }; + + if(isExists( _.keys(that.labels.responseTime.average), _.keys(data.average.firstView)) && + isExists( _.keys(that.labels.responseTime.average), _.keys(data.average.repeatView)) && + isExists( _.keys(that.labels.responseTime.median), _.keys(data.median.firstView)) && + isExists( _.keys(that.labels.responseTime.median), _.keys(data.median.repeatView)) && + isExists( _.keys(that.labels.contents), _.keys(data.median.firstView.breakdown)) && + isExists( _.keys(that.labels.contents), _.keys(data.median.repeatView.breakdown))){ + dfd.resolve(res.body); + } else { + dfd.resolve(); + } }); requests.push(dfd.promise); }); - Q.all(requests).then(function(tests){ + return Q.all(requests); + }, + getValidTests: function(tests){ + tests + + }, + renderComparizonGraph: function(){ + var that = this; + + this.getTests(this.testIds).done(function(tests){ + tests = _.compact(tests); + + that.$set('tests', tests); + + that.renderResponseTimeGraph( tests, 'average', 'first' ); + that.renderResponseTimeGraph( tests, 'median', 'first' ); + that.renderResponseTimeGraph( tests, 'average', 'repeat' ); + that.renderResponseTimeGraph( tests, 'median', 'repeat' ); + that.renderContentsSizeGraph( tests, 'first' ); + that.renderContentsSizeGraph( tests, 'repeat' ); + that.renderContentsRequestsGraph( tests, 'first' ); + that.renderContentsRequestsGraph( tests, 'repeat' ); + }); + }, + renderGraph: function(){ + var that = this; + + this.getTests(this.testIds).done(function(tests){ + tests = _.compact(tests); that.$set('tests', tests); @@ -30837,7 +30889,7 @@ require.register("grunt-wpt-page/index.js", function(exports, require, module){ renderMorris({ data: _.map(tests, function(test){ var obj = test.response.data[type][view+'View'] || {}; - obj.date = new Date( test.info.completed*1000 ).getTime(); + obj.date = new Date( test.response.data.completed ).getTime(); return obj; }), keys: _(this.labels.responseTime[type]).keys().value(), @@ -30857,7 +30909,7 @@ require.register("grunt-wpt-page/index.js", function(exports, require, module){ obj.total = _.reduce(obj, function(memo, val, key){ return memo + Number(val||0); }, 0).toFixed(1); - obj.date = new Date( test.info.completed*1000 ).getTime(); + obj.date = new Date( test.response.data.completed ).getTime(); return obj; }), keys: _(this.labels.contents).keys().value().concat(['total']), @@ -30876,7 +30928,7 @@ require.register("grunt-wpt-page/index.js", function(exports, require, module){ obj.total = _.reduce(obj, function(memo, val, key){ return memo + Number(val||0); }, 0); - obj.date = new Date( test.info.completed*1000 ).getTime(); + obj.date = new Date( test.response.data.completed ).getTime(); return obj; }), keys: _(this.labels.contents).keys().value().concat(['total']), @@ -30906,7 +30958,7 @@ require.register("grunt-wpt-page/index.js", function(exports, require, module){ require.register("grunt-wpt-page/index.html", function(exports, require, module){ -module.exports = '\n\n\n \n \n\n Grunt WebPageTest\n\n\n\n
\n \n
\n\n
\n
\n \n
\n\n

Response Time

\n

FirstView

\n

Average

\n
\n\n

Median

\n
\n\n

RepeatView

\n

Average

\n
\n\n

Median

\n
\n\n

Detail

\n

Average

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
DateIDFirstViewRepeatView
{{$value}}{{$value}}
{{info.completed | convertToDate }}{{info.id}}{{response.data.average.firstView[$key] | ms}}{{response.data.average.repeatView[$key] | ms}}
\n\n

Median

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
DateIDFirstViewRepeatView
{{$value}}{{$value}}
{{info.completed | convertToDate}}{{info.id}}{{response.data.median.firstView[$key] | ms}}{{response.data.median.repeatView[$key] | ms}}
\n\n\n

Contents Size

\n

FirstView

\n
\n\n

RepeatView

\n
\n\n

Detail

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
DateIDFirstViewRepeatView
Total{{$value}}Total{{$value}}
{{info.completed | convertToDate}}{{info.id}}{{response.data.median.firstView.breakdown | totalBytes | KB}}{{response.data.median.firstView.breakdown[$key].bytes | KB}}{{response.data.median.repeatView.breakdown | totalBytes | KB}}{{response.data.median.repeatView.breakdown[$key].bytes | KB}}
\n\n

Contents Requests

\n

FirstView

\n
\n\n

RepeatView

\n
\n\n

Detail

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
DateIDFirstViewRepeatView
Total{{$value}}Total{{$value}}
{{info.completed | convertToDate}}{{info.id}}{{response.data.median.firstView.breakdown | totalRequests }}{{response.data.median.firstView.breakdown[$key].requests }}{{response.data.median.repeatView.breakdown | totalRequests }}{{response.data.median.repeatView.breakdown[$key].requests }}
\n\n
\n
\n
\n\n \n \n \n \n \n\n'; +module.exports = '\n\n\n \n \n\n Grunt WebPageTest\n\n\n\n
\n \n
\n\n
\n
\n \n
\n\n

Response Time

\n

FirstView

\n

Average

\n
\n\n

Median

\n
\n\n

RepeatView

\n

Average

\n
\n\n

Median

\n
\n\n

Detail

\n

Average

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
DateIDFirstViewRepeatView
{{$value}}{{$value}}
{{response.data.completed}}{{response.data.testId}}{{response.data.average.firstView[$key] | ms}}{{response.data.average.repeatView[$key] | ms}}
\n\n

Median

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
DateIDFirstViewRepeatView
{{$value}}{{$value}}
{{response.data.completed}}{{response.data.testId}}{{response.data.median.firstView[$key] | ms}}{{response.data.median.repeatView[$key] | ms}}
\n\n\n

Contents Size

\n

FirstView

\n
\n\n

RepeatView

\n
\n\n

Detail

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
DateIDFirstViewRepeatView
Total{{$value}}Total{{$value}}
{{response.data.completed}}{{response.data.testId}}{{response.data.median.firstView.breakdown | totalBytes | KB}}{{response.data.median.firstView.breakdown[$key].bytes | KB}}{{response.data.median.repeatView.breakdown | totalBytes | KB}}{{response.data.median.repeatView.breakdown[$key].bytes | KB}}
\n\n

Contents Requests

\n

FirstView

\n
\n\n

RepeatView

\n
\n\n

Detail

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
DateIDFirstViewRepeatView
Total{{$value}}Total{{$value}}
{{response.data.completed}}{{response.data.testId}}{{response.data.median.firstView.breakdown | totalRequests }}{{response.data.median.firstView.breakdown[$key].requests }}{{response.data.median.repeatView.breakdown | totalRequests }}{{response.data.median.repeatView.breakdown[$key].requests }}
\n\n
\n
\n
\n\n \n \n \n \n \n\n'; }); require.alias("moment-moment/moment.js", "grunt-wpt-page/deps/moment/moment.js"); require.alias("moment-moment/moment.js", "grunt-wpt-page/deps/moment/index.js"); diff --git a/index.html b/index.html index 2d6a76a..121e91c 100644 --- a/index.html +++ b/index.html @@ -73,8 +73,8 @@

Average

- {{info.completed | convertToDate }} - {{info.id}} + {{response.data.completed}} + {{response.data.testId}} {{response.data.average.firstView[$key] | ms}} {{response.data.average.repeatView[$key] | ms}} @@ -97,8 +97,8 @@

Median

- {{info.completed | convertToDate}} - {{info.id}} + {{response.data.completed}} + {{response.data.testId}} {{response.data.median.firstView[$key] | ms}} {{response.data.median.repeatView[$key] | ms}} @@ -131,8 +131,8 @@

Detail

- {{info.completed | convertToDate}} - {{info.id}} + {{response.data.completed}} + {{response.data.testId}} {{response.data.median.firstView.breakdown | totalBytes | KB}} {{response.data.median.firstView.breakdown[$key].bytes | KB}} {{response.data.median.repeatView.breakdown | totalBytes | KB}} @@ -166,8 +166,8 @@

Detail

- {{info.completed | convertToDate}} - {{info.id}} + {{response.data.completed}} + {{response.data.testId}} {{response.data.median.firstView.breakdown | totalRequests }} {{response.data.median.firstView.breakdown[$key].requests }} {{response.data.median.repeatView.breakdown | totalRequests }} diff --git a/index.js b/index.js index 6b5a743..b1b0af9 100644 --- a/index.js +++ b/index.js @@ -44,13 +44,13 @@ } }, contents: { - 'html': 'HTML', - 'css': 'CSS', - 'image': 'Image', - 'flash': 'Flash', - 'js': 'JavaScript', - 'font': 'Font', - 'other': 'Other' + html: 'HTML', + css: 'CSS', + image: 'Image', + flash: 'Flash', + js: 'JavaScript', + font: 'Font', + other: 'Other' } } }, @@ -65,6 +65,8 @@ .set('Content-Type', 'application/json') .end(function(res){ that.results = res.body; + var aaa = that.urls; + }); request.get('tests/locations.json') @@ -73,6 +75,7 @@ that.locations = res.body; that.location = _.chain(that.locations).keys().first().value(); that.url = _.chain(that.urls).keys().first().value(); + var aaa = that.urls; }); }, @@ -82,6 +85,11 @@ }, testIds: function(){ return this.urls[this.url]; + }, + allTestIds: function(){ + return _.chain(this.urls).map(function(val, key){ + return val; + }).flatten().value(); } }, filters: { @@ -110,22 +118,66 @@ } }, methods: { - renderGraph: function(){ + getTests: function(testIds){ var requests = [], that = this; _(this.testIds).each(function(testId){ - var dfd = Q.defer(); + var dfd = Q.defer(); request.get('tests/'+testId+'.json') .set('Content-Type', 'application/json') .end(function(res){ - dfd.resolve(res.body); + var data = res.body.response.data, + isExists = function(source, target){ + return _.every(source, function(val){ + return _.contains(target, val); + }); + }; + + if(isExists( _.keys(that.labels.responseTime.average), _.keys(data.average.firstView)) && + isExists( _.keys(that.labels.responseTime.average), _.keys(data.average.repeatView)) && + isExists( _.keys(that.labels.responseTime.median), _.keys(data.median.firstView)) && + isExists( _.keys(that.labels.responseTime.median), _.keys(data.median.repeatView)) && + isExists( _.keys(that.labels.contents), _.keys(data.median.firstView.breakdown)) && + isExists( _.keys(that.labels.contents), _.keys(data.median.repeatView.breakdown))){ + dfd.resolve(res.body); + } else { + dfd.resolve(); + } }); requests.push(dfd.promise); }); - Q.all(requests).then(function(tests){ + return Q.all(requests); + }, + getValidTests: function(tests){ + tests + + }, + renderComparizonGraph: function(){ + var that = this; + + this.getTests(this.testIds).done(function(tests){ + tests = _.compact(tests); + + that.$set('tests', tests); + + that.renderResponseTimeGraph( tests, 'average', 'first' ); + that.renderResponseTimeGraph( tests, 'median', 'first' ); + that.renderResponseTimeGraph( tests, 'average', 'repeat' ); + that.renderResponseTimeGraph( tests, 'median', 'repeat' ); + that.renderContentsSizeGraph( tests, 'first' ); + that.renderContentsSizeGraph( tests, 'repeat' ); + that.renderContentsRequestsGraph( tests, 'first' ); + that.renderContentsRequestsGraph( tests, 'repeat' ); + }); + }, + renderGraph: function(){ + var that = this; + + this.getTests(this.testIds).done(function(tests){ + tests = _.compact(tests); that.$set('tests', tests); @@ -144,7 +196,7 @@ renderMorris({ data: _.map(tests, function(test){ var obj = test.response.data[type][view+'View'] || {}; - obj.date = new Date( test.info.completed*1000 ).getTime(); + obj.date = new Date( test.response.data.completed ).getTime(); return obj; }), keys: _(this.labels.responseTime[type]).keys().value(), @@ -164,7 +216,7 @@ obj.total = _.reduce(obj, function(memo, val, key){ return memo + Number(val||0); }, 0).toFixed(1); - obj.date = new Date( test.info.completed*1000 ).getTime(); + obj.date = new Date( test.response.data.completed ).getTime(); return obj; }), keys: _(this.labels.contents).keys().value().concat(['total']), @@ -183,7 +235,7 @@ obj.total = _.reduce(obj, function(memo, val, key){ return memo + Number(val||0); }, 0); - obj.date = new Date( test.info.completed*1000 ).getTime(); + obj.date = new Date( test.response.data.completed ).getTime(); return obj; }), keys: _(this.labels.contents).keys().value().concat(['total']),