kopia lustrzana https://github.com/bugout-dev/moonstream
Add datatime switcher.
rodzic
44537e67f7
commit
e221f1d2d9
|
|
@ -20,9 +20,11 @@ import { v4 } from "uuid";
|
||||||
|
|
||||||
const HOUR_KEY = "Hourly";
|
const HOUR_KEY = "Hourly";
|
||||||
const DAY_KEY = "Daily";
|
const DAY_KEY = "Daily";
|
||||||
|
const MINUTE_KEY = "Minutes";
|
||||||
let timeMap = {};
|
let timeMap = {};
|
||||||
timeMap[HOUR_KEY] = "hour";
|
timeMap[DAY_KEY] = "month";
|
||||||
timeMap[DAY_KEY] = "day";
|
timeMap[HOUR_KEY] = "week";
|
||||||
|
timeMap[MINUTE_KEY] = "day";
|
||||||
|
|
||||||
const Analytics = () => {
|
const Analytics = () => {
|
||||||
const { toggleAlert } = useContext(OverlayContext);
|
const { toggleAlert } = useContext(OverlayContext);
|
||||||
|
|
@ -89,7 +91,7 @@ const Analytics = () => {
|
||||||
// [nodesReady]
|
// [nodesReady]
|
||||||
// );
|
// );
|
||||||
|
|
||||||
const [timeRange, setTimeRange] = useState(HOUR_KEY);
|
const [timeRange, setTimeRange] = useState(timeMap[MINUTE_KEY]);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { dashboardId } = router.params;
|
const { dashboardId } = router.params;
|
||||||
const { dashboardCache, dashboardLinksCache, deleteDashboard } =
|
const { dashboardCache, dashboardLinksCache, deleteDashboard } =
|
||||||
|
|
@ -169,10 +171,12 @@ const Analytics = () => {
|
||||||
</Heading>
|
</Heading>
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<RangeSelector
|
<RangeSelector
|
||||||
initialRange={timeRange}
|
initialRange={MINUTE_KEY}
|
||||||
ranges={Object.keys(timeMap)}
|
ranges={Object.keys(timeMap)}
|
||||||
size={["sm", "md", null]}
|
size={["sm", "md", null]}
|
||||||
onChange={(e) => setTimeRange(e)}
|
onChange={(e) => {
|
||||||
|
setTimeRange(timeMap[e]);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<IconButton
|
<IconButton
|
||||||
icon={<BiTrash />}
|
icon={<BiTrash />}
|
||||||
|
|
@ -210,7 +214,8 @@ const Analytics = () => {
|
||||||
{name}
|
{name}
|
||||||
</Text>
|
</Text>
|
||||||
<SubscriptionReport
|
<SubscriptionReport
|
||||||
url={s3PresignedURLs.week}
|
timeRange={timeRange}
|
||||||
|
url={s3PresignedURLs[timeRange]}
|
||||||
id={v4()}
|
id={v4()}
|
||||||
type={v4()}
|
type={v4()}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { ResponsiveLineCanvas } from "@nivo/line";
|
import { ResponsiveLineCanvas } from "@nivo/line";
|
||||||
|
|
||||||
const Report = ({ data, metric }) => {
|
const Report = ({ data, metric, timeRange }) => {
|
||||||
const commonProperties = {
|
const commonProperties = {
|
||||||
animate: false,
|
animate: false,
|
||||||
enableSlices: "x",
|
enableSlices: "x",
|
||||||
|
|
@ -24,7 +24,29 @@ const Report = ({ data, metric }) => {
|
||||||
|
|
||||||
const xyCumulativeData = xyData.map(generateCumulativeSum(0));
|
const xyCumulativeData = xyData.map(generateCumulativeSum(0));
|
||||||
|
|
||||||
console.log(`metric ${metric} \n xyCumulativeData: `, xyCumulativeData);
|
const timeformat_scale = {
|
||||||
|
month: "%Y-%m-%d %H",
|
||||||
|
week: "%Y-%m-%d %H",
|
||||||
|
day: "%Y-%m-%d %H %M",
|
||||||
|
};
|
||||||
|
|
||||||
|
const timeformat_xformat = {
|
||||||
|
month: "time:%Y-%m-%d %H",
|
||||||
|
week: "time:%Y-%m-%d %H",
|
||||||
|
day: "time:%Y-%m-%d %H %M",
|
||||||
|
};
|
||||||
|
|
||||||
|
const axis_format = {
|
||||||
|
month: "%m-%d",
|
||||||
|
week: "%d",
|
||||||
|
day: "%H:%M",
|
||||||
|
};
|
||||||
|
|
||||||
|
const tickValues_format = {
|
||||||
|
month: "every 1 days",
|
||||||
|
week: "every 1 days",
|
||||||
|
day: "every 1 hours",
|
||||||
|
};
|
||||||
|
|
||||||
const plotData = [{ id: "1", data: xyCumulativeData }];
|
const plotData = [{ id: "1", data: xyCumulativeData }];
|
||||||
|
|
||||||
|
|
@ -36,11 +58,11 @@ const Report = ({ data, metric }) => {
|
||||||
isInteractive={true}
|
isInteractive={true}
|
||||||
xScale={{
|
xScale={{
|
||||||
type: "time",
|
type: "time",
|
||||||
format: "%Y-%m-%d %H",
|
format: timeformat_scale[timeRange],
|
||||||
useUTC: false,
|
useUTC: false,
|
||||||
precision: "hour",
|
precision: "minute",
|
||||||
}}
|
}}
|
||||||
xFormat="time:%Y-%m-%d %H"
|
xFormat={timeformat_xformat[timeRange]}
|
||||||
yScale={{
|
yScale={{
|
||||||
type: "linear",
|
type: "linear",
|
||||||
max: "auto",
|
max: "auto",
|
||||||
|
|
@ -56,14 +78,14 @@ const Report = ({ data, metric }) => {
|
||||||
legend: "count",
|
legend: "count",
|
||||||
}}
|
}}
|
||||||
axisBottom={{
|
axisBottom={{
|
||||||
format: "%Y-%m-%d",
|
format: axis_format[timeRange],
|
||||||
tickValues: "every 1 day",
|
tickValues: tickValues_format[timeRange],
|
||||||
legend: "time",
|
legend: "time",
|
||||||
tickRotation: 0,
|
tickRotation: 0,
|
||||||
legendOffset: 35,
|
legendOffset: 35,
|
||||||
legendPosition: "middle",
|
legendPosition: "middle",
|
||||||
}}
|
}}
|
||||||
curve={"basis"}
|
curve={"monotoneY"}
|
||||||
enableArea={true}
|
enableArea={true}
|
||||||
enablePointLabel={false}
|
enablePointLabel={false}
|
||||||
pointSize={0}
|
pointSize={0}
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,13 @@ timeMap[HOUR_KEY] = "hour";
|
||||||
timeMap[DAY_KEY] = "day";
|
timeMap[DAY_KEY] = "day";
|
||||||
timeMap[WEEK_KEY] = "week";
|
timeMap[WEEK_KEY] = "week";
|
||||||
|
|
||||||
const SubscriptionReport = ({ url, id, type }) => {
|
const SubscriptionReport = ({ timeRange, url, id, type }) => {
|
||||||
const { data, isLoading } = usePresignedURL({
|
const { data, isLoading } = usePresignedURL({
|
||||||
url: url,
|
url: url,
|
||||||
isEnabled: true,
|
isEnabled: true,
|
||||||
id: id,
|
id: id,
|
||||||
type: type,
|
type: type,
|
||||||
});
|
});
|
||||||
|
|
||||||
const plotMinW = "500px";
|
const plotMinW = "500px";
|
||||||
if (!data || isLoading) return <Spinner />;
|
if (!data || isLoading) return <Spinner />;
|
||||||
return (
|
return (
|
||||||
|
|
@ -86,7 +85,11 @@ const SubscriptionReport = ({ url, id, type }) => {
|
||||||
>
|
>
|
||||||
{key}
|
{key}
|
||||||
</Text>
|
</Text>
|
||||||
<Report data={data.events[key]} metric={key} />
|
<Report
|
||||||
|
data={data.events[key]}
|
||||||
|
metric={key}
|
||||||
|
timeRange={timeRange}
|
||||||
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
@ -123,7 +126,11 @@ const SubscriptionReport = ({ url, id, type }) => {
|
||||||
>
|
>
|
||||||
{key}
|
{key}
|
||||||
</Text>
|
</Text>
|
||||||
<Report data={data.functions[key]} metric={key} />
|
<Report
|
||||||
|
data={data.functions[key]}
|
||||||
|
metric={key}
|
||||||
|
timeRange={timeRange}
|
||||||
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
@ -160,7 +167,11 @@ const SubscriptionReport = ({ url, id, type }) => {
|
||||||
>
|
>
|
||||||
{key}
|
{key}
|
||||||
</Text>
|
</Text>
|
||||||
<Report data={data.generic[key]} metric={key} />
|
<Report
|
||||||
|
data={data.generic[key]}
|
||||||
|
metric={key}
|
||||||
|
timeRange={timeRange}
|
||||||
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue