mirror of https://github.com/doccano/doccano.git
Browse Source
Merge pull request #1235 from doccano/enhancement/statistics
Merge pull request #1235 from doccano/enhancement/statistics
[Enhancement] statisticspull/1240/head
Hiroki Nakayama
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 135 additions and 25 deletions
Split View
Diff Options
-
59frontend/models/statistics.ts
-
43frontend/pages/projects/_id/statistics/index.vue
-
10frontend/plugins/services.ts
-
15frontend/repositories/statistics/api.ts
-
6frontend/repositories/statistics/interface.ts
-
27frontend/services/application/statistics.service.ts
@ -0,0 +1,59 @@ |
|||
export type Label = {[key: string]: number} |
|||
|
|||
export type User = {[key: string]: number} |
|||
|
|||
export class Statistics { |
|||
constructor( |
|||
public label: Label, |
|||
public userLabel: User, |
|||
public total: number, |
|||
public remaining: number, |
|||
public user: User |
|||
) {} |
|||
|
|||
static valueOf( |
|||
{ label, user_label, total, remaining, user }: |
|||
{ |
|||
label: Label, |
|||
user_label: User, |
|||
total: number, |
|||
remaining: number, |
|||
user: User |
|||
} |
|||
): Statistics { |
|||
return new Statistics(label, user_label, total, remaining, user) |
|||
} |
|||
|
|||
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 |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
import ApiService from '@/services/api.service' |
|||
import { Statistics } from '@/models/statistics' |
|||
import { StatisticsRepository } from './interface' |
|||
|
|||
export class FromApiStatisticsRepository implements StatisticsRepository { |
|||
constructor( |
|||
private readonly request = ApiService |
|||
) {} |
|||
|
|||
async fetch(projectId: string): Promise<Statistics> { |
|||
const url = `/projects/${projectId}/statistics` |
|||
const response = await this.request.get(url) |
|||
return Statistics.valueOf(response.data) |
|||
} |
|||
} |
@ -0,0 +1,6 @@ |
|||
import { Statistics } from '@/models/statistics' |
|||
|
|||
export interface StatisticsRepository { |
|||
|
|||
fetch(projectId: string): Promise<Statistics> |
|||
} |
@ -0,0 +1,27 @@ |
|||
import { Statistics } from '@/models/statistics' |
|||
import { StatisticsRepository } from '@/repositories/statistics/interface' |
|||
|
|||
export class StatisticsDTO { |
|||
label: object |
|||
user: object |
|||
progress: 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) |
|||
} |
|||
} |
|||
|
|||
export class StatisticsApplicationService { |
|||
constructor( |
|||
private readonly repository: StatisticsRepository |
|||
) {} |
|||
|
|||
public async fetchStatistics( |
|||
projectId: string, labelText: string, userText: string, progressLabels: string[] |
|||
): Promise<StatisticsDTO> { |
|||
const item = await this.repository.fetch(projectId) |
|||
return new StatisticsDTO(item, labelText, userText, progressLabels) |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save