-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Setup Django Project and setup api app and a testing router #17
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
Changes from all commits
4753ee4
84f3c35
558e13e
e16f2df
0598536
a5c32d8
3385dee
e8e953e
0e1e982
e430043
b870060
0faee97
b35e17f
4650c18
b01b129
4ab28ec
ecbae17
a8da103
02db6ae
24f4a94
43a6501
da61bb5
8d69776
88bb043
fd1079a
7034411
a31c58e
bb73943
d8803c7
3d3ad64
79f1878
41881ef
4091e1c
c111433
38c2d82
c7c87f9
a2c09e2
0f32fd3
40a8199
1056d1c
f4f2d38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,8 @@ const RouteContent = () => { | |
| const [selectedRouteIndex, setSelectedRouteIndex] = useState(0); | ||
| const [routeName, setRouteName] = useState(""); | ||
| const [showSaveModal, setShowSaveModal] = useState(false); | ||
| const [searchId, setSearchId] = useState<string | null>(null); | ||
| const fetchGenerationRef = useRef(0); | ||
| const saveInputRef = useRef<HTMLInputElement>(null); | ||
|
|
||
| // Parse query parameters | ||
|
|
@@ -135,7 +137,11 @@ const RouteContent = () => { | |
| }; | ||
|
|
||
| // Fetch scores from backend scoring API | ||
| const fetchScores = async (routeData: RouteData[], mode: TravelMode) => { | ||
| const fetchScores = async ( | ||
| routeData: RouteData[], | ||
| mode: TravelMode, | ||
| generation: number | ||
| ) => { | ||
| setScoresLoading(true); | ||
| try { | ||
| const payload = { | ||
|
|
@@ -170,6 +176,16 @@ const RouteContent = () => { | |
| } | ||
|
|
||
| const data = await response.json(); | ||
|
|
||
| // If a newer fetchRoutes was triggered while we were waiting, | ||
| // discard this stale response entirely. | ||
| if (generation !== fetchGenerationRef.current) return; | ||
|
Comment on lines
+180
to
+182
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When two score fetches are in flight (gen 1 then gen 2), gen 1's stale response returns first, hits the early 🛡️ Proposed fix- if (generation !== fetchGenerationRef.current) return;
+ if (generation !== fetchGenerationRef.current) {
+ setScoresLoading(false);
+ return;
+ }Then guard the finally: } catch (err) {
console.error("Error fetching scores:", err);
} finally {
- setScoresLoading(false);
+ if (generation === fetchGenerationRef.current) {
+ setScoresLoading(false);
+ }
}Also applies to: 246-250 🤖 Prompt for AI Agents |
||
|
|
||
| // Capture the searchId for later use in saving | ||
| if (data.searchId) { | ||
| setSearchId(data.searchId); | ||
| } | ||
|
|
||
| const scoredRoutes = data.data?.routes; | ||
| if (scoredRoutes && Array.isArray(scoredRoutes)) { | ||
| const scores = scoredRoutes.map( | ||
|
|
@@ -194,7 +210,7 @@ const RouteContent = () => { | |
| let bestDuration = Infinity; | ||
| overallScores.forEach((score: number, i: number) => { | ||
| const dur = | ||
| routes[i]?.trafficDuration ?? routes[i]?.duration ?? Infinity; | ||
| routeData[i]?.trafficDuration ?? routeData[i]?.duration ?? Infinity; | ||
| if ( | ||
| score > overallScores[bestIndex] || | ||
| (score === overallScores[bestIndex] && dur < bestDuration) | ||
|
|
@@ -244,6 +260,9 @@ const RouteContent = () => { | |
| return; | ||
| } | ||
|
|
||
| // Increment generation so any in-flight fetchScores response is ignored | ||
| const generation = ++fetchGenerationRef.current; | ||
| setSearchId(null); | ||
| setIsLoading(true); | ||
| setError(null); | ||
|
|
||
|
|
@@ -339,7 +358,7 @@ const RouteContent = () => { | |
| }; | ||
| }); | ||
| setRoutes(fetchedRoutes); | ||
| fetchScores(fetchedRoutes, mode); | ||
| fetchScores(fetchedRoutes, mode, generation); | ||
| } else { | ||
| setError("No routes found. Please try different locations."); | ||
| setRoutes([]); | ||
|
|
@@ -393,6 +412,7 @@ const RouteContent = () => { | |
| try { | ||
| const payload = { | ||
| name: nameToSave, | ||
| searchId, // Include the searchId from the computation | ||
| from: { | ||
| address: sourceAddress, | ||
| location: { | ||
|
|
@@ -411,8 +431,7 @@ const RouteContent = () => { | |
| distance: route.distance / 1000, | ||
| duration: route.duration / 60, | ||
| routeGeometry: route.geometry, | ||
| lastComputedScore: | ||
| route.overallScore || Math.floor(Math.random() * 100), | ||
| lastComputedScore: route.overallScore ?? null, | ||
| lastComputedAt: new Date(), | ||
| travelMode: selectedMode, | ||
| })), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| """ | ||
| Pathway pipeline module for BreathClean. | ||
| """ | ||
| from .pipeline import run_batch_pipeline, run_simple_batch | ||
| from .transformers import compute_route_score, compute_batch_scores | ||
|
|
||
| __all__ = [ | ||
| "run_batch_pipeline", | ||
| "run_simple_batch", | ||
| "compute_route_score", | ||
| "compute_batch_scores" | ||
| ] |
Uh oh!
There was an error while loading. Please reload this page.