Bebirchall has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/107719


Change subject: Handlebars template for main stats view
......................................................................

Handlebars template for main stats view

Change-Id: Ifc0f7714bb8180e1152478756c890d54177b400c
---
M tests/server/package.json
M tests/server/server.js
A tests/server/views/index.html
A tests/server/views/layout.html
4 files changed, 148 insertions(+), 79 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/19/107719/1

diff --git a/tests/server/package.json b/tests/server/package.json
index 189a99e..ab45a0f 100644
--- a/tests/server/package.json
+++ b/tests/server/package.json
@@ -9,7 +9,8 @@
                "path": "0.x.x",
                "mysql": "2.x.x",
                "mysql-queues": "1.x.x",
-               "express": "2.5.x"
+               "express": "2.5.x",
+               "hbs": "2.4.0"
        },
        "main": "server.js"
 }
diff --git a/tests/server/server.js b/tests/server/server.js
index 334a0e9..9cc94c9 100755
--- a/tests/server/server.js
+++ b/tests/server/server.js
@@ -3,7 +3,8 @@
 "use strict";
 
 var express = require( 'express' ),
-       optimist = require( 'optimist' );
+       optimist = require( 'optimist' ),
+       hbs = require( 'hbs' );
 
 // Default options
 var defaults = {
@@ -705,16 +706,14 @@
        }
 };
 
-var indexLinkList = function () {
-       return '<p>More details:</p>\n<ul>' +
-               '<li><a href="/topfails">Results by title</a></li>\n' +
-               '<li><a href="/failedFetches">Non-existing test 
pages</a></li>\n' +
-               '<li><a href="/failsDistr">Histogram of failures</a></li>\n' +
-               '<li><a href="/skipsDistr">Histogram of skips</a></li>\n' +
-               '<li><a href="/commits">List of all tested commits</a></li>\n' +
-               '<li><a href="/perfstats">Performance stats of last 
commit</a></li>\n' +
-               '</ul>';
-};
+var pageListData = [
+       { url: '/topfails', title: 'Results by title' },
+       { url: '/failedFetches', title: 'Non-existing test pages' },
+       { url:  '/failsDistr', title: 'Histogram of failures' },
+       { url: '/skipsDistr', title: 'Histogram of skips' },
+       { url: '/commits', title: 'List of all tested commits' },
+       { url: '/perfstats', title: 'Performance stats of last commit' }
+];
 
 var displayPerfStat = function( type, value ) {
        // Protect against not-present perfstats, i.e. when adding new ones.
@@ -830,30 +829,18 @@
                res.end( '</table></body></html>' );
        }
 };
+
 var statsWebInterface = function ( req, res ) {
-       var query, queryParams, prefix;
+       var query, queryParams;
        var cutoffDate = new Date( Date.now() - ( cutOffTime * 1000 ) );
-
-       var displayRow = function( res, label, val ) {
-                       // round numeric data, but ignore others
-                       if( !isNaN( Math.round( val * 100 ) / 100 ) ) {
-                               val = Math.round( val * 100 ) / 100;
-                       }
-                       res.write( '<tr style="font-weight:bold"><td 
style="padding-left:20px;">' + label );
-                       if ( prefix !== null ) {
-                               res.write( ' (' + prefix + ')' );
-                       }
-                       res.write( '</td><td style="padding-left:20px; 
text-align:right">' + val + '</td></tr>' );
-       };
-
-       prefix = req.params[1] || null;
+       var prefix = req.params[1] || null;
 
        // Switch the query object based on the prefix
        if ( prefix !== null ) {
                query = dbPerWikiStatsQuery;
                queryParams = [ prefix, prefix, prefix, prefix,
-                               prefix, prefix, prefix, prefix,
-                               prefix, maxTries, cutoffDate ];
+                                               prefix, prefix, prefix, prefix,
+                                               prefix, maxTries, cutoffDate ];
        } else {
                query = dbStatsQuery;
                queryParams = [ maxTries, cutoffDate ];
@@ -867,9 +854,7 @@
                        console.error("Error: " + msg);
                        res.send( msg, 500 );
                } else {
-                       res.setHeader( 'Content-Type', 'text/html; 
charset=UTF-8' );
                        res.status( 200 );
-                       res.write( '<html><body>' );
 
                        var tests = row[0].total,
                        errorLess = row[0].no_errors,
@@ -881,57 +866,50 @@
                        syntacticDiffs = Math.round( 100 * 100 *
                                ( row[0].no_fails / ( tests || 1 ) ) ) / 100;
 
-                       res.write( '<p>We have run roundtrip-tests on <b>' +
-                               tests +
-                               '</b> articles, of which <ul><li><b>' +
-                               noErrors +
-                               '%</b> parsed without errors </li><li><b>' +
-                               syntacticDiffs +
-                               '%</b> round-tripped without semantic 
differences, and </li><li><b>' +
-                               perfects +
-                               '%</b> round-tripped with no character 
differences at all.</li>' +
-                               '</ul></p>' );
+               var width = 800;
 
-                       var width = 800;
+               var data = {
+                       prefix: prefix,
+                       results: {
+                               tests: tests,
+                               noErrors: noErrors,
+                               syntacticDiffs: syntacticDiffs,
+                               perfects: perfects
+                       },
+                       graphWidths: {
+                               perfect: width * perfects / 100 || 0,
+                               syntacticDiff: width * ( syntacticDiffs - 
perfects ) / 100 || 0,
+                               semanticDiff: width * ( 100 - syntacticDiffs ) 
/ 100 || 0
+                       },
+                       latestRevision: [
+                               { description: 'Git SHA1', value: 
row[0].maxhash },
+                               { description: 'Test Results', value: 
row[0].maxresults },
+                               { description: 'Crashers', value: 
row[0].crashers,
+                                       url: '/crashers' },
+                               { description: 'Regressions', value: 
numRegressions,
+                                       url: '/regressions/between/' + 
row[0].maxhash },
+                               { description: 'Fixes', value: numFixes,
+                                       url: '/topfixes/between/' + 
row[0].secondhash + '/' + row[0].maxhash },
+                       ],
+                       averages: [
+                               { description: 'Errors', value: 
row[0].avgerrors },
+                               { description: 'Fails', value: row[0].avgfails 
},
+                               { description: 'Skips', value: row[0].avgskips 
},
+                               { description: 'Score', value: row[0].avgscore }
+                       ],
+                       pages: pageListData
+               };
 
-                       res.write( '<table><tr height=60px>');
-                       res.write( '<td width=' +
-                                       ( width * perfects / 100 || 0 ) +
-                                       'px style="background:green" 
title="Perfect / no diffs"></td>' );
-                       res.write( '<td width=' +
-                                       ( width * ( syntacticDiffs - perfects ) 
/ 100 || 0 ) +
-                                       'px style="background:yellow" 
title="Syntactic diffs"></td>' );
-                       res.write( '<td width=' +
-                                       ( width * ( 100 - syntacticDiffs ) / 
100 || 0 ) +
-                                       'px style="background:red" 
title="Semantic diffs"></td>' );
-                       res.write( '</tr></table>' );
+               // round numeric data, but ignore others
+               hbs.registerHelper('round', function (val) {
+                       if (isNaN( Math.round( val * 100 ) / 100 )) {
+                               return val;
+                       } else {
+                               return Math.round( val * 100 ) / 100;
+                       }
+               });
 
-                       res.write( '<p>Latest revision:' );
-                       res.write( '<table><tbody>');
-                       displayRow(res, "Git SHA1", row[0].maxhash);
-                       displayRow(res, "Test Results", row[0].maxresults);
-                       displayRow( res, "Crashers",
-                                  '<a href="/crashers">' + row[0].crashers + 
'</a>' );
-                       displayRow(res, "Regressions",
-                                  '<a href="/regressions/between/' + 
row[0].secondhash + '/' +
-                                  row[0].maxhash + '">' +
-                                  numRegressions + '</a>');
-                       displayRow(res, "Fixes",
-                                  '<a href="/topfixes/between/' + 
row[0].secondhash + '/' +
-                                  row[0].maxhash + '">' +
-                                  numFixes + '</a>');
-                       res.write( '</tbody></table></p>' );
-
-                       res.write( '<p>Averages (over the latest results):' );
-                       res.write( '<table><tbody>');
-                       displayRow(res, "Errors", row[0].avgerrors);
-                       displayRow(res, "Fails", row[0].avgfails);
-                       displayRow(res, "Skips", row[0].avgskips);
-                       displayRow(res, "Score", row[0].avgscore);
-                       res.write( '</tbody></table></p>' );
-                       res.write( indexLinkList() );
-
-                       res.end( '</body></html>' );
+               res.render('index.html', data);
                }
        });
 };
@@ -1360,6 +1338,12 @@
 // Make an app
 var app = express.createServer();
 
+// Configure for Handlebars
+app.configure(function(){
+       app.set('view engine', 'html');
+       app.register('html', require('hbs'));
+});
+
 // Make the coordinator app
 var coordApp = express.createServer();
 
diff --git a/tests/server/views/index.html b/tests/server/views/index.html
new file mode 100644
index 0000000..b13ba66
--- /dev/null
+++ b/tests/server/views/index.html
@@ -0,0 +1,77 @@
+<p>
+  We have run roundtrip-tests on <b>{{results.tests}}</b> articles, of which
+</p>
+<ul>
+  <li><b>{{results.noErrors}}%</b> parsed without errors,</li>
+  </li><b>{{results.syntacticDiffs}}%</b> round-tripped without semantic 
differences, and</li>
+  <li><b>{{results.perfects}}%</b> round-tripped with no character differences 
at all.</li>
+</ul>
+<p></p>
+  
+<table>
+  <tbody>
+    <tr height="60px">
+      <td width="{{graphWidths.perfect}}" style="background:green" 
title="Perfect / no diffs">
+      </td>
+      <td width="{{graphWidths.syntacticDiff}}" style="background:yellow" 
title="Syntactic diffs">
+      </td>
+      <td width="{{graphWidths.semanticDiff}}" style="background:red" 
title="Semantic diffs">
+      </td>
+    </tr>
+  </tbody>
+</table>
+
+<p>
+  Latest revision:
+  <table>
+    <tbody>
+      {{#each latestRevision}}
+      <tr style="font-weight:bold">
+        <td style="padding-left:20px">
+          {{description}}
+          {{#if ../prefix}}
+            ({{../../prefix}})
+          {{/if}}
+        </td>
+        <td style="padding-left:20px; text-align:right">
+          {{#if url}}
+            <a href='{{url}}'>
+          {{/if}}
+          {{round value}}
+          {{#if url}}
+            </a>
+          {{/if}}
+        </td>
+      </tr>
+      {{/each}}
+    </tbody>
+  </table>
+</p>
+
+<p>
+  Averages (over the latest results):
+  <table>
+    <tbody>
+      {{#each averages}}
+      <tr style="font-weight:bold">
+        <td style="padding-left:20px">
+          {{description}}
+          {{#if ../prefix}}
+            ({{../../prefix}})
+          {{/if}}
+        </td>
+        <td style="padding-left:20px; text-align:right">{{round value}}</td>
+      </tr>
+      {{/each}}
+    </tbody>
+  </table>
+</p>
+
+<p>More details:</p>
+<ul>
+  {{#each pages}}
+    <li>
+      <a href="{{url}}">{{title}}</a>
+    </li>
+  {{/each}}
+</ul>
\ No newline at end of file
diff --git a/tests/server/views/layout.html b/tests/server/views/layout.html
new file mode 100644
index 0000000..2b24982
--- /dev/null
+++ b/tests/server/views/layout.html
@@ -0,0 +1,7 @@
+<html>
+  <head>
+  </head>
+  <body>
+    {{{body}}}
+  </body>
+</html>
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifc0f7714bb8180e1152478756c890d54177b400c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Bebirchall <[email protected]>

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

Reply via email to