Skip to content

Commit 26b2b71

Browse files
shollingsworthfeydandependabot[bot]Zesky665
authored
Merging in changes for #179 (#180)
* Adding a link to Running-man-01/trashai_nbs project * Bump vm2 from 3.9.17 to 3.9.19 in /infra (#162) Bumps [vm2](https://github.com/patriksimek/vm2) from 3.9.17 to 3.9.19. - [Release notes](https://github.com/patriksimek/vm2/releases) - [Changelog](https://github.com/patriksimek/vm2/blob/master/CHANGELOG.md) - [Commits](patriksimek/vm2@3.9.17...3.9.19) --- updated-dependencies: - dependency-name: vm2 dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump vite from 3.2.5 to 3.2.7 in /infra (#165) Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 3.2.5 to 3.2.7. - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/v3.2.7/packages/vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/v3.2.7/packages/vite) --- updated-dependencies: - dependency-name: vite dependency-type: direct:development ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump vite from 3.0.4 to 3.2.7 in /frontend (#164) Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 3.0.4 to 3.2.7. - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/v3.2.7/packages/vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/v3.2.7/packages/vite) --- updated-dependencies: - dependency-name: vite dependency-type: direct:development ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fixing build and fixing local (#170) * Add testing instructions and auto tests (#171) * Adding a link to Running-man-01/trashai_nbs project (#168) * update frontend app doc * Add manual instructions. * Added test-ids * Add test-ids to the navigation tabs * Add smoke test draft * Add placeholder file * Add photos for manual testing instructions * Upgrade node version * Remove cypress * Add test ids to summary page * Jest + Puppeteer setup * Add smoke test * Added back manual instructions * Add images for manual instructions * Add instruction for running auto tests --------- Co-authored-by: Dan Fey <[email protected]> * Adding schema files to download (#173) * adding schema files to the zip download * revert yarn change * fixing list * indentation * 124 summary csv files (#175) * aAdding summary csv reports * adding comments * fixing off by 1 error in summary counts (#177) * Consistent csv delimiter (#179) * Only using comma delimited for summary csv files and automatically quoting all string fields in the csv * Simplifying generateSummaryFiles and removing array mutation * fixing unit test * only run typescript tests with test-ts * Updated babel and dev package to run tests --------- Co-authored-by: Steven Hollingsworth <[email protected]> * Fixed broken yarn.lock --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Dan Fey <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Zesky665 <[email protected]>
1 parent 9b77297 commit 26b2b71

File tree

7 files changed

+85
-54
lines changed

7 files changed

+85
-54
lines changed

frontend/babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
presets: ['@vue/cli-plugin-babel/preset'],
2+
presets: ['@vue/cli-plugin-babel/preset', '@babel/preset-typescript'],
33
}

frontend/jest.config.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @type {import('ts-jest').JestConfigWithTsJest} */
22
module.exports = {
3-
preset: 'ts-jest',
4-
testEnvironment: 'node',
5-
};
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
testMatch: ['**/*.spec.ts'],
6+
}

frontend/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"webfontloader": "^1.6.28"
4545
},
4646
"devDependencies": {
47+
"@babel/preset-typescript": "^7.22.5",
4748
"@types/crypto-js": "^4.1.1",
4849
"@types/file-saver": "^2.0.5",
4950
"@types/google.maps": "^3.49.2",

frontend/src/lib/csv/csv.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ import {
55
} from './schema-parser'
66
import { MapJsonProperties } from './types'
77

8+
type Column = string | number | boolean
9+
10+
const quote = (s: string) => `"${s}"`
11+
const constructDelimetedRow = (delimeter: string) => (row: Column[]) =>
12+
row.map((c) => (typeof c === 'string' ? quote(c) : c)).join(delimeter)
13+
const addNewlines = (s: Column[]) => s.join('\n')
14+
815
export const objectToCsv =
916
<T>(
1017
headers: string[],
11-
fnFlatten: (obj: T) => (string | number | boolean)[][],
12-
joinStr: string = ',',
18+
fnFlatten: (obj: T) => Column[][],
19+
delimeter: string = ',',
1320
) =>
1421
(obj: T) => {
1522
const csvData = fnFlatten(obj)
@@ -21,7 +28,11 @@ export const objectToCsv =
2128
)}, see incorrect rows: ${JSON.stringify(errorRows)}`,
2229
)
2330
}
24-
return [headers, ...csvData].map((row) => row.join(joinStr)).join('\n')
31+
const rowsWithHeaders = [headers, ...csvData]
32+
const delimetedRows = rowsWithHeaders.map(
33+
constructDelimetedRow(delimeter),
34+
)
35+
return addNewlines(delimetedRows)
2536
}
2637

2738
/**

frontend/src/lib/csv/schema-parser.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ describe('csv', () => {
7373
]),
7474
)(obj)
7575
expect(csv).toEqual(
76-
'id,fruit,cultivar,inSeason\n' +
77-
'1,apple,gala,false\n' +
78-
'1,apple,red delicious,true\n' +
79-
'1,pear,bosc,false\n' +
80-
'1,pear,bartlett,true',
76+
'"id","fruit","cultivar","inSeason"\n' +
77+
'1,"apple","gala",false\n' +
78+
'1,"apple","red delicious",true\n' +
79+
'1,"pear","bosc",false\n' +
80+
'1,"pear","bartlett",true',
8181
)
8282
})
8383

frontend/src/lib/store/images.ts

+38-41
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export const useImageStore = defineStore<
312312
const zname = `${bname}.zip`
313313
const folder = zip.folder(bname)
314314

315-
generateSummaryFiles(this.summary).map(([fileName, data]) =>
315+
generateSummaryFiles(this.summary).map(({fileName, data}) =>
316316
folder!.file(fileName, data),
317317
)
318318

@@ -371,47 +371,44 @@ export const useImageStore = defineStore<
371371
},
372372
})
373373

374-
const generateSummaryFiles = (summary: Summary) => {
375-
const files: [string, string][] = []
376-
// summary json
377-
files.push(['summary.json', JSON.stringify(summary)])
374+
// summary totals csv
375+
const sTotalsHeaders = ['total_detections', 'unique_detections']
376+
const summaryTotalsToCsv = objectToCsv(sTotalsHeaders, (o: Summary) => [
377+
[o.total_detections, o.unique_detections],
378+
])
378379

379-
// summary totals csv
380-
const sTotalsHeaders = ['total_detections', 'unique_detections']
381-
const summaryTotalsCsv = objectToCsv(sTotalsHeaders, (o: Summary) => [
382-
[o.total_detections, o.unique_detections],
383-
])(summary)
384-
files.push(['summary_totals.csv', summaryTotalsCsv])
380+
// summary detected objects csv
381+
const detectedHeaders = getCsvHeadersFromJsonSchema(
382+
summarySchema.properties.detected_objects as JSONSchema7,
383+
)
384+
const detectedToCsv = objectToCsv(detectedHeaders, (obj: Summary) =>
385+
obj.detected_objects.map((v) => [v.name, v.count, v.hashes.join(',')]),
386+
)
385387

386-
// summary detected objects csv
387-
const detectedHeaders = getCsvHeadersFromJsonSchema(
388-
summarySchema.properties.detected_objects as JSONSchema7,
389-
)
390-
const detectedCsv = objectToCsv(
391-
detectedHeaders,
392-
(obj: Summary) =>
393-
obj.detected_objects.map((v) => [
394-
v.name,
395-
v.count,
396-
v.hashes.join(','),
397-
]),
398-
';',
399-
)(summary)
400-
files.push(['summary_detected.csv', detectedCsv])
388+
// summary gps objects csv
389+
const gpsHeaders = getCsvHeadersFromJsonSchema(
390+
summarySchema.properties.gps.properties.list.items as JSONSchema7,
391+
)
392+
const gpsToCsv = objectToCsv(gpsHeaders, (obj: Summary) =>
393+
obj.gps.list.map((v) => [
394+
v?.coordinate?.lat ?? '',
395+
v?.coordinate?.lng ?? '',
396+
v.hash,
397+
]),
398+
)
401399

402-
// summary gps objects csv
403-
if (summary.gps.list.length > 0) {
404-
const gpsHeaders = getCsvHeadersFromJsonSchema(
405-
summarySchema.properties.gps.properties.list.items as JSONSchema7,
406-
)
407-
const gpsCsv = objectToCsv(gpsHeaders, (obj: Summary) =>
408-
obj.gps.list.map((v) => [
409-
v?.coordinate?.lat ?? '',
410-
v?.coordinate?.lng ?? '',
411-
v.hash,
412-
]),
413-
)(summary)
414-
files.push(['summary_gps.csv', gpsCsv])
415-
}
416-
return files
400+
const generateSummaryFiles = (summary: Summary) => {
401+
const filesToGenerate = [
402+
{ fileName: 'summary.json', dataFn: JSON.stringify },
403+
{ fileName: 'summary_totals.csv', dataFn: summaryTotalsToCsv },
404+
{ fileName: 'summary_detected.csv', dataFn: detectedToCsv },
405+
...(summary.gps.list.length > 0
406+
? [{ fileName: 'summary_gps.csv', dataFn: gpsToCsv }]
407+
: []),
408+
]
409+
410+
return filesToGenerate.map(({ fileName, dataFn }) => ({
411+
fileName,
412+
data: dataFn(summary),
413+
}))
417414
}

frontend/yarn.lock

+22-1
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@
566566
dependencies:
567567
"@babel/helper-plugin-utils" "^7.14.5"
568568

569-
"@babel/plugin-syntax-typescript@^7.7.2":
569+
"@babel/plugin-syntax-typescript@^7.22.5", "@babel/plugin-syntax-typescript@^7.7.2":
570570
version "7.22.5"
571571
resolved "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.22.5.tgz"
572572
integrity sha512-1mS2o03i7t1c6VzH6fdQ3OA8tcEIxwG18zIPRp+UY1Ihv6W+XZzBCVxExF9upussPXJ0xE9XRHwMoNs1ep/nRQ==
@@ -950,6 +950,16 @@
950950
dependencies:
951951
"@babel/helper-plugin-utils" "^7.22.5"
952952

953+
"@babel/plugin-transform-typescript@^7.22.5":
954+
version "7.22.5"
955+
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.22.5.tgz#5c0f7adfc1b5f38c4dbc8f79b1f0f8074134bd7d"
956+
integrity sha512-SMubA9S7Cb5sGSFFUlqxyClTA9zWJ8qGQrppNUm05LtFuN1ELRFNndkix4zUJrC9F+YivWwa1dHMSyo0e0N9dA==
957+
dependencies:
958+
"@babel/helper-annotate-as-pure" "^7.22.5"
959+
"@babel/helper-create-class-features-plugin" "^7.22.5"
960+
"@babel/helper-plugin-utils" "^7.22.5"
961+
"@babel/plugin-syntax-typescript" "^7.22.5"
962+
953963
"@babel/plugin-transform-unicode-escapes@^7.22.5":
954964
version "7.22.5"
955965
resolved "https://registry.npmjs.org/@babel/plugin-transform-unicode-escapes/-/plugin-transform-unicode-escapes-7.22.5.tgz"
@@ -1078,6 +1088,17 @@
10781088
"@babel/types" "^7.4.4"
10791089
esutils "^2.0.2"
10801090

1091+
"@babel/preset-typescript@^7.22.5":
1092+
version "7.22.5"
1093+
resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.22.5.tgz#16367d8b01d640e9a507577ed4ee54e0101e51c8"
1094+
integrity sha512-YbPaal9LxztSGhmndR46FmAbkJ/1fAsw293tSU+I5E5h+cnJ3d4GTwyUgGYmOXJYdGA+uNePle4qbaRzj2NISQ==
1095+
dependencies:
1096+
"@babel/helper-plugin-utils" "^7.22.5"
1097+
"@babel/helper-validator-option" "^7.22.5"
1098+
"@babel/plugin-syntax-jsx" "^7.22.5"
1099+
"@babel/plugin-transform-modules-commonjs" "^7.22.5"
1100+
"@babel/plugin-transform-typescript" "^7.22.5"
1101+
10811102
"@babel/regjsgen@^0.8.0":
10821103
version "0.8.0"
10831104
resolved "https://registry.npmjs.org/@babel/regjsgen/-/regjsgen-0.8.0.tgz"

0 commit comments

Comments
 (0)