Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
thewbuk committed Nov 5, 2024
1 parent 6a6076c commit c1e25e1
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ModelTriggerTableRecord } from "instill-sdk";

import { formatDateTime } from "./formatDateTime";
import { getDateRange } from "./getDateRange";
import { sortByDate } from "./sortByDate";
Expand All @@ -18,10 +19,15 @@ export function generateModelTriggerChartRecordData(
const timeBuckets = model.timeBuckets ?? [];

// Format the time buckets
const formattedTimeBuckets = timeBuckets.map(bucket => formatDateTime(bucket, range));
const formattedTimeBuckets = timeBuckets.map((bucket) =>
formatDateTime(bucket, range),
);

// Sort and deduplicate xAxis
const xAxisSortedDates = sortByDate([...getDateRange(range), ...formattedTimeBuckets]);
const xAxisSortedDates = sortByDate([
...getDateRange(range),
...formattedTimeBuckets,
]);
const xAxis = Array.from(new Set(xAxisSortedDates));

// Initialize yAxis with zeros
Expand All @@ -30,7 +36,7 @@ export function generateModelTriggerChartRecordData(
// Populate yAxis with trigger counts
timeBuckets.forEach((bucket, index) => {
const formattedBucket = formatDateTime(bucket, range);
const xAxisIndex = xAxis.findIndex(date => date === formattedBucket);
const xAxisIndex = xAxis.findIndex((date) => date === formattedBucket);
if (xAxisIndex !== -1) {
yAxis[xAxisIndex] += model.triggerCounts?.[index] ?? 0;
}
Expand Down
49 changes: 26 additions & 23 deletions packages/toolkit/src/lib/dashboard/getModelTriggersSummary.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import { ModelTriggerCountRecord, ModelTriggersStatusSummary } from "instill-sdk";
import {
ModelTriggerCountRecord,
ModelTriggersStatusSummary,
} from "instill-sdk";

export function getModelTriggersSummary(
modelTriggerCounts: ModelTriggerCountRecord[]
modelTriggerCounts: ModelTriggerCountRecord[],
): ModelTriggersStatusSummary {
const completedModel = modelTriggerCounts.find(
(r) => r.status === "STATUS_COMPLETED"
);
const completedModel = modelTriggerCounts.find(
(r) => r.status === "STATUS_COMPLETED",
);

const erroredModel = modelTriggerCounts.find(
(r) => r.status === "STATUS_ERRORED"
);
const erroredModel = modelTriggerCounts.find(
(r) => r.status === "STATUS_ERRORED",
);

return {
completed: {
statusType: "STATUS_COMPLETED" as const,
type: "model" as const,
amount: completedModel?.triggerCount || 0,
delta: 0
},
errored: {
statusType: "STATUS_ERRORED" as const,
type: "model" as const,
amount: erroredModel?.triggerCount || 0,
delta: 0
}
};
}
return {
completed: {
statusType: "STATUS_COMPLETED" as const,
type: "model" as const,
amount: completedModel?.triggerCount || 0,
delta: 0,
},
errored: {
statusType: "STATUS_ERRORED" as const,
type: "model" as const,
amount: erroredModel?.triggerCount || 0,
delta: 0,
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,40 @@

import { useQuery } from "@tanstack/react-query";
import { ListModelTriggerCountRequest, Nullable } from "instill-sdk";

import { getInstillAPIClient } from "../../sdk-helper";

export function useModelTriggerCount({
enabled,
accessToken,
requesterId,
start,
stop,
enabled,
accessToken,
requesterId,
start,
stop,
}: {
enabled: boolean;
accessToken: Nullable<string>;
requesterId: string;
start?: string;
stop?: string;
enabled: boolean;
accessToken: Nullable<string>;
requesterId: string;
start?: string;
stop?: string;
}) {
return useQuery({
queryKey: ["modelTriggerCount", requesterId, start, stop],
queryFn: async () => {
if (!accessToken) {
throw new Error("accessToken not provided");
}
return useQuery({
queryKey: ["modelTriggerCount", requesterId, start, stop],
queryFn: async () => {
if (!accessToken) {
throw new Error("accessToken not provided");
}

const client = getInstillAPIClient({ accessToken });
const client = getInstillAPIClient({ accessToken });

const request: ListModelTriggerCountRequest = {
requesterId,
start,
stop,
};
const request: ListModelTriggerCountRequest = {
requesterId,
start,
stop,
};

const data = await client.core.metric.listModelTriggerCount(request);
return data;
},
enabled: enabled && !!requesterId,
});
const data = await client.core.metric.listModelTriggerCount(request);
return data;
},
enabled: enabled && !!requesterId,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ export function useModelTriggerMetric({
},
enabled,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
useUserNamespaces,
} from "../../../../lib";
import { getHumanReadableStringFromTime } from "../../../../server";
import { TABLE_PAGE_SIZE } from "../../../pipeline/view-pipeline/constants";
import { truncateName } from "../../../catalog";
import { TABLE_PAGE_SIZE } from "../../../pipeline/view-pipeline/constants";

const selector = (store: InstillStore) => ({
accessToken: store.accessToken,
Expand Down Expand Up @@ -189,9 +189,9 @@ export const DashboardListModel = ({ start }: DashboardListModelProps) => {
<div className="font-normal text-semantic-bg-secondary-alt-primary">
{createTime
? getHumanReadableStringFromTime(
createTime as string,
Date.now(),
)
createTime as string,
Date.now(),
)
: "-"}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
useUserNamespaces,
} from "../../../../lib";
import { getHumanReadableStringFromTime } from "../../../../server";
import { TABLE_PAGE_SIZE } from "../../../pipeline/view-pipeline/constants";
import { truncateName } from "../../../catalog";
import { TABLE_PAGE_SIZE } from "../../../pipeline/view-pipeline/constants";

const selector = (store: InstillStore) => ({
accessToken: store.accessToken,
Expand Down

0 comments on commit c1e25e1

Please sign in to comment.