Skip to content

Commit bc0dae0

Browse files
committed
feat: Model page almost completed; Working on querying from XGBoost
1 parent 2d740c9 commit bc0dae0

6 files changed

Lines changed: 124 additions & 16 deletions

File tree

client/wildfire-ui/src/hooks/use-auth.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,3 @@ export const useGoogleAuth = () => {
151151
}
152152
})
153153
}
154-
155-
// isUpdating, isLoggingOut, isSigningUp, isLoggingIn
156-
// isModelPredicting, isRetrieving
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {useMutation} from "@tanstack/react-query"
2+
import {toast} from "sonner";
3+
import { API } from "../ui/lib/api";
4+
import type { ModelInfo } from "../types/model/model-types";
5+
6+
7+
8+
9+
export const useCreatePrediction = () => {
10+
return useMutation({
11+
mutationFn: async (coordinateData: ModelInfo) => {
12+
const {data} = await API.post('/v1/intelligence/predict', coordinateData);
13+
return data;
14+
},
15+
onSuccess: () => {
16+
toast.success("Model prediction successful!")
17+
},
18+
onError: (e: any) => {
19+
toast.error(`API ERROR: ${e.detail.message}`)
20+
}
21+
})
22+
}
23+
24+
export const useDeletePredictions = () => {
25+
26+
}
27+
28+
export const useDeletePrediction = (id: string) => {
29+
30+
}

client/wildfire-ui/src/routes/auth/log/signin.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FeatherChrome, FeatherFlame } from "@subframe/core";
1+
import { FeatherFlame } from "@subframe/core";
22
import { Button } from "../../../ui/components/ui/button";
33
import { useForm } from "react-hook-form";
44
import { z } from "zod";

client/wildfire-ui/src/routes/constants/sidebar.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ import { FeatherTriangleAlert } from "@subframe/core";
1111
import { FeatherZap } from "@subframe/core";
1212
import { IconWithBackground } from "../../ui";
1313
import { useGetUser } from "../../hooks/use-auth";
14+
import { Link } from "react-router-dom";
1415

1516

1617

1718
const SideBar = () => {
1819
const {data:user} = useGetUser();
1920

2021
return (
21-
<div className="flex flex-col justify-between pl-6 pr-4 border-r-2 border-b-2 w-[15%] h-screen pt-8 pb-8 bg-white select-none">
22+
<div className="flex flex-col justify-between pl-6 pr-4 border-gray-100 border-r-2 border-b-2 w-[15%] h-screen pt-8 pb-8 bg-white select-none">
2223

2324
{/* Top Half Stack */}
2425
<div className="flex flex-col gap-y-8 relative bottom-24">
2526

2627
{/* Header Branding Row */}
2728
<div className="flex items-center gap-x-3 ">
28-
<IconWithBackground className = "" variant="error" size="large" icon={<FeatherFlame />} />
29+
<Link className = "hover:cursor-pointer" to = "/" ><IconWithBackground variant="error" size="large" icon={<FeatherFlame />} /></Link>
2930
<div className="flex flex-col shrink-0">
3031
<span className="text-md font-bold text-black tracking-tight">Pyro Intelligence</span>
3132
<span className="text-sm text-[#a79f9f] font-medium">Wildfire Engine</span>

client/wildfire-ui/src/routes/data/intelligence.tsx

Lines changed: 84 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,106 @@ import { Button } from "../../ui/components/ui/button"
44
import SideBar from "../constants/sidebar"
55
import { useNavigate } from "react-router"
66
import { useGetUser } from "../../hooks/use-auth"
7+
import { z } from "zod"
8+
import { zodResolver } from "@hookform/resolvers/zod"
9+
import { useForm } from "react-hook-form"
10+
import { Field, FieldDescription, FieldLabel, FieldGroup } from "../../ui/components/ui/field"
11+
import { Input } from "../../ui/components/ui/input"
12+
import { useCreatePrediction } from "../../hooks/use-model"
713
const Intelligence = () => {
8-
914
const navigate = useNavigate();
10-
const {data:user} = useGetUser();
15+
const { data: user } = useGetUser();
16+
const {data: model} = useCreatePrediction();
1117
if (!user) {
12-
return (
13-
navigate("/")
14-
)
18+
return (
19+
navigate("/")
20+
)
21+
}
22+
const coordinateValidation = z.object({
23+
westLon: z.number().min(-180, "Cannot exceed -180 degrees").max(180, "Cannot exceed 180 degrees"),
24+
southLat: z.number().min(-90, "Cannot exceed -90 degrees").max(90, "Cannot exceed 90 degrees"),
25+
eastLon: z.number().min(-90, "Cannot exceed -180 degrees").max(90, "Cannot exceed 180 degrees"),
26+
northLat: z.number().min(-90, "Cannot exceed -90 degrees").max(90, "Cannot exceed 90 degrees"),
27+
})
28+
29+
type coordinateQuery = z.infer<typeof coordinateValidation>;
30+
31+
const {register, handleSubmit, formState: { errors }, } = useForm<coordinateQuery>({
32+
resolver: zodResolver(coordinateValidation),
33+
defaultValues: {
34+
westLon: 0,
35+
southLat: 0,
36+
eastLon: 0,
37+
northLat: 0,
38+
},
39+
});
40+
41+
const onSubmit = (data: coordinateQuery) => {
42+
model(data, {
43+
onSuccess: () => {
44+
navigate("/field/reports")
45+
}
46+
})
1547
}
48+
49+
const capitalizeLetter = user.role.charAt(0).toUpperCase() + user.role.slice(1);
1650
return (
1751
<div className="bg-white h-full w-screen overflow-hidden"> {/* Main Box */}
1852
{/* Top Bar */}
19-
<div className="flex flex-row justify-between border-2 border-black w-[86%] p-4 relative left-[14.9%] place-items-center">
53+
<div className="flex flex-row justify-between border-2 border-gray-100 w-[86%] p-4 relative left-[14.9%] place-items-center">
2054
<div className="flex flex-col justify-center pl-4">
21-
<h1 className = "text-shadow-black font-bold text-xl">Wildfire Risk Intelligence</h1>
22-
<span className = "text-sm">NASA FIRMS Ingestion • XGBoost Inference</span>
55+
<h1 className="text-shadow-black font-bold text-xl">Wildfire Risk Intelligence</h1>
56+
<span className="text-sm">NASA FIRMS Ingestion • XGBoost Inference</span>
2357
</div>
2458
<div className="grow shrink-0 relative left-[63%]">
25-
<Button className="p-1 bg-[#DAFBE6] text-[#639273] w-[9%] h-[15%]"><FeatherShieldCheck/>{user.role}</Button>
59+
<Button className="p-1 bg-[#DAFBE6] text-[#639273] w-[9%] h-[15%]"><FeatherShieldCheck />{capitalizeLetter}</Button>
2660
</div>
2761
</div>
2862
<SideBar />
2963

3064
{/* Coordinate Box */}
31-
<div>
65+
<div className="p-15 border-2 border-gray-100 border-b-2">
66+
<h1 className="font-bold text-md">Geospatial Bounding Box</h1>
67+
<span className="text-[#a79f9f] text-sm">Define the target region for inference</span>
68+
<form onSubmit={handleSubmit(onSubmit)}>
69+
<FieldGroup>
70+
<Field>
71+
<FieldLabel htmlFor="westLon">
72+
West Longitude
73+
</FieldLabel>
74+
<Input id = "westLon" placeholder = "-122.6750" required{...register("westLon")}/>
75+
{errors.westLon && (
76+
<span className = "text-red-500 text-xs">{errors.westLon.message}</span>
77+
)}
78+
</Field>
79+
<FieldDescription>Decimal degrees (-180 to 180)</FieldDescription>
80+
81+
<Field>
82+
<FieldLabel htmlFor = "southLat">South Latitude</FieldLabel>
83+
<Input id = "southLat" placeholder = "37.4500" required {...register("southLat")}/>
84+
{errors.southLat && (
85+
<span className = "text-xs text-red-500">{errors.southLat.message}</span>
86+
)}
87+
</Field>
88+
<FieldDescription>Decimal degrees (-90 to 90)</FieldDescription>
89+
90+
<Field>
91+
<FieldLabel>East Longitude</FieldLabel>
92+
<Input id = "eastLon" placeholder = "-122.1500" required {...register("eastLon")}/>
93+
{errors.eastLon && (
94+
<span className = "text-xs text-red-500">{errors.eastLon.message}</span>
95+
)}
96+
</Field>
97+
<FieldDescription>Decimal degrees (-180 to 180)</FieldDescription>
98+
99+
<Field>
100+
<FieldLabel>North Latitude</FieldLabel>
101+
<Input id = "northLat" placeholder = "37.8750" required {...register("northLat")}/>
102+
</Field>
103+
<FieldDescription>Decimal degrees (-90 to 90)</FieldDescription>
32104

105+
</FieldGroup>
106+
</form>
33107
</div>
34108

35109
{/* Hotspot Box */}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type ModelInfo = {
2+
westLon: number;
3+
southLat: number;
4+
eastLon: number;
5+
northLat: number;
6+
}

0 commit comments

Comments
 (0)