|
8 | 8 | <div class="spacing-25"/>
|
9 | 9 | <div class="text-h6 mb-1">Number of {{ breakdownDisplayNamePlural }}</div>
|
10 | 10 | <div class="text-caption">
|
11 |
| - Over the last 28 days |
| 11 | + {{ dateRangeDescription }} |
12 | 12 | </div>
|
13 | 13 | <p class="text-h4">{{ numberOfBreakdowns }}</p>
|
14 | 14 | </div>
|
|
79 | 79 | </template>
|
80 | 80 |
|
81 | 81 | <script lang="ts">
|
82 |
| -import { defineComponent, ref, toRef } from 'vue'; |
| 82 | +import { defineComponent, ref, toRef, watch } from 'vue'; |
83 | 83 | import type { Metrics } from '@/model/Metrics';
|
84 | 84 | import { Breakdown } from '@/model/Breakdown';
|
85 | 85 | import { Pie } from 'vue-chartjs'
|
@@ -122,6 +122,10 @@ export default defineComponent({
|
122 | 122 | breakdownKey: {
|
123 | 123 | type: String,
|
124 | 124 | required: true
|
| 125 | + }, |
| 126 | + dateRangeDescription: { |
| 127 | + type: String, |
| 128 | + default: 'Over the last 28 days' |
125 | 129 | }
|
126 | 130 | },
|
127 | 131 | setup(props) {
|
@@ -157,76 +161,87 @@ export default defineComponent({
|
157 | 161 | '#7CFC00' // Lawn Green
|
158 | 162 | ]);
|
159 | 163 |
|
160 |
| - const data = toRef(props, 'metrics').value; |
| 164 | + // Function to process breakdown data |
| 165 | + const processBreakdownData = (data: Metrics[]) => { |
| 166 | + // Reset the breakdown list |
| 167 | + breakdownList.value = []; |
| 168 | + |
| 169 | + // Process the breakdown separately |
| 170 | + data.forEach((m: Metrics) => m.breakdown.forEach(breakdownData => |
| 171 | + { |
| 172 | + const breakdownName = breakdownData[props.breakdownKey as keyof typeof breakdownData] as string; |
| 173 | + let breakdown = breakdownList.value.find(b => b.name === breakdownName); |
161 | 174 |
|
162 |
| - // Process the breakdown separately |
163 |
| - data.forEach((m: Metrics) => m.breakdown.forEach(breakdownData => |
164 |
| - { |
165 |
| - const breakdownName = breakdownData[props.breakdownKey as keyof typeof breakdownData] as string; |
166 |
| - let breakdown = breakdownList.value.find(b => b.name === breakdownName); |
| 175 | + if (!breakdown) { |
| 176 | + // Create a new breakdown object if it does not exist |
| 177 | + breakdown = new Breakdown({ |
| 178 | + name: breakdownName, |
| 179 | + acceptedPrompts: breakdownData.acceptances_count, |
| 180 | + suggestedPrompts: breakdownData.suggestions_count, |
| 181 | + suggestedLinesOfCode: breakdownData.lines_suggested, |
| 182 | + acceptedLinesOfCode: breakdownData.lines_accepted, |
| 183 | + }); |
| 184 | + breakdownList.value.push(breakdown); |
| 185 | + } else { |
| 186 | + // Update the existing breakdown object |
| 187 | + breakdown.acceptedPrompts += breakdownData.acceptances_count; |
| 188 | + breakdown.suggestedPrompts += breakdownData.suggestions_count; |
| 189 | + breakdown.suggestedLinesOfCode += breakdownData.lines_suggested; |
| 190 | + breakdown.acceptedLinesOfCode += breakdownData.lines_accepted; |
| 191 | + } |
| 192 | + // Recalculate the acceptance rates |
| 193 | + breakdown.acceptanceRateByCount = breakdown.suggestedPrompts !== 0 ? (breakdown.acceptedPrompts / breakdown.suggestedPrompts) * 100 : 0; |
| 194 | + breakdown.acceptanceRateByLines = breakdown.suggestedLinesOfCode !== 0 ? (breakdown.acceptedLinesOfCode / breakdown.suggestedLinesOfCode) * 100 : 0; |
167 | 195 |
|
168 |
| - if (!breakdown) { |
169 |
| - // Create a new breakdown object if it does not exist |
170 |
| - breakdown = new Breakdown({ |
171 |
| - name: breakdownName, |
172 |
| - acceptedPrompts: breakdownData.acceptances_count, |
173 |
| - suggestedPrompts: breakdownData.suggestions_count, |
174 |
| - suggestedLinesOfCode: breakdownData.lines_suggested, |
175 |
| - acceptedLinesOfCode: breakdownData.lines_accepted, |
176 |
| - }); |
177 |
| - breakdownList.value.push(breakdown); |
178 |
| - } else { |
179 |
| - // Update the existing breakdown object |
180 |
| - breakdown.acceptedPrompts += breakdownData.acceptances_count; |
181 |
| - breakdown.suggestedPrompts += breakdownData.suggestions_count; |
182 |
| - breakdown.suggestedLinesOfCode += breakdownData.lines_suggested; |
183 |
| - breakdown.acceptedLinesOfCode += breakdownData.lines_accepted; |
184 |
| - } |
185 |
| - // Recalculate the acceptance rates |
186 |
| - breakdown.acceptanceRateByCount = breakdown.suggestedPrompts !== 0 ? (breakdown.acceptedPrompts / breakdown.suggestedPrompts) * 100 : 0; |
187 |
| - breakdown.acceptanceRateByLines = breakdown.suggestedLinesOfCode !== 0 ? (breakdown.acceptedLinesOfCode / breakdown.suggestedLinesOfCode) * 100 : 0; |
| 196 | + // Log each breakdown for debugging |
| 197 | + // console.log('Breakdown:', breakdown); |
| 198 | + })); |
188 | 199 |
|
189 |
| - // Log each breakdown for debugging |
190 |
| - // console.log('Breakdown:', breakdown); |
191 |
| - })); |
| 200 | + //Sort breakdowns map by accepted prompts |
| 201 | + breakdownList.value.sort((a, b) => b.acceptedPrompts - a.acceptedPrompts); |
192 | 202 |
|
193 |
| - //Sort breakdowns map by accepted prompts |
194 |
| - breakdownList.value.sort((a, b) => b.acceptedPrompts - a.acceptedPrompts); |
| 203 | + // Get the top 5 breakdowns by accepted prompts |
| 204 | + const top5BreakdownsAcceptedPrompts = breakdownList.value.slice(0, 5); |
| 205 | + |
| 206 | + breakdownsChartDataTop5AcceptedPrompts.value = { |
| 207 | + labels: top5BreakdownsAcceptedPrompts.map(breakdown => breakdown.name), |
| 208 | + datasets: [ |
| 209 | + { |
| 210 | + data: top5BreakdownsAcceptedPrompts.map(breakdown => breakdown.acceptedPrompts), |
| 211 | + backgroundColor: pieChartColors.value, |
| 212 | + }, |
| 213 | + ], |
| 214 | + }; |
195 | 215 |
|
196 |
| - // Get the top 5 breakdowns by accepted prompts |
197 |
| - const top5BreakdownsAcceptedPrompts = breakdownList.value.slice(0, 5); |
198 |
| - |
199 |
| - breakdownsChartDataTop5AcceptedPrompts.value = { |
200 |
| - labels: top5BreakdownsAcceptedPrompts.map(breakdown => breakdown.name), |
201 |
| - datasets: [ |
202 |
| - { |
203 |
| - data: top5BreakdownsAcceptedPrompts.map(breakdown => breakdown.acceptedPrompts), |
204 |
| - backgroundColor: pieChartColors.value, |
205 |
| - }, |
206 |
| - ], |
207 |
| - }; |
| 216 | + breakdownsChartDataTop5AcceptedPromptsByLines.value = { |
| 217 | + labels: top5BreakdownsAcceptedPrompts.map(breakdown => breakdown.name), |
| 218 | + datasets: [ |
| 219 | + { |
| 220 | + data: top5BreakdownsAcceptedPrompts.map(breakdown => breakdown.acceptanceRateByLines.toFixed(2)), |
| 221 | + backgroundColor: pieChartColors.value, |
| 222 | + }, |
| 223 | + ], |
| 224 | + }; |
208 | 225 |
|
209 |
| - breakdownsChartDataTop5AcceptedPromptsByLines.value = { |
210 |
| - labels: top5BreakdownsAcceptedPrompts.map(breakdown => breakdown.name), |
211 |
| - datasets: [ |
212 |
| - { |
213 |
| - data: top5BreakdownsAcceptedPrompts.map(breakdown => breakdown.acceptanceRateByLines.toFixed(2)), |
214 |
| - backgroundColor: pieChartColors.value, |
215 |
| - }, |
216 |
| - ], |
217 |
| - }; |
| 226 | + breakdownsChartDataTop5AcceptedPromptsByCounts.value = { |
| 227 | + labels: top5BreakdownsAcceptedPrompts.map(breakdown => breakdown.name), |
| 228 | + datasets: [ |
| 229 | + { |
| 230 | + data: top5BreakdownsAcceptedPrompts.map(breakdown => breakdown.acceptanceRateByCount.toFixed(2)), |
| 231 | + backgroundColor: pieChartColors.value, |
| 232 | + }, |
| 233 | + ], |
| 234 | + }; |
218 | 235 |
|
219 |
| - breakdownsChartDataTop5AcceptedPromptsByCounts.value = { |
220 |
| - labels: top5BreakdownsAcceptedPrompts.map(breakdown => breakdown.name), |
221 |
| - datasets: [ |
222 |
| - { |
223 |
| - data: top5BreakdownsAcceptedPrompts.map(breakdown => breakdown.acceptanceRateByCount.toFixed(2)), |
224 |
| - backgroundColor: pieChartColors.value, |
225 |
| - }, |
226 |
| - ], |
| 236 | + numberOfBreakdowns.value = breakdownList.value.length; |
227 | 237 | };
|
228 | 238 |
|
229 |
| - numberOfBreakdowns.value = breakdownList.value.length; |
| 239 | + // Watch for changes in metrics prop and re-process data |
| 240 | + watch(() => props.metrics, (newMetrics) => { |
| 241 | + if (newMetrics && Array.isArray(newMetrics)) { |
| 242 | + processBreakdownData(newMetrics); |
| 243 | + } |
| 244 | + }, { immediate: true, deep: true }); |
230 | 245 |
|
231 | 246 | return { chartOptions, breakdownList, numberOfBreakdowns,
|
232 | 247 | breakdownsChartData, breakdownsChartDataTop5AcceptedPrompts, breakdownsChartDataTop5AcceptedPromptsByLines, breakdownsChartDataTop5AcceptedPromptsByCounts };
|
|
0 commit comments