Skip to content

Commit 1f2ba12

Browse files
Copilotkarpikpl
andauthored
Add CSV export functionality for metrics data in API response tab (#224)
* Initial plan * Initial planning for CSV export functionality Co-authored-by: karpikpl <[email protected]> * Add CSV export functionality to API response tab Co-authored-by: karpikpl <[email protected]> * Remove unused convertBreakdownToCSV function and add comprehensive CopilotMetrics CSV export Co-authored-by: karpikpl <[email protected]> * fixes to CSV download --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: karpikpl <[email protected]> Co-authored-by: Piotr Karpala <[email protected]>
1 parent ea739d0 commit 1f2ba12

File tree

7 files changed

+910
-66
lines changed

7 files changed

+910
-66
lines changed

app/components/ApiResponse.vue

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<v-btn @click="checkMetricsDataQuality">Check Metric data quality</v-btn>
55
<v-spacer/>
66
<v-btn @click="copyToClipboard('metricsJsonText')">Copy Metrics to Clipboard</v-btn>
7+
<v-btn color="primary" @click="downloadMetricsCSV">Download CSV (Summary)</v-btn>
8+
<v-btn color="secondary" @click="downloadFullMetricsCSV">Download CSV (Full)</v-btn>
79
</div>
810
<transition name="fade">
911
<div v-if="showQualityMessage || showCopyMessage || showSeatMessage" :class="{'copy-message': true, 'error': isError}">{{ message }}</div>
@@ -31,8 +33,9 @@
3133
</template>
3234

3335
<script lang="ts">
34-
import { defineComponent } from 'vue';
36+
import { defineComponent, toRaw } from 'vue';
3537
import { MetricsValidator } from '@/model/MetricsValidator';
38+
import { convertMetricsToCSV, convertCopilotMetricsToCSV, downloadCSV } from '@/utils/csvExport';
3639
import type { CopilotMetrics } from '@/model/Copilot_Metrics';
3740
import type { Metrics } from '@/model/Metrics';
3841
@@ -94,7 +97,9 @@ export default defineComponent({
9497
},
9598
9699
checkMetricsDataQuality() {
97-
const validator = new MetricsValidator(this.originalMetrics);
100+
// Convert reactive proxy to raw object using Vue's toRaw
101+
const rawOriginalMetrics = toRaw(this.originalMetrics) as CopilotMetrics[];
102+
const validator = new MetricsValidator(rawOriginalMetrics);
98103
99104
// console.log(validator);
100105
// create a new MetricsValidator object
@@ -123,6 +128,60 @@ export default defineComponent({
123128
setTimeout(() => {
124129
this.showQualityMessage = false;
125130
}, 6000);
131+
},
132+
133+
downloadMetricsCSV() {
134+
try {
135+
// Convert reactive proxy to raw object using Vue's toRaw
136+
const rawMetrics = toRaw(this.metrics) as Metrics[];
137+
const csvContent = convertMetricsToCSV(rawMetrics);
138+
if (csvContent) {
139+
const currentDate = new Date().toISOString().split('T')[0];
140+
const filename = `copilot-metrics-summary-${currentDate}.csv`;
141+
downloadCSV(csvContent, filename);
142+
this.message = 'Summary CSV file downloaded successfully!';
143+
this.isError = false;
144+
} else {
145+
this.message = 'No metrics data available to export.';
146+
this.isError = true;
147+
}
148+
} catch (error) {
149+
this.message = 'Error generating CSV file.';
150+
this.isError = true;
151+
console.error('Error generating CSV:', error);
152+
}
153+
154+
this.showCopyMessage = true;
155+
setTimeout(() => {
156+
this.showCopyMessage = false;
157+
}, 3000);
158+
},
159+
160+
downloadFullMetricsCSV() {
161+
try {
162+
// Convert reactive proxy to raw object using Vue's toRaw
163+
const rawMetrics = toRaw(this.originalMetrics) as CopilotMetrics[];
164+
const csvContent = convertCopilotMetricsToCSV(rawMetrics);
165+
if (csvContent) {
166+
const currentDate = new Date().toISOString().split('T')[0];
167+
const filename = `copilot-metrics-full-${currentDate}.csv`;
168+
downloadCSV(csvContent, filename);
169+
this.message = 'Full CSV file downloaded successfully!';
170+
this.isError = false;
171+
} else {
172+
this.message = 'No metrics data available to export.';
173+
this.isError = true;
174+
}
175+
} catch (error) {
176+
this.message = 'Error generating CSV file.';
177+
this.isError = true;
178+
console.error('Error generating CSV:', error);
179+
}
180+
181+
this.showCopyMessage = true;
182+
setTimeout(() => {
183+
this.showCopyMessage = false;
184+
}, 3000);
126185
}
127186
}
128187
});

0 commit comments

Comments
 (0)