Coverage for src/types/statistics.py: 21.88%

64 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-07 23:50 +0000

1#!/usr/bin/env python3 

2 

3# Standard libraries 

4from math import isclose 

5from typing import Dict 

6 

7# TimesStatistics class, pylint: disable=too-few-public-methods 

8class TimesStatistics: 

9 

10 # Constants 

11 # PROGRESS_DECADE = '⣀⣄⣄⣆⣆⣇⣇⣧⣧⣷⣿' 

12 PROGRESS_DECADE = '▁▂▂▃▄▄▅▅▆▇█' 

13 

14 # Members 

15 defaulted: bool 

16 estimates: int 

17 spent: int 

18 

19 # Constructor 

20 def __init__(self) -> None: 

21 self.defaulted = False 

22 self.estimates = 0 

23 self.spent = 0 

24 

25 # Properties 

26 @property 

27 def remaining(self) -> int: 

28 return self.estimates - self.spent if self.estimates >= self.spent else 0 

29 

30 # Convert time estimates 

31 @staticmethod 

32 def human(time_estimate_seconds: int, defaulted: bool = False) -> str: 

33 

34 # Variables 

35 days: int 

36 minutes: int 

37 output: str = '' 

38 seconds: int 

39 

40 # Defaulted times 

41 if defaulted: 

42 output += '~?' 

43 

44 # Extract days 

45 days, seconds = divmod(time_estimate_seconds, 3600 * 8) 

46 if days: 

47 if output: 

48 output += ' ' 

49 output += f'{days}d' 

50 

51 # Extract hours 

52 hours, seconds = divmod(seconds, 3600) 

53 if hours: 

54 if output: 

55 output += ' ' 

56 output += f'{hours}h' 

57 

58 # Extract minutes 

59 minutes, _ = divmod(seconds, 60) 

60 if minutes: 

61 if output: 

62 output += ' ' 

63 output += f'{minutes}min' 

64 

65 # Empty fallback 

66 if not output: 

67 output = '/' 

68 

69 # Result 

70 return output 

71 

72 # Progress 

73 def progress(self) -> str: 

74 

75 # Variables 

76 output: str = '' 

77 percentage: float 

78 unit: int 

79 

80 # Evaluate percentage 

81 if self.spent >= self.estimates: 

82 percentage = 100.0 

83 unit = 0 

84 else: 

85 percentage = 100.0 * self.spent / self.estimates 

86 unit = int(percentage) % 10 

87 

88 # Add progress bar 

89 for percent in range(0, 100, 10): 

90 if percent == 0 and isclose(percentage, 0.0): 

91 output += TimesStatistics.PROGRESS_DECADE[0] 

92 elif percentage >= percent + 10: 

93 output += TimesStatistics.PROGRESS_DECADE[10] 

94 elif percent == 100 and isclose(percentage, 100.0): 

95 output += TimesStatistics.PROGRESS_DECADE[10] 

96 elif percentage >= percent: 

97 output += TimesStatistics.PROGRESS_DECADE[unit] 

98 else: 

99 output += TimesStatistics.PROGRESS_DECADE[0] 

100 

101 # Add percentage 

102 output += f' {percentage:.2f}%' 

103 

104 # Result 

105 return output 

106 

107# AssigneeStatistics class, pylint: disable=too-few-public-methods 

108class AssigneeStatistics: 

109 

110 # Members 

111 name: str 

112 issues_count: int 

113 times: TimesStatistics 

114 

115 # Constructor 

116 def __init__( 

117 self, 

118 name: str, 

119 ): 

120 self.name = name 

121 self.issues_count = 0 

122 self.times = TimesStatistics() 

123 

124# MilestoneStatistics class, pylint: disable=too-few-public-methods 

125class MilestoneStatistics: 

126 

127 # Members 

128 title: str 

129 issues_count: int 

130 times: TimesStatistics 

131 assignees: Dict[str, AssigneeStatistics] 

132 

133 # Constructor 

134 def __init__( 

135 self, 

136 title: str, 

137 ): 

138 self.title = title 

139 self.issues_count = 0 

140 self.times = TimesStatistics() 

141 self.assignees = {}