Skip to content

Commit

Permalink
Merge pull request #1561 from NicoPennec/fix/episode-stats
Browse files Browse the repository at this point in the history
Improve Stats pages
  • Loading branch information
frankrousseau authored Oct 25, 2024
2 parents 55c6c12 + e212714 commit a27ae95
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 44 deletions.
6 changes: 6 additions & 0 deletions src/components/cells/ValidationHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@
/>
<router-link
class="flexrow-item datatable-dropdown ellipsis task-type-name"
:title="
!hiddenColumns[columnId] ? taskTypeMap.get(columnId).name : null
"
:to="taskTypePath(columnId)"
v-if="!isCurrentUserClient"
>
{{ !hiddenColumns[columnId] ? taskTypeMap.get(columnId).name : '' }}
</router-link>
<span
class="flexrow-item datatable-dropdown ellipsis task-type-name"
:title="
!hiddenColumns[columnId] ? taskTypeMap.get(columnId).name : null
"
v-else
>
{{ !hiddenColumns[columnId] ? taskTypeMap.get(columnId).name : '' }}
Expand Down
9 changes: 7 additions & 2 deletions src/components/lists/EpisodeStatsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@
:style="getValidationStyle(columnId)"
>
<router-link
class="flexrow-item"
class="flexrow-item ellipsis"
:title="taskTypeMap.get(columnId).name"
:to="taskTypePath(columnId)"
v-if="!isCurrentUserClient"
>
{{ taskTypeMap.get(columnId).name }}
</router-link>
<span class="flexrow-item" v-else>
<span
class="flexrow-item ellipsis"
:title="taskTypeMap.get(columnId).name"
v-else
>
{{ taskTypeMap.get(columnId).name }}
</span>
</div>
Expand Down
9 changes: 7 additions & 2 deletions src/components/lists/ProductionAssetTypeList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@
:style="getValidationStyle(columnId)"
>
<router-link
class="flexrow-item"
class="flexrow-item ellipsis"
:title="taskTypeMap.get(columnId).name"
:to="taskTypePath(columnId)"
v-if="!isCurrentUserClient"
>
{{ taskTypeMap.get(columnId).name }}
</router-link>
<span class="flexrow-item" v-else>
<span
class="flexrow-item ellipsis"
:title="taskTypeMap.get(columnId).name"
v-else
>
{{ taskTypeMap.get(columnId).name }}
</span>
</div>
Expand Down
9 changes: 7 additions & 2 deletions src/components/lists/SequenceStatsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@
:style="getValidationStyle(columnId)"
>
<router-link
class="flexrow-item"
class="flexrow-item ellipsis"
:title="taskTypeMap.get(columnId).name"
:to="taskTypePath(columnId)"
v-if="!isCurrentUserClient"
>
{{ taskTypeMap.get(columnId).name }}
</router-link>
<span class="flexrow-item" v-else>
<span
class="flexrow-item ellipsis"
:title="taskTypeMap.get(columnId).name"
v-else
>
{{ taskTypeMap.get(columnId).name }}
</span>
</div>
Expand Down
7 changes: 5 additions & 2 deletions src/components/pages/EpisodeStats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
/>
<button-simple
class="flexrow-item"
:disabled="isLoading"
icon="download"
@click="exportStatisticsToCsv"
/>
Expand Down Expand Up @@ -234,7 +235,8 @@ export default {
this.taskTypeMap,
this.taskStatusMap,
this.episodeMap,
this.countMode
this.countMode,
this.currentProduction
)
} else {
csv.generateStatReports(
Expand All @@ -243,7 +245,8 @@ export default {
this.taskTypeMap,
this.taskStatusMap,
this.episodeMap,
this.countMode
this.countMode,
this.currentProduction
)
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/components/pages/ProductionAssetTypes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ export default {
this.taskTypeMap,
this.taskStatusMap,
this.assetTypeMap,
this.countMode
this.countMode,
this.currentProduction
)
},
Expand Down
3 changes: 2 additions & 1 deletion src/components/pages/SequenceStats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ export default {
this.taskTypeMap,
this.taskStatusMap,
this.sequenceMap,
this.countMode
this.countMode,
this.currentProduction
)
},
Expand Down
89 changes: 58 additions & 31 deletions src/lib/csv.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Papa from 'papaparse'

import { getTaskTypePriorityOfProd } from '@/lib/productions'
import { getPercentage } from '@/lib/stats'
import stringHelpers from '@/lib/string'
import {
Expand Down Expand Up @@ -128,8 +129,7 @@ const csv = {

buildCsvFile(name, entries) {
const csvContent = csv.turnEntriesToCsvString(entries)
const result =
'data:text/csv;charset=utf-8,' + encodeURIComponent(csvContent)
const result = `data:text/csv;charset=utf-8,${encodeURIComponent(csvContent)}`
const link = document.createElement('a')
link.setAttribute('href', result)
link.setAttribute('download', `${name}.csv`)
Expand All @@ -144,22 +144,28 @@ const csv = {
taskTypeMap,
taskStatusMap,
entryMap,
countMode
countMode,
production
) {
const headers = csv.getStatReportsHeaders(mainStats, taskTypeMap)
const headers = csv.getStatReportsHeaders(
mainStats,
taskTypeMap,
production
)
const entries = csv.getStatReportsEntries(
mainStats,
taskTypeMap,
taskStatusMap,
entryMap,
countMode
countMode,
production
)
const lines = [headers, ...entries]
return csv.buildCsvFile(name, lines)
},

getStatReportsHeaders(mainStats, taskTypeMap) {
const taskTypeIds = getStatsTaskTypeIds(mainStats, taskTypeMap)
getStatReportsHeaders(mainStats, taskTypeMap, production) {
const taskTypeIds = getStatsTaskTypeIds(mainStats, taskTypeMap, production)
const initialHeaders = ['Name', '', 'All', '']
return taskTypeIds.reduce((acc, taskTypeId) => {
if (taskTypeId !== 'all') {
Expand All @@ -176,10 +182,11 @@ const csv = {
taskTypeMap,
taskStatusMap,
entryMap,
countMode = 'count'
countMode = 'count',
production
) {
let entries = []
const taskTypeIds = getStatsTaskTypeIds(mainStats, taskTypeMap)
const taskTypeIds = getStatsTaskTypeIds(mainStats, taskTypeMap, production)
const entryIds = getStatsEntryIds(mainStats, entryMap)

entryIds.forEach(entryId => {
Expand Down Expand Up @@ -246,15 +253,21 @@ const csv = {
taskTypeMap,
taskStatusMap,
entryMap,
countMode
countMode,
production
) {
const headers = csv.getStatReportsHeaders(mainStats, taskTypeMap)
const headers = csv.getStatReportsHeaders(
mainStats,
taskTypeMap,
production
)
const entries = csv.getRetakeStatReportsEntries(
mainStats,
taskTypeMap,
taskStatusMap,
entryMap,
countMode
countMode,
production
)
const lines = [headers, ...entries]
return csv.buildCsvFile(name, lines)
Expand All @@ -265,10 +278,11 @@ const csv = {
taskTypeMap,
taskStatusMap,
entryMap,
countMode = 'count'
countMode = 'count',
production
) {
let entries = []
const taskTypeIds = getStatsTaskTypeIds(mainStats, taskTypeMap)
const taskTypeIds = getStatsTaskTypeIds(mainStats, taskTypeMap, production)
const entryIds = getStatsEntryIds(mainStats, entryMap)

entryIds.forEach(entryId => {
Expand All @@ -293,13 +307,7 @@ const csv = {
)

taskTypeIds.forEach(taskTypeId => {
if (taskTypeId === 'all') {
Object.keys(mainStats[entryId].all).forEach(taskStatusId => {
if (!['max_retake_count', 'evolution'].includes(taskStatusId)) {
lineMap[taskStatusId] = lineMap[taskStatusId].concat(['', ''])
}
})
} else {
if (taskTypeId !== 'all') {
const taskTypeStats = mainStats[entryId][taskTypeId]
if (taskTypeStats) {
const total = getStatsTotalEntryCount(
Expand All @@ -319,6 +327,12 @@ const csv = {
lineMap
)
}
} else {
Object.keys(mainStats[entryId].all).forEach(taskStatusId => {
if (!['max_retake_count', 'evolution'].includes(taskStatusId)) {
lineMap[taskStatusId] = lineMap[taskStatusId].concat(['', ''])
}
})
}
})

Expand Down Expand Up @@ -413,24 +427,37 @@ const csv = {
}
}

const getStatsTaskTypeIds = (mainStats, taskTypeMap) => {
const getStatsTaskTypeIds = (mainStats, taskTypeMap, production) => {
return Object.keys(mainStats.all)
.filter(taskTypeId => taskTypeId !== 'evolution')
.sort((a, b) => {
if (a === 'all') return 1
if (b === 'all') return -1
return taskTypeMap.get(a).priority - taskTypeMap.get(b).priority
const taskTypeA = taskTypeMap.get(a)
const taskTypeB = taskTypeMap.get(b)
const taskTypeAPriority = getTaskTypePriorityOfProd(taskTypeA, production)
const taskTypeBPriority = getTaskTypePriorityOfProd(taskTypeB, production)
if (taskTypeAPriority === taskTypeBPriority) {
return taskTypeA.name.localeCompare(taskTypeB.name, undefined, {
numeric: true
})
}
return taskTypeAPriority - taskTypeBPriority
})
}

const getStatsEntryIds = (mainStats, entryMap) => {
return Object.keys(mainStats).sort((a, b) => {
if (a === 'all') return -1
if (b === 'all') return 1
return entryMap.get(a).name.localeCompare(entryMap.get(b).name, undefined, {
numeric: true
return Object.keys(mainStats)
.filter(entryId => entryId === 'all' || entryMap.get(entryId))
.sort((a, b) => {
if (a === 'all') return -1
if (b === 'all') return 1
return entryMap
.get(a)
.name.localeCompare(entryMap.get(b).name, undefined, {
numeric: true
})
})
})
}

const getStatsTotalCount = (mainStats, taskStatusIds, countMode, entryId) => {
Expand Down Expand Up @@ -485,7 +512,7 @@ const buildTotalLines = (
name,
taskStatusName,
count || '0',
percentage + '%'
`${percentage}%`
]
})
return lineMap
Expand All @@ -507,7 +534,7 @@ const addEntryStatusStats = (
const percentage = getPercentage(count, total)
lineMap[taskStatusId] = lineMap[taskStatusId].concat([
count || '0',
percentage + '%'
`${percentage}%`
])
})
}
Expand Down
8 changes: 5 additions & 3 deletions src/store/modules/episodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,12 @@ const actions = {

loadEpisodeStats({ commit, rootGetters }, productionId) {
const taskTypeMap = rootGetters.taskTypeMap
commit(SET_EPISODE_STATS, { episodeStats: {}, taskTypeMap })
const production = rootGetters.currentProduction
commit(SET_EPISODE_STATS, { episodeStats: {}, taskTypeMap, production })
return shotsApi
.getEpisodeStats(productionId)
.then(episodeStats => {
commit(SET_EPISODE_STATS, { episodeStats, taskTypeMap })
commit(SET_EPISODE_STATS, { episodeStats, taskTypeMap, production })
return Promise.resolve(episodeStats)
})
.catch(console.error)
Expand Down Expand Up @@ -842,7 +843,8 @@ const mutations = {
) {
state.episodeValidationColumns = helpers.sortStatColumns(
episodeRetakeStats,
taskTypeMap
taskTypeMap,
production
)
state.episodeRetakeStats = episodeRetakeStats
},
Expand Down

0 comments on commit a27ae95

Please sign in to comment.