-
Notifications
You must be signed in to change notification settings - Fork 22
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
83f29fe
commit 0570f01
Showing
8 changed files
with
244 additions
and
155 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,47 @@ | ||
import { useState, useEffect } from "react"; | ||
import { backend } from "./config/actor"; | ||
import { Chart } from "./components/Chart"; | ||
|
||
function extract_slice(raw, prefix) { | ||
const len = prefix.length; | ||
return raw | ||
.filter(([name, _]) => name.startsWith(prefix)) | ||
.map(([name, n]) => [name.slice(len), Number(n)]); | ||
} | ||
function join_slice(left, right) { | ||
const l = Object.fromEntries(left); | ||
const r = Object.fromEntries(right); | ||
const full_key = [ | ||
...new Set( | ||
left.map(([name, _]) => name).concat(right.map(([name, _]) => name)) | ||
), | ||
]; | ||
return full_key.map((name) => [name, l[name] || 0, r[name] || 0]); | ||
} | ||
function two_metric(canisters, installs, title, prefix) { | ||
const new_canister = extract_slice(canisters, prefix); | ||
const wasm = extract_slice(installs, prefix); | ||
return [[title, "Canister", "Wasm"]].concat(join_slice(new_canister, wasm)); | ||
} | ||
function one_metric(map, title, prefix) { | ||
const slice = extract_slice(map, prefix); | ||
return [[title, "Count"]].concat(slice); | ||
} | ||
|
||
export function Stats() { | ||
const [example, setExample] = useState([]); | ||
const [moc, setMoc] = useState([]); | ||
|
||
useEffect(async () => { | ||
const [_, canisters, installs] = await backend.getStats(); | ||
setExample(two_metric(canisters, installs, "Example", "example:")); | ||
setMoc(one_metric(installs, "Moc", "moc:")); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<Chart title="Example" data={example} /> | ||
<Chart title="Moc" data={moc} /> | ||
</> | ||
); | ||
} |
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,21 @@ | ||
import { Chart as GChart } from "react-google-charts"; | ||
|
||
export function Chart({ title, data }) { | ||
const height = 100 * (data.length - 1); | ||
const options = { | ||
title, | ||
chartArea: { width: "50%" }, | ||
hAxis: { minValue: 0 }, | ||
bars: "horizontal", | ||
}; | ||
return ( | ||
<GChart | ||
chartType="BarChart" | ||
data={data} | ||
options={options} | ||
width="80%" | ||
height="{height}px" | ||
legendToggle | ||
/> | ||
); | ||
} |
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
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