-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f357904
commit dcfa2a8
Showing
2 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { useState } from "react" | ||
import { | ||
BarChart, | ||
Block, | ||
Card, | ||
Flex, | ||
Text, | ||
Title, | ||
Toggle, | ||
ToggleItem, | ||
} from "@tremor/react" | ||
import useSWR from "swr" | ||
import { fetcher, useUrlFilters } from "../lib/helpers" | ||
|
||
// Basic formatters for the chart values | ||
const dollarFormatter = (value: number) => | ||
`$ ${Intl.NumberFormat("us").format(value).toString()}` | ||
|
||
const numberFormatter = (value: number) => | ||
`${Intl.NumberFormat("us").format(value).toString()}` | ||
|
||
export default function ChartView() { | ||
const filters = useUrlFilters() | ||
const [selectedKpi, setSelectedKpi] = useState("tally") | ||
const { data, error } = useSWR( | ||
["https://play.clickhouse.com/?user=play", `pull-requests-${filters.org}`], | ||
([url]) => | ||
fetcher(url, { | ||
method: "POST", | ||
body: ` | ||
with | ||
events as ( | ||
SELECT * | ||
FROM github_events | ||
WHERE repo_name like '${filters.org}/%' and event_type = 'PullRequestEvent' | ||
), | ||
timeseries as ( | ||
WITH | ||
coalesce(toStartOfDay((select min(created_at) from events)), today()) AS start, | ||
coalesce(toStartOfDay((select max(created_at) from events)), today()) AS end | ||
SELECT arrayJoin( | ||
arrayMap( | ||
x -> toDate(x), | ||
range( | ||
toUInt32(start), | ||
toUInt32(end), | ||
24 * 3600 | ||
) | ||
) | ||
) as date | ||
), | ||
opened as ( | ||
select count(*) as opened, toDate(created_at) as created_at | ||
from events where (action = 'opened' or action = 'reopened') | ||
group by created_at | ||
), | ||
closed as ( | ||
select count(*) as closed, toDate(created_at) as created_at | ||
from events where action = 'closed' | ||
group by created_at | ||
), | ||
stats as ( | ||
select | ||
timeseries.date as date, | ||
sum(opened.opened) as opened, | ||
sum(closed.closed) as closed, | ||
sum(opened.opened - closed.closed) as tally | ||
from | ||
timeseries | ||
left join | ||
closed on closed.created_at = timeseries.date | ||
left join | ||
opened on opened.created_at = timeseries.date | ||
group by | ||
timeseries.date | ||
) | ||
SELECT | ||
date, | ||
sum(opened) as opened, | ||
sum(closed) as closed, | ||
sum(sum(tally)) OVER w AS tally | ||
FROM | ||
stats | ||
GROUP BY date | ||
WINDOW w AS (ORDER BY date ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) | ||
FORMAT JSON`, | ||
}) | ||
) | ||
// console.log("data", data) | ||
// console.log("error", error) | ||
|
||
// map formatters by selectedKpi | ||
const formatters: { [key: string]: any } = { | ||
Sales: dollarFormatter, | ||
Profit: dollarFormatter, | ||
Customers: numberFormatter, | ||
} | ||
|
||
if (!data) return <div>Loading...</div> | ||
|
||
const chartData = data.data | ||
return ( | ||
<Card> | ||
<div className="md:flex justify-between"> | ||
<Block> | ||
<Flex | ||
justifyContent="justify-start" | ||
spaceX="space-x-0.5" | ||
alignItems="items-center" | ||
> | ||
<Title>Issue History</Title> | ||
</Flex> | ||
<Text>Issue growth across all repos</Text> | ||
</Block> | ||
<div className="mt-6 md:mt-0"> | ||
<Toggle | ||
color="zinc" | ||
defaultValue={selectedKpi} | ||
handleSelect={(value) => setSelectedKpi(value)} | ||
> | ||
<ToggleItem value="tally" text="Tally" /> | ||
<ToggleItem value="opened" text="Opened" /> | ||
<ToggleItem value="closed" text="Closed" /> | ||
</Toggle> | ||
</div> | ||
</div> | ||
<BarChart | ||
data={chartData} | ||
dataKey="date" | ||
categories={[selectedKpi]} | ||
colors={["blue"]} | ||
showLegend={false} | ||
valueFormatter={formatters[selectedKpi]} | ||
yAxisWidth="w-14" | ||
height="h-96" | ||
marginTop="mt-8" | ||
/> | ||
</Card> | ||
) | ||
} |
dcfa2a8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
githubanalytics – ./
githubanalytics-copple.vercel.app
githubanalytics-ashen.vercel.app
www.githubanalytics.co
githubanalytics-git-main-copple.vercel.app
githubanalytics.co