Skip to content

Commit

Permalink
feat: add short report
Browse files Browse the repository at this point in the history
Part of #332.

Also part of phetsims/qa#869.
  • Loading branch information
liammulh committed Feb 8, 2023
1 parent d0644eb commit c455614
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2022, University of Colorado Boulder

import privateConfig from '../../../common/privateConfig.js';
import publicConfig from '../../../common/publicConfig.js';
import getCategorizedStringKeys from '../getCategorizedStringKeys.js';
import getLatestSimSha from '../getLatestSimSha.js';
import getSimHtml from '../getSimHtml.js';
Expand All @@ -26,6 +28,25 @@ const getTranslationReportObject = async (
numSimSpecificTranslatedStrings: wantsUntranslated === 'true' ? 0 : null
};

// If the user is in development environment, and they set the short report
// flag in their config file to true, just send a bunch of random data.
// We do this to short-circuit having to do all the HTTP requests and computations
// normally required for translation report objects.
if ( publicConfig.ENVIRONMENT === 'development' && privateConfig.SHORT_REPORT ) {
const getRandomInt = ( min, max ) => {
return Math.floor( Math.random() * ( max - min ) + min );
};
const NUMERATOR_MIN = 0;
const NUMERATOR_MAX = 20;
const DENOMINATOR_MIN = 20;
const DENOMINATOR_MAX = 100;
translationReportObject.numCommonStrings = getRandomInt( DENOMINATOR_MIN, DENOMINATOR_MAX );
translationReportObject.numCommonTranslatedStrings = getRandomInt( NUMERATOR_MIN, NUMERATOR_MAX );
translationReportObject.numSimSpecificStrings = getRandomInt( DENOMINATOR_MIN, DENOMINATOR_MAX );
translationReportObject.numSimSpecificTranslatedStrings = wantsUntranslated === 'true' ? 0 : getRandomInt( DENOMINATOR_MIN, DENOMINATOR_MAX );
return translationReportObject;
}

const simUrl = getSimUrl( simName );
const simHtml = await getSimHtml( simUrl );
const stringKeysWithRepoName = Object.keys( getStringKeysWithRepoName( simHtml ) );
Expand Down

0 comments on commit c455614

Please sign in to comment.