-
Notifications
You must be signed in to change notification settings - Fork 0
fix: make calculator, publish, profile and Excel import work #113
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
Open
paccloud
wants to merge
4
commits into
main
Choose a base branch
from
fix/calculator-p0-bugs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
22dbe21
fix: make calculator, publish, profile and Excel import work
claude a5d3c6f
fix: close publish preview when auth token refresh fails
claude bc57547
Merge main into fix/calculator-p0-bugs
claude bdc9401
fix: scale only percent-formatted XLSX yield cells
claude 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
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
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
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,63 @@ | ||
| // Normalizes fish yield data into the shape the Calculator reads: | ||
| // conversions[key] = { from, to, yield: number, range: [min, max] | null }. | ||
| // | ||
| // The bundled FISH_DATA_V3 keys conversions as "From → To" and omits the | ||
| // from/to fields; the Neon-backed /api/fish-data response includes them. | ||
| // Normalizing both lets the calculator work offline and when the API fails. | ||
|
|
||
| const ARROW = ' → '; | ||
|
|
||
| function toNumber(value) { | ||
| const n = typeof value === 'number' ? value : Number.parseFloat(value); | ||
| return Number.isFinite(n) ? n : null; | ||
| } | ||
|
|
||
| function toRange(range) { | ||
| if (Array.isArray(range) && range.length === 2) { | ||
| const min = toNumber(range[0]); | ||
| const max = toNumber(range[1]); | ||
| return min !== null && max !== null ? [min, max] : null; | ||
| } | ||
| if (typeof range === 'string') { | ||
| const [min, max] = range.split('-').map(toNumber); | ||
| return min != null && max != null ? [min, max] : null; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| export function normalizeConversion(key, conv) { | ||
| let { from, to } = conv; | ||
| if ((!from || !to) && key.includes(ARROW)) { | ||
| const [keyFrom, ...rest] = key.split(ARROW); | ||
| from = from || keyFrom.trim(); | ||
| to = to || rest.join(ARROW).trim(); | ||
| } | ||
| return { ...conv, from, to, yield: toNumber(conv.yield), range: toRange(conv.range) }; | ||
| } | ||
|
|
||
| export function withConversionStates(fishData) { | ||
| const out = {}; | ||
| for (const [species, data] of Object.entries(fishData || {})) { | ||
| const conversions = {}; | ||
| for (const [key, conv] of Object.entries(data?.conversions || {})) { | ||
| conversions[key] = normalizeConversion(key, conv || {}); | ||
| } | ||
| out[species] = { ...data, conversions }; | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| // True when at least one conversion has a usable from/to pair and yield. | ||
| export function hasUsableConversions(fishData) { | ||
| return Object.values(fishData || {}).some((data) => | ||
| Object.values(data?.conversions || {}).some( | ||
| (conv) => conv.from && conv.to && conv.yield !== null && conv.yield > 0 | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| // A yield percentage is usable when it is a finite number in (0, 100]. | ||
| export function parseYieldPercent(value) { | ||
| const n = toNumber(value); | ||
| return n !== null && n > 0 && n <= 100 ? n : null; | ||
| } |
Oops, something went wrong.
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.