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.

87 lines
2.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. export type Label = {[key: string]: number}
  2. export type User = {[key: string]: number}
  3. export type ConfirmedCount = {[key: string]: number}
  4. export class Statistics {
  5. constructor(
  6. public label: Label,
  7. public userLabel: User,
  8. public total: number,
  9. public remaining: number,
  10. public user: User,
  11. public confirmedCount: ConfirmedCount,
  12. ) {}
  13. static valueOf(
  14. { label, user_label, total, remaining, user, confirmed_count }:
  15. {
  16. label: Label,
  17. user_label: User,
  18. total: number,
  19. remaining: number,
  20. user: User,
  21. confirmed_count: ConfirmedCount,
  22. }
  23. ): Statistics {
  24. return new Statistics(label, user_label, total, remaining, user, confirmed_count)
  25. }
  26. private makeData(object: Label | User, label: string) {
  27. const labels = object ? Object.keys(object) : []
  28. const counts = object ? Object.values(object) : []
  29. return {
  30. labels,
  31. datasets: [{
  32. label,
  33. backgroundColor: '#00d1b2',
  34. data: counts
  35. }]
  36. }
  37. }
  38. public labelStats(label: string) {
  39. return this.makeData(this.label, label)
  40. }
  41. public userStats(label: string) {
  42. return this.makeData(this.user, label)
  43. }
  44. public progress(labels: string[]) {
  45. const complete = this.total - this.remaining
  46. const incomplete = this.remaining
  47. return {
  48. datasets: [{
  49. data: [complete, incomplete],
  50. backgroundColor: ['#00d1b2', '#ffdd57']
  51. }],
  52. labels
  53. }
  54. }
  55. private makeProgressData(roleName: string, labels: string[]) {
  56. const confirmed = this.confirmedCount[roleName]
  57. const unconfirmed = this.total - confirmed
  58. return {
  59. datasets: [{
  60. data: [confirmed, unconfirmed],
  61. backgroundColor: ['#00d1b2', '#ffdd57']
  62. }],
  63. labels
  64. }
  65. }
  66. public annotatorProgress(labels: string[]) {
  67. return this.makeProgressData('annotator', labels)
  68. }
  69. public approverProgress(labels: string[]) {
  70. return this.makeProgressData('annotation_approver', labels)
  71. }
  72. public adminProgress(labels: string[]) {
  73. return this.makeProgressData('project_admin', labels)
  74. }
  75. }