Skip to content

Commit

Permalink
Update webui with GitHub link and chart page (#6)
Browse files Browse the repository at this point in the history
* Update webui with GitHub link and chart page

Add GitHub link icon and new chart page to web UI.

* **Add GitHub link icon**
  - Add a GitHub link icon to the top-right corner of all pages in `webapp/index.html`.
  - Link the icon to the GitHub repository URL.

* **Create ChartPage component**
  - Add a new file `webapp/src/components/ChartPage.tsx` to create a React component for displaying the chart.
  - Use Chart.js to render the chart.
  - Load data from `assets/pr_counts_by_date.csv` and display it as a line chart.

* **Update main.tsx for routing**
  - Modify `webapp/src/main.tsx` to include routing for the new chart page.
  - Import and use the `ChartPage` component.

* **Update README.md**
  - Add instructions for accessing the new chart page.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/kaakaa/ai-agent-statistics?shareId=XXXX-XXXX-XXXX-XXXX).

* Add chart data fetching and routing for ChartPage component

* **ChartPage.tsx**
  - Replace d3-fetch with fetch API to load CSV data
  - Parse CSV data and update chartData state

* **main.tsx**
  - Replace `Switch` with `Routes` for routing
  - Update `Route` components to use `element` prop instead of `component` prop

* feat: support subpath settings

* feat: add new chart page

* Update webapp/src/components/statistics/PullRequestsCount.tsx

Co-authored-by: Copilot <[email protected]>

* Update webapp/src/components/statistics/PullRequestsCount.tsx

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
  • Loading branch information
kaakaa and Copilot authored Jan 3, 2025
1 parent d3a88e8 commit dcd8182
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ $ npm run preview
=> access to http://localhost:4173/ai-agent-statistics
```

## Accessing the Chart Page

To view the chart of PR counts by date, follow these steps:

1. Open your web browser.
2. Navigate to the following URL: `http://localhost:4173/ai-agent-statistics/chart`
3. You will see a line chart displaying the PR counts by date.
10 changes: 10 additions & 0 deletions webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AI-Agent Statistics</title>
<style>
.github-icon {
position: absolute;
top: 10px;
right: 10px;
}
</style>
</head>
<body>
<a href="https://github.com/kaakaa/ai-agent-statistics" class="github-icon">
<img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" alt="GitHub" width="32" height="32">
</a>
<div id="root"></div>
<script type="module" src="./src/main.tsx"></script>
</body>
Expand Down
76 changes: 75 additions & 1 deletion webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
"@mui/material": "^6.3.0",
"@mui/x-data-grid": "^7.23.5",
"@tanstack/react-table": "^8.20.6",
"chart.js": "^4.4.7",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-chartjs-2": "^5.3.0",
"react-dom": "^18.3.1",
"react-router": "^7.1.1"
},
"devDependencies": {
"@eslint/js": "^9.17.0",
Expand Down
55 changes: 55 additions & 0 deletions webapp/src/components/Statistics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { useEffect, useState } from 'react';
import { Chart as ChartJS, CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend } from 'chart.js';

import { PRCount } from '../types';
import PullRequestsCountChart from './statistics/PullRequestsCount';
import ReposCountChart from './statistics/ReposCount';

ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend);

export type ChartDataType = {
labels: string[];
datasets: {
label: string;
data: number[];
borderColor: string;
backgroundColor: string
}[];
}

const StatisticsPage = () => {
const [prCounts, setPrCounts] = useState<PRCount[]>([]);

useEffect(() => {
const fetchData = async () => {
const basepath = import.meta.env.BASE_URL
const baseUrl = `${window.location.protocol}//${window.location.host}${basepath}`.replace(/\/$/, '');
console.log(`fetch pr_counts_by_date.csv from baseUrl: ${baseUrl}`);
const resp = await fetch(`${baseUrl}/assets/pr_counts_by_date.csv`);

const csv = await resp.text();
const prCounts: PRCount[]= csv.split('\n').slice(1).map(row => {
const values = row.split(',');
return {
date: values[0],
author: values[1],
count: parseInt(values[2], 10),
repos: parseInt(values[3], 10),
}
});
setPrCounts(prCounts);
};
fetchData();
}, []);

return (
<div>
<h1>PR Count by Date</h1>
<PullRequestsCountChart prCounts={prCounts} />
<h1>Repos Count by Date</h1>
<ReposCountChart prCounts={prCounts} />
</div>
);
};

export default StatisticsPage;
34 changes: 34 additions & 0 deletions webapp/src/components/statistics/PullRequestsCount.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Line } from 'react-chartjs-2';

import { PRCount } from '../../types';

type ChartProps = {
prCounts: PRCount[];
}

const PullRequestsCountChart = ({prCounts}: ChartProps) => {
const authors = [
{name: "devin-ai-integration", color: 'rgba(0, 180, 170, 1)'},
{name: "devloai", color: 'rgba(0, 122, 255, 1)'},
{name: "openhands-agent", color: 'rgba(255, 204, 0, 1)'},
];
const labels = Array.from(new Set(prCounts.map((prCount: PRCount) => prCount.date)));

const datasets = authors.map(author => {
const countsByAuthor = prCounts.filter((prCount: PRCount) => prCount.author === author.name)
const counts = labels.map(date => countsByAuthor.find((c: PRCount) => c.date === date)?.count || 0);
return {
label: author.name,
data: counts,
borderColor: author.color,
backgroundColor: 'rgba(75, 192, 192, 0.2)',
}
});
return (
<>
<Line data={{labels, datasets: datasets}} />
</>
)
}

export default PullRequestsCountChart;
34 changes: 34 additions & 0 deletions webapp/src/components/statistics/ReposCount.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Line } from 'react-chartjs-2';

import { PRCount } from '../../types';

type ChartProps = {
prCounts: PRCount[];
}

const ReposCountChart = ({prCounts}: ChartProps) => {
const authors = [
{name: "devin-ai-integration", color: 'rgba(0, 180, 170, 1)'},
{name: "devloai", color: 'rgba(0, 122, 255, 1)'},
{name: "openhands-agent", color: 'rgba(255, 204, 0, 1)'},
];
const labels = Array.from(new Set(prCounts.map((prCount: any) => prCount.date)));

const datasets = authors.map(author => {
const countsByAuthor = prCounts.filter((prCount: any) => prCount.author === author.name)
const counts = labels.map(date => countsByAuthor.find((c: PRCount) => c.date === date)?.repos || 0);
return {
label: author.name,
data: counts,
borderColor: author.color,
backgroundColor: 'rgba(75, 192, 192, 0.2)',
}
});
return (
<>
<Line data={{labels, datasets: datasets}} />
</>
)
}

export default ReposCountChart;
11 changes: 10 additions & 1 deletion webapp/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { BrowserRouter as Router, Route, Routes } from 'react-router';
import './index.css'
import PullRequestsTable from './components/PullRequests.tsx'
import StatisticsPage from './components/Statistics.tsx';

const base = import.meta.env.BASE_URL

createRoot(document.getElementById('root')!).render(
<StrictMode>
<PullRequestsTable />
<Router basename={base}>
<Routes>
<Route path="/" element={<PullRequestsTable />} />
<Route path="/chart" element={<StatisticsPage />} />
</Routes>
</Router>
</StrictMode>,
)
6 changes: 6 additions & 0 deletions webapp/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type PRCount = {
date: string;
author: string;
count: number;
repos: number;
}

0 comments on commit dcd8182

Please sign in to comment.