From 4e365983507ea7cbe7f92ef487db221cfcc3d1de Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 6 Jan 2022 16:22:11 +0900 Subject: [PATCH] Update statistics service --- .../domain/models/statistics/statistics.ts | 87 +-------------- .../models/statistics/statisticsRepository.ts | 7 +- .../pages/projects/_id/statistics/index.vue | 104 +++--------------- .../statistics/apiStatisticsRepository.ts | 20 +++- .../statisticsApplicationService.ts | 17 ++- .../application/statistics/statisticsData.ts | 20 ---- 6 files changed, 49 insertions(+), 206 deletions(-) diff --git a/frontend/domain/models/statistics/statistics.ts b/frontend/domain/models/statistics/statistics.ts index 9ec8b6ee..5e420e1c 100644 --- a/frontend/domain/models/statistics/statistics.ts +++ b/frontend/domain/models/statistics/statistics.ts @@ -1,87 +1,8 @@ export type Label = {[key: string]: number} - export type User = {[key: string]: number} - export type ConfirmedCount = {[key: string]: number} - -export class Statistics { - constructor( - public label: Label, - public userLabel: User, - public total: number, - public remaining: number, - public user: User, - public confirmedCount: ConfirmedCount, - ) {} - - static valueOf( - { label, user_label, total, remaining, user, confirmed_count }: - { - label: Label, - user_label: User, - total: number, - remaining: number, - user: User, - confirmed_count: ConfirmedCount, - } - ): Statistics { - return new Statistics(label, user_label, total, remaining, user, confirmed_count) - } - - private makeData(object: Label | User, label: string) { - const labels = object ? Object.keys(object) : [] - const counts = object ? Object.values(object) : [] - return { - labels, - datasets: [{ - label, - backgroundColor: '#00d1b2', - data: counts - }] - } - } - - public labelStats(label: string) { - return this.makeData(this.label, label) - } - - public userStats(label: string) { - return this.makeData(this.user, label) - } - - public progress(labels: string[]) { - const complete = this.total - this.remaining - const incomplete = this.remaining - return { - datasets: [{ - data: [complete, incomplete], - backgroundColor: ['#00d1b2', '#ffdd57'] - }], - labels - } - } - - private makeProgressData(roleName: string, labels: string[]) { - const confirmed = this.confirmedCount[roleName] - const unconfirmed = this.total - confirmed - return { - datasets: [{ - data: [confirmed, unconfirmed], - backgroundColor: ['#00d1b2', '#ffdd57'] - }], - labels - } - } - - public annotatorProgress(labels: string[]) { - return this.makeProgressData('annotator', labels) - } - - public approverProgress(labels: string[]) { - return this.makeProgressData('annotation_approver', labels) - } - - public adminProgress(labels: string[]) { - return this.makeProgressData('project_admin', labels) - } +export type Distribution = {[user: string]: {[label: string]: number}} +export interface Progress { + total: number + progress: {user: string, done: number}[] } diff --git a/frontend/domain/models/statistics/statisticsRepository.ts b/frontend/domain/models/statistics/statisticsRepository.ts index c7b6efb7..8aeb50a6 100644 --- a/frontend/domain/models/statistics/statisticsRepository.ts +++ b/frontend/domain/models/statistics/statisticsRepository.ts @@ -1,6 +1,7 @@ -import { Statistics } from '~/domain/models/statistics/statistics' +import { Distribution, Progress } from '~/domain/models/statistics/statistics' export interface StatisticsRepository { - - fetch(projectId: string): Promise + fetchCategoryDistribution(projectId: string): Promise + fetchSpanDistribution(projectId: string): Promise + fetchMemberProgress(projectId: string): Promise } diff --git a/frontend/pages/projects/_id/statistics/index.vue b/frontend/pages/projects/_id/statistics/index.vue index ef6c30b3..c3eb7ed3 100644 --- a/frontend/pages/projects/_id/statistics/index.vue +++ b/frontend/pages/projects/_id/statistics/index.vue @@ -1,109 +1,33 @@ diff --git a/frontend/repositories/statistics/apiStatisticsRepository.ts b/frontend/repositories/statistics/apiStatisticsRepository.ts index 2aa919bb..633d0696 100644 --- a/frontend/repositories/statistics/apiStatisticsRepository.ts +++ b/frontend/repositories/statistics/apiStatisticsRepository.ts @@ -1,15 +1,27 @@ import ApiService from '@/services/api.service' import { StatisticsRepository } from '@/domain/models/statistics/statisticsRepository' -import { Statistics } from '~/domain/models/statistics/statistics' +import { Distribution, Progress } from '~/domain/models/statistics/statistics' export class APIStatisticsRepository implements StatisticsRepository { constructor( private readonly request = ApiService ) {} - async fetch(projectId: string): Promise { - const url = `/projects/${projectId}/statistics` + async fetchCategoryDistribution(projectId: string): Promise { + const url = `/projects/${projectId}/category-distribution` const response = await this.request.get(url) - return Statistics.valueOf(response.data) + return response.data + } + + async fetchSpanDistribution(projectId: string): Promise { + const url = `/projects/${projectId}/span-distribution` + const response = await this.request.get(url) + return response.data + } + + async fetchMemberProgress(projectId: string): Promise { + const url = `/projects/${projectId}/member-progress` + const response = await this.request.get(url) + return response.data } } diff --git a/frontend/services/application/statistics/statisticsApplicationService.ts b/frontend/services/application/statistics/statisticsApplicationService.ts index 0441769a..bae36a1b 100644 --- a/frontend/services/application/statistics/statisticsApplicationService.ts +++ b/frontend/services/application/statistics/statisticsApplicationService.ts @@ -1,15 +1,20 @@ -import { StatisticsDTO } from './statisticsData' import { StatisticsRepository } from '~/domain/models/statistics/statisticsRepository' +import { Progress, Distribution } from '~/domain/models/statistics/statistics' export class StatisticsApplicationService { constructor( private readonly repository: StatisticsRepository ) {} - public async fetchStatistics( - projectId: string, labelText: string, userText: string, progressLabels: string[] - ): Promise { - const item = await this.repository.fetch(projectId) - return new StatisticsDTO(item, labelText, userText, progressLabels) + public async fetchMemberProgress(projectId: string): Promise { + return await this.repository.fetchMemberProgress(projectId) + } + + public async fetchCategoryDistribution(projectId: string): Promise { + return await this.repository.fetchCategoryDistribution(projectId) + } + + public async fetchSpanDistribution(projectId: string): Promise { + return await this.repository.fetchSpanDistribution(projectId) } } diff --git a/frontend/services/application/statistics/statisticsData.ts b/frontend/services/application/statistics/statisticsData.ts index 2a55c201..e69de29b 100644 --- a/frontend/services/application/statistics/statisticsData.ts +++ b/frontend/services/application/statistics/statisticsData.ts @@ -1,20 +0,0 @@ -import { Statistics } from '~/domain/models/statistics/statistics' - - -export class StatisticsDTO { - label: object; - user: object; - progress: object; - annotatorProgress: object; - approverProgress: object; - adminProgress: object; - - constructor(item: Statistics, labelText: string, userText: string, progressLabels: string[]) { - this.label = item.labelStats(labelText); - this.user = item.userStats(userText); - this.progress = item.progress(progressLabels); - this.annotatorProgress = item.annotatorProgress(progressLabels); - this.approverProgress = item.approverProgress(progressLabels); - this.adminProgress = item.adminProgress(progressLabels); - } -}