Skip to content

Commit 11c7306

Browse files
committed
updated credits per voxel information
1 parent e29b9b4 commit 11c7306

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

frontend/javascripts/viewer/view/ai_jobs/credit_information.tsx

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
import { type JobCreditCostInfo, getJobCreditCost } from "admin/rest_api";
22
import { Button, Card, Col, Row, Spin, Typography } from "antd";
3-
import { formatCreditsString } from "libs/format_utils";
3+
import { formatCreditsString, formatVoxels } from "libs/format_utils";
44
import { useFetch } from "libs/react_helpers";
55
import { useWkSelector } from "libs/react_hooks";
66
import { computeArrayFromBoundingBox } from "libs/utils";
77
import type React from "react";
88
import { useRunAiModelJobContext } from "./run_ai_model/ai_image_segmentation_job_context";
9+
import BoundingBox from "viewer/model/bucket_data_handling/bounding_box";
10+
import { useCallback, useMemo } from "react";
11+
import { APIJobType } from "types/api_types";
12+
import features from "features";
913

1014
const { Title, Text } = Typography;
1115

1216
export const CreditInformation: React.FC = () => {
17+
const jobTypeToCreditCostPerGVx: Record<APIJobType, number> = useMemo(
18+
() => ({
19+
[APIJobType.INFER_NUCLEI]: features().neuronInferralCostPerGVx,
20+
[APIJobType.INFER_NEURONS]: features().neuronInferralCostPerGVx,
21+
[APIJobType.INFER_MITOCHONDRIA]: features().mitochondriaInferralCostPerGVx,
22+
[APIJobType.INFER_INSTANCES]: features().neuronInferralCostPerGVx,
23+
}),
24+
[],
25+
);
26+
1327
const { selectedModel, selectedJobType, selectedBoundingBox, handleStartAnalysis } =
1428
useRunAiModelJobContext();
1529
const organizationCredits = useWkSelector(
@@ -28,6 +42,14 @@ export const CreditInformation: React.FC = () => {
2842
[selectedBoundingBox, selectedJobType],
2943
);
3044

45+
const getBoundingBoxinVoxels = useCallback((): string => {
46+
if (selectedBoundingBox) {
47+
const bbVolumeInVx = new BoundingBox(selectedBoundingBox.boundingBox).getVolume();
48+
return formatVoxels(bbVolumeInVx);
49+
}
50+
return "-";
51+
}, [selectedBoundingBox]);
52+
3153
const costInCredits = jobCreditCostInfo?.costInCredits;
3254

3355
return (
@@ -54,10 +76,18 @@ export const CreditInformation: React.FC = () => {
5476
</Row>
5577
<Row justify="space-between">
5678
<Col>
57-
<Text>Dataset Size (Est.):</Text>
79+
<Text>Dataset Size:</Text>
80+
</Col>
81+
<Col>
82+
<Text strong>{getBoundingBoxinVoxels()}</Text>
83+
</Col>
84+
</Row>
85+
<Row justify="space-between">
86+
<Col>
87+
<Text>Credits per Gigavoxel:</Text>
5888
</Col>
5989
<Col>
60-
<Text strong>{selectedBoundingBox ? "Selected" : "-"}</Text>
90+
<Text strong>{selectedJobType ? jobTypeToCreditCostPerGVx[selectedJobType] : "-"}</Text>
6191
</Col>
6292
</Row>
6393
<hr style={{ margin: "24px 0" }} />
@@ -69,7 +99,7 @@ export const CreditInformation: React.FC = () => {
6999
{jobCreditCostInfo === undefined && selectedBoundingBox && selectedModel ? (
70100
<Spin size="small" />
71101
) : (
72-
<Text strong>{costInCredits ? formatCreditsString(costInCredits) : "FREE"}</Text>
102+
<Text strong>{costInCredits ? formatCreditsString(costInCredits) : "-"}</Text>
73103
)}
74104
</Col>
75105
</Row>
@@ -78,7 +108,7 @@ export const CreditInformation: React.FC = () => {
78108
block
79109
size="large"
80110
style={{ marginTop: "24px" }}
81-
disabled={!selectedModel || !selectedBoundingBox}
111+
disabled={!selectedModel || !selectedBoundingBox || !jobCreditCostInfo?.hasEnoughCredits}
82112
onClick={handleStartAnalysis}
83113
>
84114
Start Analysis

0 commit comments

Comments
 (0)