Coverage for little_loops / cli / issues / impact_effort.py: 94%

108 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2026-03-04 01:17 -0600

1"""ll-issues impact-effort: ASCII impact vs effort matrix for active issues.""" 

2 

3from __future__ import annotations 

4 

5import argparse 

6from typing import TYPE_CHECKING 

7 

8if TYPE_CHECKING: 

9 from little_loops.config import BRConfig 

10 from little_loops.issue_parser import IssueInfo 

11 

12# Effort/impact scale: 1=low, 2=medium, 3=high 

13_PRIORITY_TO_EFFORT = {0: 3, 1: 3, 2: 2, 3: 2, 4: 1, 5: 1} 

14_PRIORITY_TO_IMPACT = {0: 3, 1: 3, 2: 2, 3: 2, 4: 1, 5: 1} 

15 

16# Max issues to show per quadrant before truncating 

17_MAX_PER_QUADRANT = 6 

18 

19# Column width for each quadrant (content area, excluding border chars) 

20_COL_WIDTH = 20 

21 

22 

23def _infer_effort(issue: IssueInfo) -> int: 

24 """Return effort level (1=low, 2=med, 3=high) from frontmatter or priority.""" 

25 if issue.effort is not None: 

26 return max(1, min(3, issue.effort)) 

27 return _PRIORITY_TO_EFFORT.get(issue.priority_int, 2) 

28 

29 

30def _infer_impact(issue: IssueInfo) -> int: 

31 """Return impact level (1=low, 2=med, 3=high) from frontmatter or priority.""" 

32 if issue.impact is not None: 

33 return max(1, min(3, issue.impact)) 

34 return _PRIORITY_TO_IMPACT.get(issue.priority_int, 2) 

35 

36 

37def _issue_slug(issue: IssueInfo) -> str: 

38 """Extract short slug from filename: description segment with hyphens→spaces, truncated.""" 

39 name = issue.path.stem # e.g. "P3-FEAT-505-ll-issues-cli-command" 

40 parts = name.split("-", 3) # ['P3', 'FEAT', '505', 'll-issues-cli-command'] 

41 if len(parts) >= 4: 

42 slug = parts[3].replace("-", " ") 

43 else: 

44 slug = issue.title 

45 max_len = _COL_WIDTH - len(issue.issue_id) - 2 

46 return slug[:max_len] if len(slug) > max_len else slug 

47 

48 

49def _render_quadrant_lines(issues: list[IssueInfo], header: str) -> list[str]: 

50 """Render lines for a single quadrant (no borders, fixed _COL_WIDTH).""" 

51 lines: list[str] = [] 

52 lines.append(header.ljust(_COL_WIDTH)) 

53 shown = issues[:_MAX_PER_QUADRANT] 

54 for issue in shown: 

55 slug = _issue_slug(issue) 

56 line = f"{issue.issue_id} {slug}" 

57 lines.append(line.ljust(_COL_WIDTH)) 

58 if len(issues) > _MAX_PER_QUADRANT: 

59 extra = len(issues) - _MAX_PER_QUADRANT 

60 lines.append(f" \u2026 +{extra} more".ljust(_COL_WIDTH)) 

61 if not shown: 

62 lines.append("(none)".ljust(_COL_WIDTH)) 

63 return lines 

64 

65 

66def _render_grid( 

67 q_high_low: list[IssueInfo], # high impact, low effort = quick wins 

68 q_high_high: list[IssueInfo], # high impact, high effort = major projects 

69 q_low_low: list[IssueInfo], # low impact, low effort = fill-ins 

70 q_low_high: list[IssueInfo], # low impact, high effort = thankless tasks 

71) -> str: 

72 """Render the 2x2 ASCII grid and return as a string.""" 

73 lines_tl = _render_quadrant_lines(q_high_low, "\u2605 QUICK WINS") 

74 lines_tr = _render_quadrant_lines(q_high_high, "\u25b2 MAJOR PROJECTS") 

75 lines_bl = _render_quadrant_lines(q_low_low, "\u00b7 FILL-INS") 

76 lines_br = _render_quadrant_lines(q_low_high, "\u2717 THANKLESS") 

77 

78 # Pad all quadrant line lists to the same height 

79 top_height = max(len(lines_tl), len(lines_tr)) 

80 bot_height = max(len(lines_bl), len(lines_br)) 

81 

82 def pad(lst: list[str], height: int) -> list[str]: 

83 while len(lst) < height: 

84 lst.append(" " * _COL_WIDTH) 

85 return lst 

86 

87 lines_tl = pad(lines_tl, top_height) 

88 lines_tr = pad(lines_tr, top_height) 

89 lines_bl = pad(lines_bl, bot_height) 

90 lines_br = pad(lines_br, bot_height) 

91 

92 # Box-drawing characters 

93 h = "\u2500" 

94 v = "\u2502" 

95 tl = "\u250c" 

96 tr = "\u2510" 

97 bl = "\u2514" 

98 br = "\u2518" 

99 tm = "\u252c" 

100 bm = "\u2534" 

101 ml = "\u251c" 

102 mr = "\u2524" 

103 mid = "\u253c" 

104 

105 bar = h * (_COL_WIDTH + 2) 

106 top_border = f"{tl}{bar}{tm}{bar}{tr}" 

107 mid_border = f"{ml}{bar}{mid}{bar}{mr}" 

108 bot_border = f"{bl}{bar}{bm}{bar}{br}" 

109 

110 label_width = 12 # len("High IMPACT ") == len("Low IMPACT ") == len(" " * 12) 

111 grid_width = len(top_border) # 1 + (_COL_WIDTH+2) + 1 + (_COL_WIDTH+2) + 1 = 47 

112 col_section = _COL_WIDTH + 2 # 22 — one column's width including surrounding spaces 

113 

114 out: list[str] = [] 

115 

116 # Axis labels: "← EFFORT →" centered over grid; "Low"/"High" over each column 

117 effort_label = "\u2190 EFFORT \u2192" 

118 out.append(" " * label_width + effort_label.center(grid_width)) 

119 out.append( 

120 " " * (label_width + 1) + "Low".center(col_section) + " " + "High".center(col_section) 

121 ) 

122 

123 out.append(" " * label_width + top_border) 

124 for i, (tl_line, tr_line) in enumerate(zip(lines_tl, lines_tr, strict=True)): 

125 row_label = "High IMPACT " if i == 0 else " " * label_width 

126 out.append(f"{row_label}{v} {tl_line} {v} {tr_line} {v}") 

127 out.append(" " * label_width + mid_border) 

128 for i, (bl_line, br_line) in enumerate(zip(lines_bl, lines_br, strict=True)): 

129 row_label = "Low IMPACT " if i == 0 else " " * label_width 

130 out.append(f"{row_label}{v} {bl_line} {v} {br_line} {v}") 

131 out.append(" " * label_width + bot_border) 

132 

133 return "\n".join(out) 

134 

135 

136def cmd_impact_effort(config: BRConfig, args: argparse.Namespace) -> int: 

137 """Display impact vs effort matrix for active issues. 

138 

139 Issues are grouped into four quadrants: 

140 - Quick Wins: high impact, low effort 

141 - Major Projects: high impact, high effort 

142 - Fill-ins: low impact, low effort 

143 - Thankless Tasks: low impact, high effort 

144 

145 Effort and impact (1=low, 2=med, 3=high) are read from issue frontmatter 

146 if present; otherwise inferred from priority (P0-P1=high, P2-P3=med, P4-P5=low). 

147 

148 Args: 

149 config: Project configuration 

150 args: Parsed arguments (unused, reserved for future flags) 

151 

152 Returns: 

153 Exit code (0 = success) 

154 """ 

155 from little_loops.issue_parser import find_issues 

156 

157 issues = find_issues(config) 

158 

159 if not issues: 

160 print("No active issues found.") 

161 return 0 

162 

163 q_high_low: list[IssueInfo] = [] 

164 q_high_high: list[IssueInfo] = [] 

165 q_low_low: list[IssueInfo] = [] 

166 q_low_high: list[IssueInfo] = [] 

167 

168 for issue in issues: 

169 effort = _infer_effort(issue) 

170 impact = _infer_impact(issue) 

171 high_impact = impact >= 2 

172 high_effort = effort >= 2 

173 if high_impact and not high_effort: 

174 q_high_low.append(issue) 

175 elif high_impact and high_effort: 

176 q_high_high.append(issue) 

177 elif not high_impact and not high_effort: 

178 q_low_low.append(issue) 

179 else: 

180 q_low_high.append(issue) 

181 

182 print(_render_grid(q_high_low, q_high_high, q_low_low, q_low_high)) 

183 return 0