Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

161 Add API calls UUID Seed lIst #162

Merged
merged 9 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nachet-frontend",
"private": true,
"version": "0.8.4",
"version": "0.8.5",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
64 changes: 44 additions & 20 deletions src/App.tsx
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HashRouter as Router, Route, Routes } from "react-router-dom";
import { useCallback, Fragment, useState, useEffect } from "react";
import { v4 as uuidv4 } from "uuid";
// import { v4 as uuidv4 } from "uuid";
import Cookies from "js-cookie";
import Navbar from "./components/header/navbar";
import Body from "./root/body";
Expand All @@ -19,6 +19,7 @@ function App({
height: window.innerHeight,
});
const [uuid, setUuid] = useState<string>("");
// const [container_uuid, setContainerUuid] = useState<string>("");
const [creativeCommonsPopupOpen, setCreativeCommonsPopupOpen] =
useState<boolean>(false);
const [switchLanguage, setSwitchLanguage] = useState<boolean>(false);
Expand Down Expand Up @@ -47,29 +48,49 @@ function App({
}
}, []);

const createUuid = useCallback((): void => {
// create a new uuid for user and set a cookie to remember it for 10 years (it is used to identify user container in azure storage)
const newUuid = uuidv4();
setUuid(newUuid);
Cookies.set("user-uuid", newUuid, { expires: 365 * 10 });
}, []);
// const createContainerUuid = useCallback((): void => {
// // create a new uuid for user and set a cookie to remember it for 10 years (it is used to identify user container in azure storage)
// const newUuid = uuidv4();
// setContainerUuid(newUuid);
// Cookies.set("container-uuid", newUuid, { expires: 365 * 10 });
// }, []);

const getUuid = useCallback((): void => {
// check if the user has already a uuid (cookie)
const existingUuid = Cookies.get("user-uuid") as string;
if (existingUuid !== undefined) {
setUuid(existingUuid);
console.log("Existing UUID: " + existingUuid);
} else {
console.log("Creating new UUID");
createUuid();
}
}, [createUuid]);
// const getContainerUuid = useCallback((): void => {
// // check if the user has already a uuid (cookie)
// const existingUuid = Cookies.get("container-uuid") as string;
// if (existingUuid !== undefined) {
// setContainerUuid(existingUuid);
// console.log("Existing Container UUID: " + existingUuid);
// } else {
// console.log("Creating new Container UUID");
// createContainerUuid();
// }
// }, [createContainerUuid]);

// const handleSignIn = (): void => {
// setSignedIn(true);
// };

// // uuid will check if an email is already stored in the cookie, if not setsignup open
// const getUuid = useCallback((): void => {
// // check if the user has email stored in the cookie
// const email: string | undefined = Cookies.get("user-email");
// if (email == null || !email.includes("@") || !signedIn) {
// setSignUpOpen(true);
// } else {
// requestUUID(email)
// .then((response) => {
// setUuid(response.data.uuid);
// Cookies.set("user-uuid", response.data.uuid, { expires: 30 });
// }
// setUuid(uuid);
// Cookies.set("user-uuid", uuid, { expires: 30 });
// }
// }, [signedIn]);

useEffect(() => {
getUuid();
getCreativeCommonsAgreement();
}, [getUuid, getCreativeCommonsAgreement]);
}, [getCreativeCommonsAgreement]);

useEffect(() => {
// update window size on resize
Expand Down Expand Up @@ -112,6 +133,9 @@ function App({
handleCreativeCommonsAgreement={handleCreativeCommonsAgreement}
setSignUpOpen={setSignUpOpen}
signUpOpen={signUpOpen}
signedIn={signedIn}
setSignedIn={setSignedIn}
setUuid={setUuid}
/>
}
/>
Expand Down
8 changes: 4 additions & 4 deletions src/_versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export interface TsAppVersion {
gitTag?: string;
};
export const versions: TsAppVersion = {
version: '0.8.4',
version: '0.8.5',
name: 'nachet-frontend',
versionDate: '2024-05-30T04:19:03.983Z',
gitCommitHash: 'd019904',
versionLong: '0.8.4-d019904',
versionDate: '2024-06-05T14:39:44.056Z',
gitCommitHash: '9074593',
versionLong: '0.8.5-9074593',
};
export default versions;
63 changes: 59 additions & 4 deletions src/common/api.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from "axios";
import { AzureAPIError, ValueError } from "./error";
import {
ApiInferenceData,
ApiSpeciesData,
FeedbackDataNegative,
FeedbackDataPositive,
Images,
Expand Down Expand Up @@ -43,7 +44,9 @@ const handleAxios = async <T>(request: {
export const readAzureStorageDir = async (
backendUrl: string,
uuid: string,
): Promise<void> => {
): Promise<{
[key: string]: number;
}> => {
if (backendUrl === "" || backendUrl == null) {
throw new ValueError("Backend URL is null or empty");
}
Expand Down Expand Up @@ -128,7 +131,8 @@ export const inferenceRequest = async (
imageObject: Images,
curDir: string,
uuid: string,
): Promise<ApiInferenceData[]> => {
container_uuid: string,
): Promise<ApiInferenceData> => {
if (backendUrl === "" || backendUrl == null) {
throw new ValueError("Backend URL is null or empty");
}
Expand Down Expand Up @@ -156,10 +160,11 @@ export const inferenceRequest = async (
image: imageObject.src,
imageDims: imageObject.imageDims,
folder_name: curDir,
container_name: uuid,
user_id: uuid,
container_name: container_uuid,
},
};
return handleAxios<ApiInferenceData[]>(request);
return handleAxios<ApiInferenceData>(request);
};

export const fetchModelMetadata = async (
Expand Down Expand Up @@ -236,3 +241,53 @@ export const sendNegativeFeedback = async (
};
return handleAxios(request);
};

export const requestUUID = async (
backendUrl: string,
email: string,
): Promise<{
user_id: string;
}> => {
if (backendUrl === "" || backendUrl == null) {
throw new ValueError("Backend URL is null or empty");
}
const request = {
method: "post",
url: `${backendUrl}/get-user-id`,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
data: {
email: email,
},
};
return handleAxios<{
user_id: string;
}>(request);
};

export const requestClassList = async (
backendUrl: string,
// uuid: string,
): Promise<ApiSpeciesData> => {
if (backendUrl === "" || backendUrl == null) {
throw new ValueError("Backend URL is null or empty");
}
// if (uuid === "" || uuid == null) {
// throw new ValueError("UUID is null or empty");
// }
const request = {
method: "get",
url: `${backendUrl}/seeds`,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
data: {},
// data: {
// uuid: uuid,
// },
};
return handleAxios<ApiSpeciesData>(request);
};
6 changes: 3 additions & 3 deletions src/common/cacheutils.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ export const loadResultsToCache = (
boxes: inferenceData.boxes.map((box) => {
return {
...box.box,
inferenceId: inferenceData.inferenceId,
boxId: box.boxId,
classId: box.classId,
inferenceId: inferenceData.inference_id,
boxId: box.box_id,
classId: box.object_type_id,
label: box.label,
};
}),
Expand Down
8 changes: 8 additions & 0 deletions src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
deleteAzureStorageDir,
inferenceRequest,
fetchModelMetadata,
requestClassList,
sendNegativeFeedback,
sendPositiveFeedback,
requestUUID,
} from "./api";
import {
loadToCanvas,
Expand Down Expand Up @@ -42,4 +46,8 @@ export {
loadResultsToCache,
getLabelOccurrence,
getScaledBounds,
requestClassList,
sendNegativeFeedback,
sendPositiveFeedback,
requestUUID,
};
1 change: 1 addition & 0 deletions src/common/tests/api.test.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ describe("inferenceRequest", () => {
imageObject,
curDir,
uuid,
uuid,
),
).toEqual("data");
});
Expand Down
22 changes: 14 additions & 8 deletions src/common/tests/loadresultstocache.test.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ describe("loadResultsToCache", () => {
let inferenceData: ApiInferenceData = {
filename: "test",
imageId: "test",
inferenceId: "test",
inference_id: "test",
boxes: [
{
score: 0.1,
classId: "0",
label: "a",
boxId: "0",
box_id: "0",
object_type_id: "0",
box: {
topX: 1,
topY: 1,
Expand All @@ -42,7 +43,8 @@ describe("loadResultsToCache", () => {
score: 0.2,
classId: "1",
label: "b",
boxId: "1",
box_id: "1",
object_type_id: "1",
box: {
topX: 2,
topY: 2,
Expand All @@ -57,7 +59,8 @@ describe("loadResultsToCache", () => {
score: 0.3,
classId: "2",
label: "c",
boxId: "2",
box_id: "2",
object_type_id: "2",
box: {
topX: 3,
topY: 3,
Expand Down Expand Up @@ -92,13 +95,14 @@ describe("loadResultsToCache", () => {
inferenceData = {
filename: "test",
imageId: "test",
inferenceId: "test",
inference_id: "test",
boxes: [
{
score: 0.1,
classId: "0",
label: "a",
boxId: "0",
box_id: "0",
object_type_id: "0",
box: {
topX: 1,
topY: 1,
Expand All @@ -113,7 +117,8 @@ describe("loadResultsToCache", () => {
score: 0.2,
classId: "1",
label: "b",
boxId: "1",
box_id: "1",
object_type_id: "1",
box: {
topX: 2,
topY: 2,
Expand All @@ -128,7 +133,8 @@ describe("loadResultsToCache", () => {
score: 0.3,
classId: "2",
label: "c",
boxId: "2",
box_id: "2",
object_type_id: "2",
box: {
topX: 3,
topY: 3,
Expand Down
12 changes: 7 additions & 5 deletions src/common/types.d.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
export interface ApiInferenceData {
filename: string;
imageId: string;
inferenceId: string;
inference_id: string;
boxes: Array<{
topN: Array<{ score: number; label: string }>;
score: number;
label: string;
classId: string;
boxId: string;
object_type_id: string;
box_id: string;
box: BoxCoordinates;
overlapping: boolean;
overlappingIndices: number;
Expand Down Expand Up @@ -79,16 +80,17 @@ export interface LabelOccurrences {
[label: string]: number;
}

// TODO: Redefine when the backend is updated
interface ClassData {
id: number;
classId: string;
label: string;
}

interface ApiSpeciesData {
classId: string;
label: string;
seeds: Array<{
seed_id: string;
seed_name: string;
}>;
}

export interface ModelMetadata {
Expand Down
7 changes: 6 additions & 1 deletion src/components/body/authentication/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import {
} from "@mui/material";
import CloseIcon from "@mui/icons-material/Close";
import { colours } from "../../../styles/colours";
import Cookies from "js-cookie";

interface params {
setSignUpOpen: React.Dispatch<React.SetStateAction<boolean>>;
onSignIn: () => void;
}

const SignUp: React.FC<params> = (props): JSX.Element => {
Expand All @@ -27,8 +29,11 @@ const SignUp: React.FC<params> = (props): JSX.Element => {
const data = new FormData(event.currentTarget);
console.log({
email: data.get("email"),
password: data.get("password"),
// password: data.get("password"),
});
Cookies.set("user-email", String(data.get("email") ?? ""), { expires: 30 });
props.onSignIn();
handleClose();
};

return (
Expand Down
Loading
Loading