generated from include-davis/Next.js-App-Router-Starter
-
Notifications
You must be signed in to change notification settings - Fork 2
CSV ingestion fixes #354
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
ReehalS
wants to merge
2
commits into
main
Choose a base branch
from
349-csv-ingestion-fixes
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.
+1,087
−108
Open
CSV ingestion fixes #354
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # **.mjs | ||
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,48 @@ | ||
| import { | ||
| matchCanonicalTrack, | ||
| sortTracks, | ||
| } from '@utils/csv-ingestion/csvAlgorithm'; | ||
|
|
||
| describe('csvAlgorithm track matching', () => { | ||
| it('matches tracks case-insensitively to canonical names', () => { | ||
| expect(matchCanonicalTrack('best hardware hack')).toBe( | ||
| 'Best Hardware Hack' | ||
| ); | ||
| expect(matchCanonicalTrack('Best hardware hack')).toBe( | ||
| 'Best Hardware Hack' | ||
| ); | ||
| }); | ||
|
|
||
| it('does not attempt to correct spelling', () => { | ||
| expect(matchCanonicalTrack('Best Hardwre Hack')).toBeNull(); | ||
| expect(matchCanonicalTrack('Best Assistive Technlogy')).toBeNull(); | ||
| }); | ||
|
|
||
| it('ingests all opt-in tracks and does not cap length', () => { | ||
| const tracks = sortTracks( | ||
| 'best hardware hack', | ||
| '', | ||
| '', | ||
| 'Best Use of Gemini API; Best Use of MongoDB Atlas, Best Use of Vectara | Best Use of Auth0' | ||
| ); | ||
|
|
||
| expect(tracks).toEqual([ | ||
| 'Best Hardware Hack', | ||
| 'Best Use of Gemini API', | ||
| 'Best Use of MongoDB Atlas', | ||
| 'Best Use of Vectara', | ||
| 'Best Use of Auth0', | ||
| ]); | ||
| }); | ||
|
|
||
| it('filters out excluded tracks', () => { | ||
| const tracks = sortTracks( | ||
| 'Best Hack for Social Good', | ||
| "Hacker's Choice Award", | ||
| '', | ||
| 'Best Hack for Social Good, Best Hardware Hack' | ||
| ); | ||
|
|
||
| expect(tracks).toEqual(['Best Hardware Hack']); | ||
| }); | ||
| }); |
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,32 @@ | ||
| import { validateCsvBlob } from '@utils/csv-ingestion/csvAlgorithm'; | ||
|
|
||
| describe('csvAlgorithm validation', () => { | ||
| it("silently ignores 'N/A' without warnings", async () => { | ||
| const csv = | ||
| 'Table Number,Project Status,Project Title,Track #1 (Primary Track),Track #2,Track #3,Opt-In Prizes\n' + | ||
| '12,Submitted (Gallery/Visible),Test Project,Best Beginner Hack,N/A,,\n'; | ||
|
|
||
| const blob = new Blob([csv], { type: 'text/csv' }); | ||
| const res = await validateCsvBlob(blob); | ||
|
|
||
| expect(res.ok).toBe(true); | ||
| expect(res.report.errorRows).toBe(0); | ||
| expect(res.report.warningRows).toBe(0); | ||
| expect(res.report.issues).toEqual([]); | ||
| }); | ||
|
|
||
| it('treats duplicate tracks as warnings (non-blocking)', async () => { | ||
| const csv = | ||
| 'Table Number,Project Status,Project Title,Track #1 (Primary Track),Track #2,Track #3,Opt-In Prizes\n' + | ||
| '87,Submitted (Gallery/Visible),PartyPal,Best UI/UX Design,Best UI/UX Design,,\n'; | ||
|
|
||
| const blob = new Blob([csv], { type: 'text/csv' }); | ||
| const res = await validateCsvBlob(blob); | ||
|
|
||
| expect(res.ok).toBe(true); | ||
| expect(res.report.errorRows).toBe(0); | ||
| expect(res.report.warningRows).toBe(1); | ||
| expect(res.report.issues[0].severity).toBe('warning'); | ||
| expect(res.report.issues[0].duplicateTracks).toEqual(['Best UI/UX Design']); | ||
| }); | ||
| }); |
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,14 @@ | ||
| 'use server'; | ||
|
|
||
| import { getDatabase } from '@utils/mongodb/mongoClient.mjs'; | ||
|
|
||
| export default async function checkTeamsPopulated() { | ||
| try { | ||
| const db = await getDatabase(); | ||
| const count = await db.collection('teams').countDocuments({}); | ||
| return { ok: true, populated: count > 0, count, error: null }; | ||
| } catch (e) { | ||
| const error = e as Error; | ||
| return { ok: false, populated: false, count: 0, error: error.message }; | ||
| } | ||
| } |
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,7 @@ | ||||||||||
| 'use server'; | ||||||||||
|
|
||||||||||
| import { CreateManyTeams } from '@datalib/teams/createTeams'; | ||||||||||
|
|
||||||||||
| export default async function ingestTeams(body: object) { | ||||||||||
|
||||||||||
| export default async function ingestTeams(body: object) { | |
| type IngestTeamsBody = Parameters<typeof CreateManyTeams>[0]; | |
| export default async function ingestTeams(body: IngestTeamsBody) { |
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,28 @@ | ||
| 'use server'; | ||
|
|
||
| import { validateCsvBlob } from '@utils/csv-ingestion/csvAlgorithm'; | ||
|
|
||
| export default async function validateCSV(formData: FormData) { | ||
| const file = formData.get('file') as File | null; | ||
| if (!file) { | ||
| return { | ||
| ok: false, | ||
| body: null, | ||
| validBody: null, | ||
| report: null, | ||
| error: 'Missing file', | ||
| }; | ||
| } | ||
|
|
||
| const data = await file.arrayBuffer(); | ||
| const blob = new Blob([data], { type: file.type }); | ||
|
|
||
| const res = await validateCsvBlob(blob); | ||
| return { | ||
| ok: res.ok, | ||
| body: res.body, | ||
| validBody: res.validBody, | ||
| report: res.report, | ||
| error: res.error, | ||
| }; | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment in .prettierignore is ineffective. In .prettierignore files, comments should start on their own line with a hash (#), not inline. The pattern "# **.mjs" will be treated as a literal pattern to ignore files named "# .mjs" rather than as a comment. If you want to ignore .mjs files, remove the "# " prefix to use ".mjs" as the pattern, or if you want a comment, move it to a separate line.