You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

59 lines
1.3 KiB

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
}
}
}