From 3b7e3e391aac565172ae198163abbc9c964eacbc Mon Sep 17 00:00:00 2001 From: Chris Malley Date: Wed, 20 Jun 2018 11:52:56 -0600 Subject: [PATCH] clean up logging of NumberProperty values, #58 Signed-off-by: Chris Malley --- js/common/model/SingleSpringSystem.js | 2 +- js/common/model/Spring.js | 12 +++++++----- js/energy/model/EnergyModel.js | 8 ++++++-- js/intro/model/IntroModel.js | 6 ++++-- js/systems/model/ParallelSystem.js | 9 ++++++--- js/systems/model/SeriesSystem.js | 9 ++++++--- 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/js/common/model/SingleSpringSystem.js b/js/common/model/SingleSpringSystem.js index 812f2316..00d3c102 100644 --- a/js/common/model/SingleSpringSystem.js +++ b/js/common/model/SingleSpringSystem.js @@ -29,7 +29,7 @@ define( function( require ) { // Components of the system // @public spring - this.spring = new Spring( 'singleSpring', _.extend( {}, springOptions, { + this.spring = new Spring( _.extend( {}, springOptions, { tandem: tandem.createTandem( 'spring' ) } ) ); assert && assert( this.spring.displacementProperty.get() === 0 ); // spring is at equilibrium diff --git a/js/common/model/Spring.js b/js/common/model/Spring.js index b1a40d7a..205f11a9 100644 --- a/js/common/model/Spring.js +++ b/js/common/model/Spring.js @@ -45,16 +45,18 @@ define( function( require ) { var NumberIO = require( 'ifphetio!PHET_IO/types/NumberIO' ); /** - * @param {string} logName - name that appears in log messages * @param {Object} [options] * @constructor */ - function Spring( logName, options ) { + function Spring( options ) { var self = this; options = _.extend( { + // name that appears in log messages + logName: null, + // {number} x location of the left end of the spring, units = m left: 0, @@ -151,11 +153,11 @@ define( function( require ) { // log each PhET-iO instrumented NumberProperty value when it changes phet.log && this.appliedForceProperty.link( - function( appliedForce ) { phet.log( logName + ' appliedForce=' + appliedForce ); } ); + function( appliedForce ) { phet.log( options.logName + ' appliedForce=' + appliedForce ); } ); phet.log && this.springConstantProperty.link( - function( springConstant ) { phet.log( logName + ' springConstant=' + springConstant ); } ); + function( springConstant ) { phet.log( options.logName + ' springConstant=' + springConstant ); } ); phet.log && this.displacementProperty.link( - function( displacement ) { phet.log( logName + ' displacement=' + displacement ); } ); + function( displacement ) { phet.log( options.logName + ' displacement=' + displacement ); } ); //------------------------------------------------ // Derived properties diff --git a/js/energy/model/EnergyModel.js b/js/energy/model/EnergyModel.js index 5ccec075..3f4fd559 100644 --- a/js/energy/model/EnergyModel.js +++ b/js/energy/model/EnergyModel.js @@ -19,10 +19,14 @@ define( function( require ) { * @constructor */ function EnergyModel( tandem ) { - this.system = new SingleSpringSystem( tandem.createTandem( 'system' ), { + + var springOptions = { + logName: 'spring', springConstantRange: new RangeWithValue( 100, 400, 100 ), // units = N/m displacementRange: new RangeWithValue( -1, 1, 0 ) // units = m - } ); + }; + + this.system = new SingleSpringSystem( tandem.createTandem( 'system' ), springOptions ); } hookesLaw.register( 'EnergyModel', EnergyModel ); diff --git a/js/intro/model/IntroModel.js b/js/intro/model/IntroModel.js index 55a106b6..a737b619 100644 --- a/js/intro/model/IntroModel.js +++ b/js/intro/model/IntroModel.js @@ -26,8 +26,10 @@ define( function( require ) { }; // @public - this.system1 = new SingleSpringSystem( tandem.createTandem( 'system1' ), springOptions ); - this.system2 = new SingleSpringSystem( tandem.createTandem( 'system2' ), springOptions ); + this.system1 = new SingleSpringSystem( tandem.createTandem( 'system1' ), + _.extend( {}, springOptions, { logName: 'spring1' } ) ); + this.system2 = new SingleSpringSystem( tandem.createTandem( 'system2' ), + _.extend( {}, springOptions, { logName: 'spring2' } ) ); } hookesLaw.register( 'IntroModel', IntroModel ); diff --git a/js/systems/model/ParallelSystem.js b/js/systems/model/ParallelSystem.js index a79dd5a8..4e1cf58e 100644 --- a/js/systems/model/ParallelSystem.js +++ b/js/systems/model/ParallelSystem.js @@ -45,7 +45,8 @@ define( function( require ) { // Components of the system // @public - this.topSpring = new Spring( 'topSpring', { + this.topSpring = new Spring( { + logName: 'topSpring', left: 0, // x location of the left end of the spring, units = m equilibriumLength: 1.5, // length of the spring at equilibrium, units = m springConstantRange: new RangeWithValue( 200, 600, 200 ), // range and initial value of k1, units = N/m @@ -56,7 +57,8 @@ define( function( require ) { } ); // @public bottom spring, in parallel with top spring, with identical configuration - this.bottomSpring = new Spring( 'bottomSpring', { + this.bottomSpring = new Spring( { + logName: 'bottomSpring', left: this.topSpring.leftProperty.get(), equilibriumLength: this.topSpring.equilibriumLength, springConstantRange: this.topSpring.springConstantRange, @@ -73,7 +75,8 @@ define( function( require ) { 'top and bottom springs must have same equilibrium position' ); // @public the single spring that is equivalent to the 2 springs in parallel - this.equivalentSpring = new Spring( 'equivalentSpring', { + this.equivalentSpring = new Spring( { + logName: 'equivalentSpring', left: this.topSpring.leftProperty.get(), equilibriumLength: this.topSpring.equilibriumLength, // keq = k1 + k2 diff --git a/js/systems/model/SeriesSystem.js b/js/systems/model/SeriesSystem.js index 34515f72..9fcbcad6 100644 --- a/js/systems/model/SeriesSystem.js +++ b/js/systems/model/SeriesSystem.js @@ -44,7 +44,8 @@ define( function( require ) { // Components of the system // @public left spring - this.leftSpring = new Spring( 'leftSpring', { + this.leftSpring = new Spring( { + logName: 'leftSpring', left: 0, // x location of the left end of the spring, units = m equilibriumLength: 0.75, // length of the spring at equilibrium, units = m springConstantRange: new RangeWithValue( 200, 600, 200 ), // range and initial value of k1, units = N/m @@ -54,7 +55,8 @@ define( function( require ) { } ); // @public right spring, in series with the left spring, with identical configuration - this.rightSpring = new Spring( 'rightSpring', { + this.rightSpring = new Spring( { + logName: 'rightSpring', left: this.leftSpring.rightProperty.get(), // attached to the right end of the left spring equilibriumLength: this.leftSpring.equilibriumLength, springConstantRange: this.leftSpring.springConstantRange, @@ -64,7 +66,8 @@ define( function( require ) { } ); // @public the single spring that is equivalent to the 2 springs in series - this.equivalentSpring = new Spring( 'equivalentSpring', { + this.equivalentSpring = new Spring( { + logName: 'equivalentSpring', left: this.leftSpring.leftProperty.get(), equilibriumLength: this.leftSpring.equilibriumLength + this.rightSpring.equilibriumLength, // keq = 1 / ( 1/k1 + 1/k2 )