Skip to content

Commit

Permalink
Specify distributions in scene models, see #164
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed May 4, 2023
1 parent 68b4835 commit f46ab53
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
8 changes: 5 additions & 3 deletions js/common/model/CAVSceneModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class CAVSceneModel implements TModel {
// Starting at 0, iterate through the index of the kickers. This updates the SoccerPlayer.isActiveProperty to show the current kicker
private readonly activeKickerIndexProperty: NumberProperty;

public constructor( options: { tandem: Tandem } ) {
public constructor( initialDistribution: ReadonlyArray<number>, options: { tandem: Tandem } ) {

const updateDataMeasures = () => this.updateDataMeasures();

Expand Down Expand Up @@ -177,7 +177,7 @@ export default class CAVSceneModel implements TModel {
this.hasKickableSoccerBallsProperty = new DerivedProperty( [ this.numberOfUnkickedBallsProperty ],
numberOfUnkickedBalls => numberOfUnkickedBalls > 0 );

this.distributionProperty = new Property( CAVSceneModel.chooseDistribution(), {
this.distributionProperty = new Property( initialDistribution, {
tandem: options.tandem.createTandem( 'distributionProperty' ),
phetioValueType: ArrayIO( NumberIO ),
phetioDocumentation: 'The distribution of probabilities of where the balls will land is represented as an un-normalized array of non-negative, floating-point numbers, one value for each location in the physical range',
Expand Down Expand Up @@ -278,6 +278,8 @@ export default class CAVSceneModel implements TModel {
* Resets the model.
*/
public reset(): void {

// TODO: This should only be in MedianSceneModel and MeanAndMedianSceneModel
this.distributionProperty.value = CAVSceneModel.chooseDistribution();

this.clearData();
Expand Down Expand Up @@ -384,7 +386,7 @@ export default class CAVSceneModel implements TModel {
}
}

private static chooseDistribution(): ReadonlyArray<number> {
public static chooseDistribution(): ReadonlyArray<number> {
return dotRandom.nextBoolean() ? CAVConstants.LEFT_SKEWED_DATA : CAVConstants.RIGHT_SKEWED_DATA;
}

Expand Down
2 changes: 1 addition & 1 deletion js/mean-and-median/model/MeanAndMedianModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class MeanAndMedianModel extends CAVModel {

public constructor( options: { tandem: Tandem } ) {

const scene = new CAVSceneModel( { tandem: options.tandem.createTandem( 'sceneModel' ) } );
const scene = new CAVSceneModel( CAVSceneModel.chooseDistribution(), { tandem: options.tandem.createTandem( 'sceneModel' ) } );
super( [ scene ], {
...options,
instrumentMeanPredictionProperty: true
Expand Down
2 changes: 1 addition & 1 deletion js/median/model/MedianModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class MedianModel extends CAVModel {
public readonly isSortingDataProperty: BooleanProperty;

public constructor( options: { tandem: Tandem } ) {
const scene = new CAVSceneModel( { tandem: options.tandem.createTandem( 'sceneModel' ) } );
const scene = new CAVSceneModel( CAVSceneModel.chooseDistribution(), { tandem: options.tandem.createTandem( 'sceneModel' ) } );
super( [ scene ], {
...options,
instrumentMeanPredictionProperty: false
Expand Down
29 changes: 14 additions & 15 deletions js/variability/model/VariabilityModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@ export default class VariabilityModel extends CAVModel {

public constructor( options: VariabilityModelOptions ) {

const sceneModels = [

// TODO: Each of these should have its own distribution
new VariabilitySceneModel( { tandem: options.tandem.createTandem( 'sceneModel1' ) } ),
new VariabilitySceneModel( { tandem: options.tandem.createTandem( 'sceneModel2' ) } ),
new VariabilitySceneModel( { tandem: options.tandem.createTandem( 'sceneModel3' ) } ),
new VariabilitySceneModel( { tandem: options.tandem.createTandem( 'sceneModel4' ) } )
];
super( sceneModels, options );

this.initialized = true;

this.variabilitySceneModels = sceneModels;

// TODO: When the selected scene model changes, make the old one invisible and make the new one visible, see https://github.com/phetsims/center-and-variability/issues/164

// this.selectedDistributionProperty.link( distribution => {
//
Expand All @@ -62,6 +47,20 @@ export default class VariabilityModel extends CAVModel {
// distribution === DistributionType.KICKER_3 ? [ 6, 9, 11, 14, 11, 8, 6, 5, 5, 5, 5, 5, 5, 5, 5 ] :
// /*KICKER_4*/ [ 5, 5, 5, 5, 5, 5, 5, 5, 6, 8, 11, 14, 11, 9, 6 ];
// } );
const sceneModels = [

// TODO: Each of these should have its own distribution
new VariabilitySceneModel( [ 0, 0, 0, 1, 3, 10, 18, 20, 18, 10, 3, 1, 0, 0, 0 ], { tandem: options.tandem.createTandem( 'sceneModel1' ) } ),
new VariabilitySceneModel( [ 5, 5, 10, 10, 25, 30, 40, 50, 40, 30, 25, 10, 10, 5, 5 ], { tandem: options.tandem.createTandem( 'sceneModel2' ) } ),
new VariabilitySceneModel( [ 6, 9, 11, 14, 11, 8, 6, 5, 5, 5, 5, 5, 5, 5, 5 ], { tandem: options.tandem.createTandem( 'sceneModel3' ) } ),
new VariabilitySceneModel( [ 5, 5, 5, 5, 5, 5, 5, 5, 6, 8, 11, 14, 11, 9, 6 ], { tandem: options.tandem.createTandem( 'sceneModel4' ) } )
];
super( sceneModels, options );

this.initialized = true;

this.variabilitySceneModels = sceneModels;


this.selectedVariabilityProperty = new EnumerationProperty( VariabilityMeasure.RANGE, {
tandem: options.tandem.createTandem( 'selectedVariabilityProperty' )
Expand Down
4 changes: 2 additions & 2 deletions js/variability/model/VariabilitySceneModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default class VariabilitySceneModel extends CAVSceneModel {

private readonly initialized: boolean = false;

public constructor( options: { tandem: Tandem } ) {
super( options );
public constructor( distribution: ReadonlyArray<number>, options: { tandem: Tandem } ) {
super( distribution, options );

this.maxValueProperty = new DerivedProperty( [ this.dataRangeProperty ], dataRange => {
return dataRange === null ? null : dataRange.max;
Expand Down

0 comments on commit f46ab53

Please sign in to comment.