Skip to content

Commit

Permalink
Restructuring experimental CT interface to using modules, see #88
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Apr 16, 2020
1 parent 4a3f3a3 commit d44fa32
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 17 deletions.
5 changes: 3 additions & 2 deletions html/local-report.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
<script src="../../sherpa/lib/himalaya-0.2.7.js"></script>
<script src="../../sherpa/lib/he-1.1.1.js"></script>
<script src="../../query-string-machine/js/QueryStringMachine.js"></script>
<script src="../../scenery/build/scenery.min.js"></script>
<script src="../js/local-report.js"></script>
<!-- <script src="../../scenery/build/scenery.min.js"></script> -->

<script type="module" src="../js/aqua-main.js"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions js/aqua-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright 2020, University of Colorado Boulder

import './report/reportModules.js';
File renamed without changes.
162 changes: 162 additions & 0 deletions js/report/reportModules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Copyright 2020, University of Colorado Boulder

/**
* Displays a self-updating report of continuous test results
*
* @author Jonathan Olson <[email protected]>
*/

import Property from '../../../axon/js/Property.js';
import Display from '../../../scenery/js/display/Display.js';
import Node from '../../../scenery/js/nodes/Node.js';
import Rectangle from '../../../scenery/js/nodes/Rectangle.js';
import Text from '../../../scenery/js/nodes/Text.js';
import VBox from '../../../scenery/js/nodes/VBox.js';
import Color from '../../../scenery/js/util/Color.js';

window.assertions.enableAssert();

const options = QueryStringMachine.getAll( {
server: {
type: 'string',

// Origin for our server (ignoring current port), so that we don't require localhost
defaultValue: window.location.protocol + '//' + window.location.hostname
}
} );

const passColor = new Color( 60, 255, 60 );
const failColor = new Color( 255, 90, 90 );
const mixedColor = new Color( 255,210,80 );
const unincludedColor = new Color( 128, 128, 128 );
const untestedColor = new Color( 240, 240, 240 );

// Property.<string>
const snapshotStatusProperty = new Property( 'unknown status' );

snapshotStatusProperty.lazyLink( status => console.log( `Status: ${status}` ) );

(function snapshotStatusLoop() {
const req = new XMLHttpRequest();
req.onload = function() {
setTimeout( snapshotStatusLoop, 1000 );
snapshotStatusProperty.value = JSON.parse( req.responseText ).status;
};
req.onerror = function() {
setTimeout( snapshotStatusLoop, 1000 );
snapshotStatusProperty.value = 'Could not contact server';
};
req.open( 'get', options.server + '/aquaserver/snapshot-status', true );
req.send();
})();

// Property.<Object|null>
const reportProperty = new Property( {
snapshots: [],
testNames: []
} );

(function reportLoop() {
const req = new XMLHttpRequest();
req.onload = function() {
setTimeout( reportLoop, 20000 );
reportProperty.value = JSON.parse( req.responseText );
};
req.onerror = function() {
setTimeout( reportLoop, 20000 );
reportProperty.reset();
};
req.open( 'get', options.server + '/aquaserver/report', true );
req.send();
})();

const rootNode = new Node();
const display = new Display( rootNode, {
passiveEvents: true
} );

document.body.appendChild( display.domElement );

const statusNode = new Text( '', { fontSize: 14 } );
snapshotStatusProperty.link( status => {
statusNode.text = status;
} );

const reportNode = new Node();

rootNode.addChild( new VBox( {
spacing: 10,
align: 'left',
children: [ statusNode, reportNode ]
} ) );

reportProperty.link( report => {
const testLabels = report.testNames.map( names => new Text( names.join( ' : ' ), { fontSize: 12 } ) );

const padding = 3;

const snapshotLabels = report.snapshots.map( snapshot => new VBox( {
spacing: 2,
children: [
...new Date( snapshot.timestamp ).toLocaleString().replace( ',', '' ).replace( ' AM', 'am' ).replace( ' PM', 'pm' ).split( ' ' ).map( str => new Text( str, { fontSize: 10 } ) )
],
cursor: 'pointer'
} ) );

const maxTestLabelWidth = _.max( testLabels.map( node => node.width ) );
const maxTestLabelHeight = _.max( testLabels.map( node => node.height ) );
const maxSnapshotLabelWidth = _.max( snapshotLabels.map( node => node.width ) );
const maxSnapshotLabelHeight = _.max( snapshotLabels.map( node => node.height ) );

const snapshotsTestNodes = _.flatten( report.snapshots.map( ( snapshot, i ) => {
return report.testNames.map( ( names, j ) => {
const test = _.find( snapshot.tests, test => _.isEqual( names, test.names ) );

const background = new Rectangle( 0, 0, maxSnapshotLabelWidth, maxTestLabelHeight, {
x: maxTestLabelWidth + padding + i * ( maxSnapshotLabelWidth + padding ),
y: maxSnapshotLabelHeight + padding + j * ( maxTestLabelHeight + padding )
} );

if ( test ) {
if ( test.passCount > 0 && test.failCount === 0 ) {
background.fill = passColor;
}
else if ( test.passCount === 0 && test.failCount > 0 ) {
background.fill = failColor;
}
else if ( test.passCount === 0 && test.failCount === 0 ) {
background.fill = untestedColor;
}
else {
background.fill = mixedColor;
}
}
else {
background.fill = unincludedColor;
}

return background;
} );
} ) );

testLabels.forEach( ( label, i ) => {
label.left = 0;
label.top = i * ( maxTestLabelHeight + padding ) + maxSnapshotLabelHeight + padding;
} );
snapshotLabels.forEach( ( label, i ) => {
label.top = 0;
label.left = ( maxTestLabelWidth + padding ) + i * ( maxSnapshotLabelWidth + padding );
} );

reportNode.children = [
...testLabels,
...snapshotLabels,
...snapshotsTestNodes
];
} );

display.initializeEvents();
display.updateOnRequestAnimationFrame( dt => {
display.width = Math.ceil( rootNode.width );
display.height = Math.ceil( rootNode.height );
} );
12 changes: 6 additions & 6 deletions js/Snapshot.js → js/server/Snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

'use strict';

const copyDirectory = require( '../../perennial/js/common/copyDirectory' );
const createDirectory = require( '../../perennial/js/common/createDirectory' );
const deleteDirectory = require( '../../perennial/js/common/deleteDirectory' );
const execute = require( '../../perennial/js/common/execute' );
const getRepoList = require( '../../perennial/js/common/getRepoList' );
const gitRevParse = require( '../../perennial/js/common/gitRevParse' );
const copyDirectory = require( '../../../perennial/js/common/copyDirectory' );
const createDirectory = require( '../../../perennial/js/common/createDirectory' );
const deleteDirectory = require( '../../../perennial/js/common/deleteDirectory' );
const execute = require( '../../../perennial/js/common/execute' );
const getRepoList = require( '../../../perennial/js/common/getRepoList' );
const gitRevParse = require( '../../../perennial/js/common/gitRevParse' );
const Test = require( './Test' );
const fs = require( 'fs' );
const _ = require( 'lodash' ); // eslint-disable-line
Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 9 additions & 9 deletions js/local-server.js → js/server/continuous-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

'use strict';

const asyncFilter = require( '../../perennial/js/common/asyncFilter' );
const cloneMissingRepos = require( '../../perennial/js/common/cloneMissingRepos' );
const execute = require( '../../perennial/js/common/execute' );
const getRepoList = require( '../../perennial/js/common/getRepoList' );
const gitPull = require( '../../perennial/js/common/gitPull' );
const gruntCommand = require( '../../perennial/js/common/gruntCommand' );
const isStale = require( '../../perennial/js/common/isStale' );
const npmUpdate = require( '../../perennial/js/common/npmUpdate' );
const sleep = require( '../../perennial/js/common/sleep' );
const asyncFilter = require( '../../../perennial/js/common/asyncFilter' );
const cloneMissingRepos = require( '../../../perennial/js/common/cloneMissingRepos' );
const execute = require( '../../../perennial/js/common/execute' );
const getRepoList = require( '../../../perennial/js/common/getRepoList' );
const gitPull = require( '../../../perennial/js/common/gitPull' );
const gruntCommand = require( '../../../perennial/js/common/gruntCommand' );
const isStale = require( '../../../perennial/js/common/isStale' );
const npmUpdate = require( '../../../perennial/js/common/npmUpdate' );
const sleep = require( '../../../perennial/js/common/sleep' );
const Snapshot = require( './Snapshot' );
const fs = require( 'fs' );
const http = require( 'http' );
Expand Down

0 comments on commit d44fa32

Please sign in to comment.