Add interval modifiers
This commit is contained in:
parent
492918d7f1
commit
002c8c45f3
@ -9,7 +9,7 @@ import { PlayerControl } from './PlayerControl'
|
|||||||
import styles from './RsvpReader.css'
|
import styles from './RsvpReader.css'
|
||||||
import { BorderMarker } from './PivotMarker'
|
import { BorderMarker } from './PivotMarker'
|
||||||
import { Progress } from './Progress'
|
import { Progress } from './Progress'
|
||||||
import { TimeCalc } from './TimeCalc'
|
import { TotalTime } from './TotalTime'
|
||||||
|
|
||||||
export const RsvpReader = () => {
|
export const RsvpReader = () => {
|
||||||
return (
|
return (
|
||||||
@ -28,7 +28,7 @@ export const RsvpReader = () => {
|
|||||||
</SegmentControl>
|
</SegmentControl>
|
||||||
</div>
|
</div>
|
||||||
<Options></Options>
|
<Options></Options>
|
||||||
<TimeCalc />
|
<TotalTime />
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.item}>{/* <TextOutput /> */}</div>
|
<div className={styles.item}>{/* <TextOutput /> */}</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useSelector } from 'react-redux'
|
import { useSelector } from 'react-redux'
|
||||||
import { selectSegments, selectWpm } from '../store/selectors'
|
import { selectTotalTime } from '../store/selectors'
|
||||||
|
|
||||||
function formatTime(totalSeconds) {
|
function formatTime(totalSeconds) {
|
||||||
const hours = Math.floor(totalSeconds / 3600)
|
const hours = Math.floor(totalSeconds / 3600)
|
||||||
@ -10,14 +10,12 @@ function formatTime(totalSeconds) {
|
|||||||
return `${hours}:${pad(minutes)}:${pad(seconds)}`
|
return `${hours}:${pad(minutes)}:${pad(seconds)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TimeCalc = () => {
|
export const TotalTime = () => {
|
||||||
const wpm = useSelector(selectWpm)
|
const millis = useSelector(selectTotalTime)
|
||||||
const segments = useSelector(selectSegments)
|
|
||||||
const minutesNeeded = segments.length / wpm
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h2>Time needed</h2>
|
<h2>Time needed</h2>
|
||||||
Time needed for Text: {formatTime(minutesNeeded * 60)}
|
Time needed for Text: {formatTime(millis / 1000)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
36
src/lib/intervalModifier.js
Normal file
36
src/lib/intervalModifier.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
const commonWords = [
|
||||||
|
'I',
|
||||||
|
'he',
|
||||||
|
'she',
|
||||||
|
'it',
|
||||||
|
'you',
|
||||||
|
'the',
|
||||||
|
'a',
|
||||||
|
'to',
|
||||||
|
'of',
|
||||||
|
'and',
|
||||||
|
'in'
|
||||||
|
]
|
||||||
|
const punctuations = [
|
||||||
|
'.',
|
||||||
|
',',
|
||||||
|
':',
|
||||||
|
';',
|
||||||
|
'\\',
|
||||||
|
'=',
|
||||||
|
'/',
|
||||||
|
'*',
|
||||||
|
'’',
|
||||||
|
'(',
|
||||||
|
')',
|
||||||
|
'&'
|
||||||
|
]
|
||||||
|
|
||||||
|
export function intervalModifier(segment) {
|
||||||
|
// double the interval on punctuations
|
||||||
|
if (punctuations.some(el => segment.includes(el))) return 2
|
||||||
|
// half the interval on common words
|
||||||
|
if (commonWords.includes(segment)) return 0.5
|
||||||
|
// unmodified interval
|
||||||
|
return 1
|
||||||
|
}
|
@ -3,6 +3,7 @@ import { parseText } from '../lib/parseText'
|
|||||||
|
|
||||||
import { getNextBiggerNumber, getNextSmallerNumber } from '../lib/array-util.js'
|
import { getNextBiggerNumber, getNextSmallerNumber } from '../lib/array-util.js'
|
||||||
import { pivotize } from '../lib/pivotize'
|
import { pivotize } from '../lib/pivotize'
|
||||||
|
import { intervalModifier } from '../lib/intervalModifier'
|
||||||
|
|
||||||
// util
|
// util
|
||||||
const notNull = val => val != null
|
const notNull = val => val != null
|
||||||
@ -137,11 +138,27 @@ export const safeSelectPrevSentence = createSelector(
|
|||||||
(has, sentence, idx) => (has ? sentence : idx)
|
(has, sentence, idx) => (has ? sentence : idx)
|
||||||
)
|
)
|
||||||
|
|
||||||
// options
|
// options2
|
||||||
|
|
||||||
export const selectWpm = state => state.wpm
|
export const selectWpm = state => state.wpm
|
||||||
export const selectInterval = createSelector(selectWpm, wpm => 60000 / wpm)
|
|
||||||
export const selectOffset = state => state.offset
|
export const selectOffset = state => state.offset
|
||||||
|
export const selectBaseInterval = createSelector(selectWpm, wpm => 60000 / wpm)
|
||||||
|
|
||||||
|
export const selectIntervals = createSelector(
|
||||||
|
selectSegments,
|
||||||
|
selectBaseInterval,
|
||||||
|
(segments, interval) => segments.map(seg => interval * intervalModifier(seg))
|
||||||
|
)
|
||||||
|
|
||||||
|
export const selectInterval = createSelector(
|
||||||
|
selectIntervals,
|
||||||
|
selectCurrentSegmentIndex,
|
||||||
|
(intervals, idx) => intervals[idx]
|
||||||
|
)
|
||||||
|
|
||||||
|
export const selectTotalTime = createSelector(selectIntervals, intervals =>
|
||||||
|
intervals.reduce((a, b) => a + b, 0)
|
||||||
|
)
|
||||||
|
|
||||||
// player
|
// player
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user