diff --git a/client/src/views/show/config/ConfigCharacters.vue b/client/src/views/show/config/ConfigCharacters.vue index fbb540a1..8f4ebb25 100644 --- a/client/src/views/show/config/ConfigCharacters.vue +++ b/client/src/views/show/config/ConfigCharacters.vue @@ -5,58 +5,67 @@ > -
Character List
- - - - - - + + + + + + + + + +
import { required } from 'vuelidate/lib/validators'; import { mapGetters, mapActions } from 'vuex'; +import CharacterLineStats from '@/vue_components/show/config/characters/CharacterLineStats.vue'; export default { name: 'ConfigCharacters', + components: { CharacterLineStats }, data() { return { rowsPerPage: 15, diff --git a/client/src/vue_components/show/config/characters/CharacterLineStats.vue b/client/src/vue_components/show/config/characters/CharacterLineStats.vue new file mode 100644 index 00000000..4490c5e2 --- /dev/null +++ b/client/src/vue_components/show/config/characters/CharacterLineStats.vue @@ -0,0 +1,176 @@ + + + diff --git a/server/controllers/api/show/characters.py b/server/controllers/api/show/characters.py index fa621223..1b7eede2 100644 --- a/server/controllers/api/show/characters.py +++ b/server/controllers/api/show/characters.py @@ -1,5 +1,8 @@ +from collections import defaultdict + from tornado import escape +from models.script import Script, ScriptRevision, ScriptLine from models.show import Show, Cast, Character, CharacterGroup from rbac.role import Role from schemas.schemas import CharacterSchema, CharacterGroupSchema @@ -154,6 +157,46 @@ async def delete(self): await self.finish({'message': '404 show not found'}) +@ApiRoute('show/character/stats', ApiVersion.V1) +class CharacterStatsController(BaseAPIController): + async def get(self): + current_show = self.get_current_show() + show_id = current_show['id'] + + with self.make_session() as session: + show: Show = session.query(Show).get(show_id) + if show: + script: Script = session.query(Script).filter(Script.show_id == show.id).first() + + if script.current_revision: + revision: ScriptRevision = session.query(ScriptRevision).get( + script.current_revision) + else: + self.set_status(400) + await self.finish({'message': 'Script does not have a current revision'}) + return + + line_counts = defaultdict(lambda: defaultdict(lambda: defaultdict(int))) + for line_association in revision.line_associations: + line: ScriptLine = line_association.line + if line.stage_direction: + continue + for line_part in line.line_parts: + if line_part.line_part_cuts is not None: + continue + if line_part.character_id: + line_counts[line_part.character_id][line.act_id][line.scene_id] += 1 + elif line_part.character_group_id: + for character in line_part.character_group.characters: + line_counts[character.id][line.act_id][line.scene_id] += 1 + + self.set_status(200) + await self.finish({'line_counts': line_counts}) + else: + self.set_status(404) + await self.finish({'message': '404 show not found'}) + + @ApiRoute('show/character/group', ApiVersion.V1) class CharacterGroupController(BaseAPIController):