|
1 | 1 | import { add } from './math'
|
2 | 2 |
|
3 |
| -// Update the store with the time spent while committing host effects |
4 |
| -const updateStore = (store, measure) => { |
5 |
| - if (measure.name.includes('⚛')) { |
6 |
| - const measureName = measure.name.split('⚛ ').join('') |
| 3 | +const COMMITTING_HOST_EFFECTS = 'Committing Host Effects' |
7 | 4 |
|
8 |
| - if (measureName.includes('Committing Host Effects')) { |
9 |
| - var totalEffects = Number(measureName.split(':')[1].split(' ')[1]) |
10 |
| - if (!store['Committing Host Effects']) { |
11 |
| - store['Committing Host Effects'] = { |
12 |
| - timeSpent: [], |
13 |
| - totalEffects: [] |
| 5 | +// Update the store with the time spent while committing host effects |
| 6 | +const getCommitHostEffectsTime = measures => { |
| 7 | + const measurementsByMatchingName = measures.filter( |
| 8 | + measure => |
| 9 | + measure.name.includes('⚛') && |
| 10 | + measure.name |
| 11 | + .split('⚛ ') |
| 12 | + .join('') |
| 13 | + .includes(COMMITTING_HOST_EFFECTS) |
| 14 | + ) |
| 15 | + |
| 16 | + return { |
| 17 | + [COMMITTING_HOST_EFFECTS]: { |
| 18 | + totalEffects: measurementsByMatchingName.map( |
| 19 | + measurementByMatchingName => { |
| 20 | + const measurementName = measurementByMatchingName.name |
| 21 | + .split('⚛ ') |
| 22 | + .join('') |
| 23 | + const effectValue = measurementName.split(':')[1].split(' ')[1] |
| 24 | + return Number(effectValue) |
14 | 25 | }
|
15 |
| - } |
16 |
| - |
17 |
| - store['Committing Host Effects'].timeSpent.push( |
18 |
| - Number(measure.duration.toFixed(2)) |
19 |
| - ) |
20 |
| - store['Committing Host Effects'].totalEffects.push(totalEffects) |
| 26 | + ), |
| 27 | + timeSpent: measurementsByMatchingName.map(measurementByMatchingName => { |
| 28 | + const durationValue = measurementByMatchingName.duration.toFixed(2) |
| 29 | + return Number(durationValue) |
| 30 | + }) |
21 | 31 | }
|
22 | 32 | }
|
23 |
| - |
24 |
| - return {} |
25 |
| -} |
26 |
| - |
27 |
| -const getCommitHostEffectsTime = measures => { |
28 |
| - let store = {} |
29 |
| - |
30 |
| - for (const measure of measures) { |
31 |
| - updateStore(store, measure) |
32 |
| - } |
33 |
| - |
34 |
| - return store |
35 | 33 | }
|
36 | 34 |
|
37 | 35 | // Get total number of host effects
|
38 |
| -const getTotalEffects = store => { |
39 |
| - let totalEffects = 0 |
40 |
| - |
41 |
| - for (const measure in store) { |
42 |
| - totalEffects = totalEffects || 0 |
43 |
| - totalEffects += add(store[measure].totalEffects) |
44 |
| - } |
45 |
| - |
46 |
| - return Number(totalEffects.toFixed(2)) |
47 |
| -} |
| 36 | +const getTotalEffects = store => |
| 37 | + Number(add(store[COMMITTING_HOST_EFFECTS].totalEffects)) |
48 | 38 |
|
49 | 39 | export { getTotalEffects, getCommitHostEffectsTime }
|
0 commit comments