Skip to content

Commit

Permalink
feat: add more WIP toward composite column
Browse files Browse the repository at this point in the history
For #348.

Came out of phetsims/qa#869.
  • Loading branch information
liammulh committed Feb 8, 2023
1 parent ffcf4d1 commit 1cb05ee
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 45 deletions.
18 changes: 2 additions & 16 deletions src/client/components/TranslationReportTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,10 @@ const TranslationReportTable = ( { locale, localeName, wantsUntranslated } ) =>
: <></>
}
</th>
<th>Sim-Specific Strings
<th>Translated Strings
{
reportPopulated && reportRows.length > 1
? <SortButton onClick={() => handleSortButtonClick( SortKeyEnum.SIM_SPECIFIC_PERCENT )}/>
: <></>
}
</th>
<th>Shared Strings
{
reportPopulated && reportRows.length > 1
? <SortButton onClick={() => handleSortButtonClick( SortKeyEnum.SHARED_PERCENT )}/>
: <></>
}
</th>
<th>Common Strings
{
reportPopulated && reportRows.length > 1
? <SortButton onClick={() => handleSortButtonClick( SortKeyEnum.COMMON_PERCENT )}/>
? <SortButton onClick={() => handleSortButtonClick( 'gonna need to change this' )}/>
: <></>
}
</th>
Expand Down
4 changes: 4 additions & 0 deletions src/client/img/info-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous">
</script>
<!-- popper is needed for tooltips. -->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p"
crossorigin="anonymous">
</script>
</head>
<body>
<div id="root">
Expand Down
7 changes: 4 additions & 3 deletions src/client/js/SortKeyEnum.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

const SortKeyEnum = {
SIM_TITLE: [ 'simTitle' ],
SIM_SPECIFIC_PERCENT: [ 'simSpecificPercent', 'numSimSpecificStrings' ],
COMMON_PERCENT: [ 'commonPercent', 'numCommonStrings' ],
SHARED_PERCENT: [ 'sharedPercent', 'numSharedStrings' ]
TOTAL_STRINGS: [ 'percentTotal, totalTranslatedStrings' ],
SIM_SPECIFIC_PERCENT: [ 'percentSimSpecific', 'numSimSpecificStrings' ],
COMMON_PERCENT: [ 'percentCommon', 'numCommonStrings' ],
SHARED_PERCENT: [ 'percentShared', 'numSharedStrings' ]
};

Object.freeze( SortKeyEnum );
Expand Down
48 changes: 28 additions & 20 deletions src/client/jsx/getTranslationReportRows.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Link } from 'react-router-dom';
import getMinutesElapsed from '../../common/getMinutesElapsed.js';
import publicConfig from '../../common/publicConfig.js';
import getSortedTranslationReportRows from './getSortedTranslationReportRows.jsx';
import infoCircle from '../img/info-circle.svg';

/**
* Return an array of translation report table rows, i.e. return an array of JSX. These rows are put into the
Expand Down Expand Up @@ -75,34 +76,41 @@ const getTranslationReportRows = (
}

// Create the row JSX.
const simSpecificPercent = Math.floor( ( reportObject.numSimSpecificTranslatedStrings / reportObject.numSimSpecificStrings ) * 100 );
let sharedPercent = 0;
const hasSharedStrings = reportObject.numSharedStrings !== null;
let sharedStatsString = 'N/A';
const commonPercent = Math.floor( ( reportObject.numCommonTranslatedStrings / reportObject.numCommonStrings ) * 100 );
if ( hasSharedStrings ) {
sharedPercent = Math.floor( ( reportObject.numSharedTranslatedStrings / reportObject.numSharedStrings ) * 100 );
sharedStatsString = `${sharedPercent}% (${reportObject.numSharedTranslatedStrings} of ${reportObject.numSharedStrings})`;
sharedStatsString = `${reportObject.percentShared}% (${reportObject.numSharedTranslatedStrings} of ${reportObject.numSharedStrings})`;
}
let totalStrings = reportObject.numSimSpecificStrings +
reportObject.numCommonStrings;
let totalTranslatedStrings = reportObject.numSimSpecificTranslatedStrings +
reportObject.numCommonTranslatedStrings;
if ( hasSharedStrings ) {
totalStrings += reportObject.numSharedStrings;
totalTranslatedStrings += reportObject.numSharedTranslatedStrings;
}
const simSpecificStatsString = `${simSpecificPercent}% (${reportObject.numSimSpecificTranslatedStrings} of ${reportObject.numSimSpecificStrings})`;
const commonStatsString = `${commonPercent}% (${reportObject.numCommonTranslatedStrings} of ${reportObject.numCommonStrings})`;
console.log( sharedStatsString );
console.log( simSpecificStatsString );
console.log( commonStatsString );
const totalPercent = Math.floor( ( totalTranslatedStrings / totalStrings ) * 100 );
const simSpecificStatsString = `${reportObject.percentSimSpecific}% (${reportObject.numSimSpecificTranslatedStrings} of ${reportObject.numSimSpecificStrings})`;
const commonStatsString = `${reportObject.percentCommon}% (${reportObject.numCommonTranslatedStrings} of ${reportObject.numCommonStrings})`;
const statsString = `Statistics for ${reportObject.simTitle}:
Sim-Specific Strings: ${simSpecificStatsString}
Shared Strings: ${sharedStatsString}
Common Strings: ${commonStatsString}`;
const buttonStyle = {
marginRight: '6px',
padding: '0'
};
const statsInfoJsx = (
<button
onClick={() => window.alert( statsString )}
style={buttonStyle}
type='button'
className='btn btn-light'
data-bs-toggle='tooltip'
data-bs-placement='top'
title={statsString}>
<img src={infoCircle} alt='info icon'/>
</button>
);
if ( Object.keys( translationReportJsx ).includes( reportObject.simName ) ) {
translationReportJsx[ reportObject.simName ] = (
<tr key={reportObject.simName}>
<td><Link to={`/translate/${locale}/${reportObject.simName}`}>{reportObject.simTitle}</Link>{pendingUpdate}</td>
<td>{totalPercent}% ({totalTranslatedStrings} of {totalStrings})</td>
<td>
{statsInfoJsx}
{reportObject.percentTotal}% ({reportObject.totalTranslatedStrings} of {reportObject.totalStrings})
</td>
</tr>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ import getCommonTranslatedStringKeysAndValues from './getCommonTranslatedStringK
import getSimSpecificEnglishStringKeysAndValues from './getSimSpecificEnglishStringKeysAndValues.js';
import getSimSpecificTranslatedStringKeysAndValues from './getSimSpecificTranslatedStringKeysAndValues.js';

const getPercent = ( numerator, denominator ) => {
let percent = null;
if ( numerator !== null && denominator !== null ) {
percent = Math.floor( ( numerator / denominator ) * 100 );
}
return percent;
};

const getTotalStrings = values => {
let total = 0;
for ( const value of values ) {
if ( value === null ) {
total += 0;
}
else {
total += value;
}
}
return total;
};

const getTranslationReportObject = async (
simName,
locale,
Expand All @@ -26,10 +47,16 @@ const getTranslationReportObject = async (
simTitle: simTitle,
numCommonStrings: null,
numCommonTranslatedStrings: null,
percentCommon: null,
numSimSpecificStrings: null,
numSimSpecificTranslatedStrings: wantsUntranslated === 'true' ? 0 : null,
percentSimSpecific: null,
numSharedStrings: null,
numSharedTranslatedStrings: null
numSharedTranslatedStrings: wantsUntranslated === 'true' ? 0 : null,
percentShared: null,
totalStrings: null,
totalTranslatedStrings: null,
percentTotal: null
};

// If the user is in development environment, and they set the short report
Expand All @@ -46,10 +73,37 @@ const getTranslationReportObject = async (
const DENOMINATOR_MAX = 100;
translationReportObject.numCommonStrings = getRandomInt( DENOMINATOR_MIN, DENOMINATOR_MAX );
translationReportObject.numCommonTranslatedStrings = getRandomInt( NUMERATOR_MIN, NUMERATOR_MAX );
translationReportObject.percentCommon = getPercent(
translationReportObject.numCommonTranslatedStrings,
translationReportObject.numCommonStrings
);
translationReportObject.numSimSpecificStrings = getRandomInt( DENOMINATOR_MIN, DENOMINATOR_MAX );
translationReportObject.numSimSpecificTranslatedStrings = wantsUntranslated === 'true' ? 0 : getRandomInt( DENOMINATOR_MIN, DENOMINATOR_MAX );
translationReportObject.percentSimSpecific = getPercent(
translationReportObject.numSimSpecificTranslatedStrings,
translationReportObject.numSimSpecificStrings
);
translationReportObject.numSharedStrings = getRandomInt( DENOMINATOR_MIN, DENOMINATOR_MAX );
translationReportObject.numSharedTranslatedStrings = getRandomInt( NUMERATOR_MIN, NUMERATOR_MAX );
translationReportObject.percentShared = getPercent(
translationReportObject.numSharedTranslatedStrings,
translationReportObject.numSharedStrings
);
translationReportObject.totalStrings = getTotalStrings( [
translationReportObject.numCommonStrings,
translationReportObject.numSimSpecificStrings,
translationReportObject.numSharedStrings
] );
translationReportObject.totalTranslatedStrings = getTotalStrings( [
translationReportObject.numCommonTranslatedStrings,
translationReportObject.numSimSpecificTranslatedStrings,
translationReportObject.numSharedTranslatedStrings
] );
translationReportObject.percentTotal = getPercent(
translationReportObject.totalTranslatedStrings,
translationReportObject.totalStrings
);

return translationReportObject;
}

Expand Down Expand Up @@ -82,6 +136,11 @@ const getTranslationReportObject = async (
.filter( key => commonTranslatedStringKeysAndValues[ key ] !== ''
&& commonEnglishStringKeysAndValues[ key ] !== noLongerUsedFlag ).length;

translationReportObject.percentCommon = getPercent(
translationReportObject.numCommonTranslatedStrings,
translationReportObject.numCommonStrings
);

const latestSimSha = await getLatestSimSha( simName );
const simSpecificEnglishStringKeysAndValues = await getSimSpecificEnglishStringKeysAndValues(
simName,
Expand All @@ -107,6 +166,11 @@ const getTranslationReportObject = async (
} ).length;
}

translationReportObject.percentSimSpecific = getPercent(
translationReportObject.numSimSpecificTranslatedStrings,
translationReportObject.numSimSpecificStrings
);

// If there are shared strings for this sim, we need to get the stats for those.
if ( categorizedStringKeys.shared.length > 0 ) {

Expand Down Expand Up @@ -156,15 +220,30 @@ const getTranslationReportObject = async (
&& sharedEnglishStringKeysAndValues[ key ] !== noLongerUsedFlag;
} ).length;
}
else {

// If we don't have a translation, this is zero.
translationReportObject.numSharedTranslatedStrings = 0;
}
}
}

translationReportObject.percentShared = getPercent(
translationReportObject.numSharedTranslatedStrings,
translationReportObject.numSharedStrings
);
}

translationReportObject.totalStrings = getTotalStrings( [
translationReportObject.numCommonStrings,
translationReportObject.numSimSpecificStrings,
translationReportObject.numSharedStrings
] );
translationReportObject.totalTranslatedStrings = getTotalStrings( [
translationReportObject.numCommonTranslatedStrings,
translationReportObject.numSimSpecificTranslatedStrings,
translationReportObject.numSharedTranslatedStrings
] );
translationReportObject.percentTotal = getPercent(
translationReportObject.totalTranslatedStrings,
translationReportObject.totalStrings
);

return translationReportObject;
};

Expand Down

0 comments on commit 1cb05ee

Please sign in to comment.