-
Notifications
You must be signed in to change notification settings - Fork 4
Add streaming bulk soil analysis uploads with batching #459
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
53197a0
fix: support uploading for more than 10 pdfs
SvenVw 2d1c8bd
feat: add progress bar during upload of multiple pdf's
SvenVw 9108a13
refactor: use seperate api route to enable parallel requests and prog…
SvenVw cd83ebb
fix: automatic coupling of pdf's with fields
SvenVw 9b5cd8a
feat: improvements for nmin analysis
SvenVw 34c9408
nitpicks
SvenVw e14567b
fix: rerendering after submission
SvenVw e5386dc
fix: handle end of stream
SvenVw 3058ae5
fix: double error message
SvenVw e4c5050
fix: handle invalid date
SvenVw a21728c
fix: hook rule violation
SvenVw 0c37796
fix: type
SvenVw c919661
refactor: improve validation
SvenVw 0dfe71b
refactor: improve coordinate validation
SvenVw 6611ef0
fix: use lowercase
SvenVw e154ce2
refactor: remove not used code
SvenVw 6325c68
refactor: use same logic for dropping and selecting
SvenVw e155677
refactor: process batches after each other to prevent overwhelming th…
SvenVw f567a1e
refactor: moving matching into shared function
SvenVw 860c5da
fix: imports
SvenVw dc8e57d
fix: improve error message
SvenVw 9cf0d26
refactor: strip raw data
SvenVw 71fb625
fix: use already defined type
SvenVw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { booleanPointInPolygon } from "@turf/turf" | ||
| import type { ProcessedAnalysis } from "./bulk-upload-review" | ||
|
|
||
| type Field = { | ||
| b_id: string | ||
| b_name: string | ||
| geometry: any | ||
| } | ||
|
|
||
| /** | ||
| * Matches extracted soil analyses to existing farm fields using geometry and name. | ||
| */ | ||
| export function matchAnalysesToFields( | ||
| analyses: any[], | ||
| fields: Field[], | ||
| ): ProcessedAnalysis[] { | ||
| return analyses.map((analysis) => { | ||
| let matchedFieldId = "" | ||
| let matchReason: "geometry" | "name" | "both" | undefined | ||
|
|
||
| // Geometry matching | ||
| if (analysis.location && analysis.location.coordinates) { | ||
| const [lon, lat] = analysis.location.coordinates | ||
| if (typeof lon === "number" && typeof lat === "number") { | ||
| const fieldMatch = fields.find((field) => { | ||
| if (!field.geometry) return false | ||
| try { | ||
| // booleanPointInPolygon handles both Polygon and MultiPolygon | ||
| return booleanPointInPolygon( | ||
| analysis.location, | ||
| field.geometry as any, | ||
| ) | ||
| } catch (e) { | ||
| console.warn(`Matching failed for field ${field.b_name}:`, e) | ||
| return false | ||
| } | ||
| }) | ||
| if (fieldMatch) { | ||
| matchedFieldId = fieldMatch.b_id | ||
| matchReason = "geometry" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Fallback: Name matching (b_fieldname vs field name) | ||
| const analysisName = (analysis.b_name || "") | ||
| .toLowerCase() | ||
| .trim() | ||
|
|
||
| if (analysisName) { | ||
| const fieldMatch = fields.find( | ||
| (field) => | ||
| field.b_name.toLowerCase().trim() === analysisName, | ||
| ) | ||
|
Collaborator
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. so, its only a check if full name is exactly identical?
Collaborator
Author
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. Yes, but ignoring capitals |
||
|
|
||
| if (fieldMatch) { | ||
| if (matchedFieldId) { | ||
| // Check if it's the same field | ||
| if (matchedFieldId === fieldMatch.b_id) { | ||
| matchReason = "both" | ||
| } | ||
| } else { | ||
| matchedFieldId = fieldMatch.b_id | ||
| matchReason = "name" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| ...analysis, | ||
| matchedFieldId, | ||
| matchReason, | ||
| } | ||
| }) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.