Add number of word stats and stat section to DictionaryDetails
This commit is contained in:
parent
3b275ca765
commit
ae50f5f970
|
@ -108,3 +108,29 @@ export function addHelpfulPrototypes () {
|
||||||
export function characterIsUppercase (character) {
|
export function characterIsUppercase (character) {
|
||||||
return character === character.toUpperCase();
|
return character === character.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getWordsStats (words, partsOfSpeech) {
|
||||||
|
const wordStats = {
|
||||||
|
numberOfWords: [
|
||||||
|
{
|
||||||
|
name: 'Total',
|
||||||
|
value: words.length,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
partsOfSpeech.forEach(partOfSpeech => {
|
||||||
|
const wordsWithPartOfSpeech = words.filter(word => word.partOfSpeech === partOfSpeech);
|
||||||
|
wordStats.numberOfWords.push({
|
||||||
|
name: partOfSpeech,
|
||||||
|
value: wordsWithPartOfSpeech.length,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
wordStats.numberOfWords.push({
|
||||||
|
name: 'Unclassified',
|
||||||
|
value: words.filter(word => !partsOfSpeech.includes(word.partOfSpeech)).length,
|
||||||
|
});
|
||||||
|
|
||||||
|
return wordStats;
|
||||||
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@ export class MainDisplay extends Component {
|
||||||
partsOfSpeech={ dictionaryInfo.partsOfSpeech }
|
partsOfSpeech={ dictionaryInfo.partsOfSpeech }
|
||||||
details={ dictionaryInfo.details }
|
details={ dictionaryInfo.details }
|
||||||
settings={ dictionaryInfo.settings }
|
settings={ dictionaryInfo.settings }
|
||||||
|
stats={ dictionaryInfo.stats }
|
||||||
alphabeticalOrder={ dictionaryInfo.alphabeticalOrder }
|
alphabeticalOrder={ dictionaryInfo.alphabeticalOrder }
|
||||||
updateDisplay={ updateDisplay }
|
updateDisplay={ updateDisplay }
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -28,6 +28,7 @@ export class DictionaryDetails extends Component {
|
||||||
alphabeticalOrder: PropTypes.array,
|
alphabeticalOrder: PropTypes.array,
|
||||||
details: PropTypes.object,
|
details: PropTypes.object,
|
||||||
settings: PropTypes.object,
|
settings: PropTypes.object,
|
||||||
|
stats: PropTypes.array,
|
||||||
updater: PropTypes.object,
|
updater: PropTypes.object,
|
||||||
updateDisplay: PropTypes.func,
|
updateDisplay: PropTypes.func,
|
||||||
}, props, 'prop', 'DictionaryDetails');
|
}, props, 'prop', 'DictionaryDetails');
|
||||||
|
@ -87,8 +88,26 @@ export class DictionaryDetails extends Component {
|
||||||
|
|
||||||
case DISPLAY.STATS : {
|
case DISPLAY.STATS : {
|
||||||
displayJSX = (
|
displayJSX = (
|
||||||
<div className="content">
|
<div className='columns'>
|
||||||
<p>Stats!</p>
|
<div className='column'>
|
||||||
|
<strong>Number of Words</strong>
|
||||||
|
<div className='field is-grouped is-grouped-multiline'>
|
||||||
|
{this.props.stats.numberOfWords.map(stat => {
|
||||||
|
return (
|
||||||
|
<div className='control'>
|
||||||
|
<div className='tags has-addons'>
|
||||||
|
<span className='tag'>
|
||||||
|
{ stat.name }
|
||||||
|
</span>
|
||||||
|
<span className='tag is-white'>
|
||||||
|
{ stat.value }
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -4,7 +4,7 @@ import './sass/main.scss';
|
||||||
import Inferno from 'inferno';
|
import Inferno from 'inferno';
|
||||||
import Component from 'inferno-component';
|
import Component from 'inferno-component';
|
||||||
|
|
||||||
import { addHelpfulPrototypes } from './Helpers';
|
import { addHelpfulPrototypes, getWordsStats } from './Helpers';
|
||||||
addHelpfulPrototypes();
|
addHelpfulPrototypes();
|
||||||
|
|
||||||
import dictionary from './managers/DictionaryData';
|
import dictionary from './managers/DictionaryData';
|
||||||
|
@ -29,6 +29,7 @@ class App extends Component {
|
||||||
partsOfSpeech: dictionary.partsOfSpeech,
|
partsOfSpeech: dictionary.partsOfSpeech,
|
||||||
details: dictionary.details,
|
details: dictionary.details,
|
||||||
settings: dictionary.settings,
|
settings: dictionary.settings,
|
||||||
|
stats: [],
|
||||||
alphabeticalOrder: dictionary.alphabeticalOrder,
|
alphabeticalOrder: dictionary.alphabeticalOrder,
|
||||||
|
|
||||||
displayedWords: [],
|
displayedWords: [],
|
||||||
|
@ -48,6 +49,7 @@ class App extends Component {
|
||||||
partsOfSpeech,
|
partsOfSpeech,
|
||||||
details,
|
details,
|
||||||
settings,
|
settings,
|
||||||
|
stats,
|
||||||
alphabeticalOrder,
|
alphabeticalOrder,
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
|
||||||
|
@ -58,6 +60,7 @@ class App extends Component {
|
||||||
partsOfSpeech,
|
partsOfSpeech,
|
||||||
details,
|
details,
|
||||||
settings,
|
settings,
|
||||||
|
stats,
|
||||||
alphabeticalOrder,
|
alphabeticalOrder,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -72,10 +75,11 @@ class App extends Component {
|
||||||
// const {searchIn, searchTerm, filteredPartsOfSpeech} = this.state.searchConfig;
|
// const {searchIn, searchTerm, filteredPartsOfSpeech} = this.state.searchConfig;
|
||||||
|
|
||||||
// TODO: Sort out searching to remove this temporary solution.
|
// TODO: Sort out searching to remove this temporary solution.
|
||||||
dictionary.wordsPromise.then((words) => {
|
dictionary.wordsPromise.then(words => {
|
||||||
this.setState({
|
this.setState({
|
||||||
displayedWords: words,
|
displayedWords: words,
|
||||||
})
|
stats: getWordsStats(words, this.state.partsOfSpeech),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue