Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 7, 2025

This PR implements CSV export functionality that allows users to download GitHub Copilot metrics data in CSV format directly from the API response tab.

Changes Made

New Features

  • CSV Export Button: Added a "Download CSV" button to the API response tab alongside existing "Check Metric data quality" and "Copy Metrics to Clipboard" buttons
  • CSV Utility Functions: Created comprehensive utility functions in app/utils/csvExport.ts to convert metrics data to properly formatted CSV
  • Automatic File Download: Implemented browser-based CSV file download with automatic filename generation (e.g., copilot-metrics-2025-01-07.csv)

CSV Format

The exported CSV includes all essential metrics with user-friendly headers:

  • Date
  • Total Suggestions/Acceptances
  • Total Lines Suggested/Accepted
  • Total Active Users
  • Chat metrics (acceptances, turns, active users)
  • Calculated acceptance rates (by count and by lines) with 2 decimal precision

Example CSV output:

Date,Total Suggestions,Total Acceptances,Total Lines Suggested,Total Lines Accepted,Total Active Users,Total Chat Acceptances,Total Chat Turns,Total Active Chat Users,Acceptance Rate by Count (%),Acceptance Rate by Lines (%)
2024-11-04,21,11,82,20,4,2,44,4,52.38,24.39
2024-11-05,4,0,4,0,3,0,30,3,0.00,0.00

User Experience

  • Success/error messaging provides clear feedback
  • Non-intrusive integration with existing UI
  • Works with both live API data and mock data

Testing

  • Added comprehensive unit tests for CSV utility functions
  • Tests cover normal operation, edge cases (empty data, null inputs)
  • All existing tests continue to pass

Technical Implementation

  • Leverages existing processed Metrics data for consistent formatting
  • Uses browser's native download API for file delivery
  • Maintains TypeScript type safety throughout
  • Zero impact on existing functionality

This enhancement makes it easy for users to export GitHub Copilot metrics for analysis in Excel, Google Sheets, or other data analysis tools, addressing a common user need for data portability.

Fixes #223.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.fontshare.com
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
    • Triggering command: /usr/local/bin/node --enable-source-maps /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/@nuxt/cli/bin/nuxi.mjs _dev (dns block)
  • api.fontsource.org
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
    • Triggering command: /usr/local/bin/node --enable-source-maps /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/@nuxt/cli/bin/nuxi.mjs _dev (dns block)
  • fonts.bunny.net
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
    • Triggering command: /usr/local/bin/node --enable-source-maps /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/@nuxt/cli/bin/nuxi.mjs _dev (dns block)
  • fonts.google.com
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
    • Triggering command: /usr/local/bin/node --enable-source-maps /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/@nuxt/cli/bin/nuxi.mjs _dev (dns block)
  • fonts.googleapis.com
    • Triggering command: node (vitest 2) (dns block)
    • Triggering command: node (vitest 1) (dns block)
    • Triggering command: node (vitest 3) (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Support for export to CSV for data returned from the API Add CSV export functionality for metrics data in API response tab Jul 7, 2025
Copilot AI requested a review from karpikpl July 7, 2025 20:19
Copilot finished work on behalf of karpikpl July 7, 2025 20:19
@karpikpl
Copy link
Collaborator

karpikpl commented Jul 8, 2025

@copilot
looks like convertBreakdownToCSV is not used, would it be possible to convert new metrics format to CSV and flatten it by day?

Copy link
Contributor Author

Copilot AI commented Jul 8, 2025

@copilot
looks like convertBreakdownToCSV is not used, would it be possible to convert new metrics format to CSV and flatten it by day?

I've addressed your feedback by removing the unused convertBreakdownToCSV function and implementing a comprehensive CSV export for the raw CopilotMetrics format. The solution now provides two CSV export options:

  1. Summary CSV - Exports the processed metrics data with aggregated totals (existing functionality)
  2. Full CSV - Exports the complete raw CopilotMetrics data flattened by day with detailed breakdowns

The Full CSV flattens all nested metrics data by day, including:

  • IDE Code Completions (by editor, model, and language)
  • IDE Chat (by editor and model)
  • Dotcom Chat (by model)
  • Dotcom Pull Requests (by repository and model)

This provides users with comprehensive access to all the detailed metrics data in a flat CSV format for analysis. The implementation includes proper TypeScript typing, comprehensive tests, and maintains backward compatibility.

Commit: 806eb72

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.fontshare.com
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
  • api.fontsource.org
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
  • fonts.bunny.net
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
  • fonts.google.com
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
  • fonts.googleapis.com
    • Triggering command: node (vitest 1) (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from karpikpl July 8, 2025 02:43
Copilot finished work on behalf of karpikpl July 8, 2025 02:43
@karpikpl karpikpl requested a review from Copilot July 8, 2025 03:41
@karpikpl karpikpl marked this pull request as ready for review July 8, 2025 03:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds CSV export capabilities for both summary and full metrics data, including utility functions, UI integration, and tests.

  • Introduces convertMetricsToCSV, convertCopilotMetricsToCSV, and downloadCSV utilities for CSV generation and download
  • Updates the API response component to include two new download buttons with handlers
  • Adds comprehensive unit tests for CSV export functions

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/csvExport.nuxt.spec.ts New unit tests covering summary and full CSV export edge cases
app/utils/csvExport.ts Implements CSV conversion and browser download functionality
app/components/ApiResponse.vue Adds "Download CSV" buttons and corresponding methods
app/model/MetricsToUsageConverter.ts Enhances conversion from CopilotMetrics to Metrics
app/model/MetricsValidator.ts Improves validation of continuous dates and invalid entries
app/model/Copilot_Metrics.ts Expands and types Copilot metrics model classes
Comments suppressed due to low confidence (2)

app/model/MetricsToUsageConverter.ts:4

  • [nitpick] The function name convertToMetrics is ambiguous—consider renaming it to convertCopilotMetricsToMetrics or similar to clearly convey its purpose.
export const convertToMetrics = (copilotMetrics: CopilotMetrics[]): Metrics[] => {

app/model/MetricsToUsageConverter.ts:4

  • The converter references Metrics and BreakdownData but they are not imported in this module, resulting in a compile error. Add import { Metrics, BreakdownData } from '@/model/Metrics'; at the top.
export const convertToMetrics = (copilotMetrics: CopilotMetrics[]): Metrics[] => {

console.error('Error generating CSV:', error);
}
this.showCopyMessage = true;
Copy link

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The showCopyMessage flag is reused for download notifications, which may overlap with copy-to-clipboard messages. Consider introducing a separate state (e.g., showDownloadMessage) for download success/error to improve clarity.

Copilot uses AI. Check for mistakes.
Comment on lines +31 to +40
if (prevDate && currDate) {
const diffDays = (currDate.getTime() - prevDate.getTime()) / (1000 * 60 * 60 * 24);

if (diffDays > 1) {
for (let d = 1; d < diffDays; d++) {
const missingDate = new Date(prevDate.getTime() + d * (1000 * 60 * 60 * 24));
const dateString = missingDate.toISOString().split('T')[0];
if (dateString) {
missingDates.push(dateString);
}
Copy link

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Since the dates array only contains valid Date objects, the prevDate and currDate null checks are redundant. You can simplify the loop by removing this guard.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot can you fix this?

@karpikpl karpikpl merged commit 1f2ba12 into main Jul 8, 2025
6 checks passed
@karpikpl karpikpl deleted the copilot/fix-223 branch July 8, 2025 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for export to CSV for data returned from the API

2 participants