1
1
import moment from "moment"
2
2
import { IMultiSeries , ISeries } from "../interfaces/issueInterfaces"
3
- import { SECOND_IN_A_DAY } from "../interfaces/settingsInterfaces"
4
3
import { getRandomRGBColor , resetRandomGenerator } from "../utils"
5
4
import API from "./api"
5
+ const ms = require ( 'ms' )
6
6
7
7
enum EChartFormat {
8
- SECONDS = 'Seconds ' ,
8
+ HOURS = 'Hours ' ,
9
9
DAYS = 'Days' ,
10
10
PERCENTAGE = 'Percentage' ,
11
11
}
12
12
13
+ const MS_IN_A_DAY = ms ( '1d' )
14
+ const MS_IN_A_HOUR = ms ( '1h' )
15
+
13
16
export async function getWorklogPerDay ( projectKeyOrId : string , startDate : string , endDate : string = 'now()' ) {
14
17
const worklogs = await API . macro . getWorkLogByDates ( projectKeyOrId , startDate , endDate )
15
18
const labels = [ ]
@@ -22,7 +25,7 @@ export async function getWorklogPerDay(projectKeyOrId: string, startDate: string
22
25
}
23
26
const usersSeries : IMultiSeries = { }
24
27
for ( const worklog of worklogs ) {
25
- const author = worklog . author . key
28
+ const author = worklog . author . name
26
29
if ( ! usersSeries [ author ] ) {
27
30
usersSeries [ author ] = Object . assign ( { } , emptySeries )
28
31
}
@@ -53,22 +56,32 @@ export async function getWorklogPerDay(projectKeyOrId: string, startDate: string
53
56
export async function getWorklogPerUser ( projectKeyOrId : string , startDate : string , endDate : string = 'now()' , options : { format ?: EChartFormat , capacity ?: ISeries } = { } ) {
54
57
const opt = {
55
58
format : options . format || EChartFormat . PERCENTAGE ,
56
- capacity : options . capacity || { } ,
59
+ capacity : options . capacity || null ,
57
60
}
58
- const series = await API . macro . getWorkLogByUser ( projectKeyOrId , startDate , endDate )
61
+ const series = await API . macro . getWorkLogSeriesByUser ( projectKeyOrId , startDate , endDate )
59
62
switch ( opt . format ) {
60
- case EChartFormat . SECONDS :
63
+ case EChartFormat . HOURS :
64
+ for ( const a in series ) {
65
+ series [ a ] = series [ a ] / MS_IN_A_HOUR
66
+ }
61
67
break
62
68
case EChartFormat . DAYS :
63
69
for ( const a in series ) {
64
- series [ a ] = series [ a ] / SECOND_IN_A_DAY
70
+ series [ a ] = series [ a ] / MS_IN_A_DAY
65
71
}
66
72
break
67
73
case EChartFormat . PERCENTAGE :
68
- const days = moment ( moment ( endDate ) . unix ( ) - moment ( startDate ) . unix ( ) ) . days ( )
74
+ const days = moment . duration ( moment ( endDate ) . diff ( startDate ) ) . asDays ( )
69
75
for ( const author in series ) {
70
- const capacity = opt . capacity [ author ] || days
71
- series [ author ] = series [ author ] / capacity / SECOND_IN_A_DAY * 100
76
+ if ( opt . capacity ) {
77
+ if ( author in opt . capacity ) {
78
+ series [ author ] = series [ author ] / opt . capacity [ author ] / MS_IN_A_DAY * 100
79
+ } else {
80
+ delete series [ author ]
81
+ }
82
+ } else {
83
+ series [ author ] = series [ author ] / days / MS_IN_A_DAY * 100
84
+ }
72
85
}
73
86
break
74
87
default :
0 commit comments