(line: string, results: string[])
| 39 | ); |
| 40 | |
| 41 | function processOutputLine(line: string, results: string[]) { |
| 42 | const trimmedLine = line.trim(); |
| 43 | if (!trimmedLine) return; |
| 44 | |
| 45 | let metricName = ''; |
| 46 | let metricValue = 0; |
| 47 | |
| 48 | try { |
| 49 | const parsed = JSON.parse(trimmedLine); |
| 50 | if ( |
| 51 | parsed && |
| 52 | typeof parsed === 'object' && |
| 53 | 'metric' in parsed && |
| 54 | 'value' in parsed |
| 55 | ) { |
| 56 | metricName = parsed.metric; |
| 57 | metricValue = parseFloat(parsed.value); |
| 58 | results.push(`${metricName},${metricValue}`); |
| 59 | } else { |
| 60 | const parts = trimmedLine.split(','); |
| 61 | if (parts.length === 2) { |
| 62 | metricName = parts[0]; |
| 63 | metricValue = parseFloat(parts[1]); |
| 64 | results.push(trimmedLine); |
| 65 | } else { |
| 66 | results.push(trimmedLine); |
| 67 | return; // Unable to parse for deltas |
| 68 | } |
| 69 | } |
| 70 | } catch { |
| 71 | const parts = trimmedLine.split(','); |
| 72 | if (parts.length === 2) { |
| 73 | metricName = parts[0]; |
| 74 | metricValue = parseFloat(parts[1]); |
| 75 | results.push(trimmedLine); |
| 76 | } else { |
| 77 | results.push(trimmedLine); |
| 78 | return; // Unable to parse for deltas |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // Calculate and append deltas if the metric is a valid number |
| 83 | if (metricName && !isNaN(metricValue)) { |
| 84 | const avg7d = getHistoricalAverage(metricName, 7); |
| 85 | if (avg7d !== null) { |
| 86 | results.push( |
| 87 | `${metricName}_delta_7d,${(metricValue - avg7d).toFixed(2)}`, |
| 88 | ); |
| 89 | } |
| 90 | |
| 91 | const avg30d = getHistoricalAverage(metricName, 30); |
| 92 | if (avg30d !== null) { |
| 93 | results.push( |
| 94 | `${metricName}_delta_30d,${(metricValue - avg30d).toFixed(2)}`, |
| 95 | ); |
| 96 | } |
| 97 | } |
| 98 | } |
no test coverage detected