Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Sep 11, 2023
1 parent aff3603 commit adb69b1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Stats.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useState, useEffect } from "react";
import { backend } from "./config/actor";
import { Chart } from "./components/Chart";
import { Chart, Pie } from "./components/Chart";

function extract_slice(raw, cond) {
return raw
const res = raw
.filter(([name, _]) => cond(name))
.map(([name, n]) => [name, Number(n)]);
res.sort((a, b) => b[1] - a[1]);
return res;
}
function join_slice(left, right) {
const l = Object.fromEntries(left);
Expand All @@ -15,7 +17,9 @@ function join_slice(left, right) {
left.map(([name, _]) => name).concat(right.map(([name, _]) => name))
),
];
return full_key.map((name) => [name, l[name] || 0, r[name] || 0]);
const res = full_key.map((name) => [name, l[name] || 0, r[name] || 0]);
res.sort((a, b) => b[2] - a[2]);
return res;
}
function two_metric(canisters, installs, title, cond) {
const new_canister = extract_slice(canisters, cond);
Expand All @@ -38,6 +42,7 @@ export function Stats() {

useEffect(() => {
async function doit() {
// eslint-disable-next-line
const [_, canisters, installs] = await backend.getStats();
setExample(
two_metric(
Expand All @@ -48,7 +53,7 @@ export function Stats() {
)
);
setRef(
two_metric(canisters, installs, "Ref link", (name) =>
two_metric(canisters, installs, "Reference link", (name) =>
name.startsWith("ref:")
)
);
Expand Down Expand Up @@ -80,9 +85,9 @@ export function Stats() {

return (
<>
<Pie title="Install mode" data={mode} />
<Chart title="Example" data={example} />
<Chart title="Ref link" data={ref} />
<Chart title="Install mode" data={mode} />
<Chart title="Reference link" data={ref} />
<Chart title="Origin" data={origin} />
<Chart title="Playground imports" data={imports} />
<Chart title="Moc" data={moc} />
Expand Down
21 changes: 21 additions & 0 deletions src/components/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,24 @@ export function Chart({ title, data }) {
</>
);
}

export function Pie({ title, data }) {
const options = {
title,
pieHole: 0.4,
is3D: false,
};
return (
<>
{data.length > 1 ? (
<GChart
chartType="PieChart"
data={data}
options={options}
width="80%"
height="300px"
/>
) : null}
</>
);
}

0 comments on commit adb69b1

Please sign in to comment.