Skip to content

Commit

Permalink
Merging in changes for #179 (#180)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
4 people authored Jul 1, 2023
1 parent 9b77297 commit 26b2b71
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 54 deletions.
2 changes: 1 addition & 1 deletion frontend/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
presets: ['@vue/cli-plugin-babel/preset'],
presets: ['@vue/cli-plugin-babel/preset', '@babel/preset-typescript'],
}
7 changes: 4 additions & 3 deletions frontend/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/*.spec.ts'],
}
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"webfontloader": "^1.6.28"
},
"devDependencies": {
"@babel/preset-typescript": "^7.22.5",
"@types/crypto-js": "^4.1.1",
"@types/file-saver": "^2.0.5",
"@types/google.maps": "^3.49.2",
Expand Down
17 changes: 14 additions & 3 deletions frontend/src/lib/csv/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ import {
} from './schema-parser'
import { MapJsonProperties } from './types'

type Column = string | number | boolean

const quote = (s: string) => `"${s}"`
const constructDelimetedRow = (delimeter: string) => (row: Column[]) =>
row.map((c) => (typeof c === 'string' ? quote(c) : c)).join(delimeter)
const addNewlines = (s: Column[]) => s.join('\n')

export const objectToCsv =
<T>(
headers: string[],
fnFlatten: (obj: T) => (string | number | boolean)[][],
joinStr: string = ',',
fnFlatten: (obj: T) => Column[][],
delimeter: string = ',',
) =>
(obj: T) => {
const csvData = fnFlatten(obj)
Expand All @@ -21,7 +28,11 @@ export const objectToCsv =
)}, see incorrect rows: ${JSON.stringify(errorRows)}`,
)
}
return [headers, ...csvData].map((row) => row.join(joinStr)).join('\n')
const rowsWithHeaders = [headers, ...csvData]
const delimetedRows = rowsWithHeaders.map(
constructDelimetedRow(delimeter),
)
return addNewlines(delimetedRows)
}

/**
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/lib/csv/schema-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ describe('csv', () => {
]),
)(obj)
expect(csv).toEqual(
'id,fruit,cultivar,inSeason\n' +
'1,apple,gala,false\n' +
'1,apple,red delicious,true\n' +
'1,pear,bosc,false\n' +
'1,pear,bartlett,true',
'"id","fruit","cultivar","inSeason"\n' +
'1,"apple","gala",false\n' +
'1,"apple","red delicious",true\n' +
'1,"pear","bosc",false\n' +
'1,"pear","bartlett",true',
)
})

Expand Down
79 changes: 38 additions & 41 deletions frontend/src/lib/store/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export const useImageStore = defineStore<
const zname = `${bname}.zip`
const folder = zip.folder(bname)

generateSummaryFiles(this.summary).map(([fileName, data]) =>
generateSummaryFiles(this.summary).map(({fileName, data}) =>
folder!.file(fileName, data),
)

Expand Down Expand Up @@ -371,47 +371,44 @@ export const useImageStore = defineStore<
},
})

const generateSummaryFiles = (summary: Summary) => {
const files: [string, string][] = []
// summary json
files.push(['summary.json', JSON.stringify(summary)])
// summary totals csv
const sTotalsHeaders = ['total_detections', 'unique_detections']
const summaryTotalsToCsv = objectToCsv(sTotalsHeaders, (o: Summary) => [
[o.total_detections, o.unique_detections],
])

// summary totals csv
const sTotalsHeaders = ['total_detections', 'unique_detections']
const summaryTotalsCsv = objectToCsv(sTotalsHeaders, (o: Summary) => [
[o.total_detections, o.unique_detections],
])(summary)
files.push(['summary_totals.csv', summaryTotalsCsv])
// summary detected objects csv
const detectedHeaders = getCsvHeadersFromJsonSchema(
summarySchema.properties.detected_objects as JSONSchema7,
)
const detectedToCsv = objectToCsv(detectedHeaders, (obj: Summary) =>
obj.detected_objects.map((v) => [v.name, v.count, v.hashes.join(',')]),
)

// summary detected objects csv
const detectedHeaders = getCsvHeadersFromJsonSchema(
summarySchema.properties.detected_objects as JSONSchema7,
)
const detectedCsv = objectToCsv(
detectedHeaders,
(obj: Summary) =>
obj.detected_objects.map((v) => [
v.name,
v.count,
v.hashes.join(','),
]),
';',
)(summary)
files.push(['summary_detected.csv', detectedCsv])
// summary gps objects csv
const gpsHeaders = getCsvHeadersFromJsonSchema(
summarySchema.properties.gps.properties.list.items as JSONSchema7,
)
const gpsToCsv = objectToCsv(gpsHeaders, (obj: Summary) =>
obj.gps.list.map((v) => [
v?.coordinate?.lat ?? '',
v?.coordinate?.lng ?? '',
v.hash,
]),
)

// summary gps objects csv
if (summary.gps.list.length > 0) {
const gpsHeaders = getCsvHeadersFromJsonSchema(
summarySchema.properties.gps.properties.list.items as JSONSchema7,
)
const gpsCsv = objectToCsv(gpsHeaders, (obj: Summary) =>
obj.gps.list.map((v) => [
v?.coordinate?.lat ?? '',
v?.coordinate?.lng ?? '',
v.hash,
]),
)(summary)
files.push(['summary_gps.csv', gpsCsv])
}
return files
const generateSummaryFiles = (summary: Summary) => {
const filesToGenerate = [
{ fileName: 'summary.json', dataFn: JSON.stringify },
{ fileName: 'summary_totals.csv', dataFn: summaryTotalsToCsv },
{ fileName: 'summary_detected.csv', dataFn: detectedToCsv },
...(summary.gps.list.length > 0
? [{ fileName: 'summary_gps.csv', dataFn: gpsToCsv }]
: []),
]

return filesToGenerate.map(({ fileName, dataFn }) => ({
fileName,
data: dataFn(summary),
}))
}
23 changes: 22 additions & 1 deletion frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@
dependencies:
"@babel/helper-plugin-utils" "^7.14.5"

"@babel/plugin-syntax-typescript@^7.7.2":
"@babel/plugin-syntax-typescript@^7.22.5", "@babel/plugin-syntax-typescript@^7.7.2":
version "7.22.5"
resolved "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.22.5.tgz"
integrity sha512-1mS2o03i7t1c6VzH6fdQ3OA8tcEIxwG18zIPRp+UY1Ihv6W+XZzBCVxExF9upussPXJ0xE9XRHwMoNs1ep/nRQ==
Expand Down Expand Up @@ -950,6 +950,16 @@
dependencies:
"@babel/helper-plugin-utils" "^7.22.5"

"@babel/plugin-transform-typescript@^7.22.5":
version "7.22.5"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.22.5.tgz#5c0f7adfc1b5f38c4dbc8f79b1f0f8074134bd7d"
integrity sha512-SMubA9S7Cb5sGSFFUlqxyClTA9zWJ8qGQrppNUm05LtFuN1ELRFNndkix4zUJrC9F+YivWwa1dHMSyo0e0N9dA==
dependencies:
"@babel/helper-annotate-as-pure" "^7.22.5"
"@babel/helper-create-class-features-plugin" "^7.22.5"
"@babel/helper-plugin-utils" "^7.22.5"
"@babel/plugin-syntax-typescript" "^7.22.5"

"@babel/plugin-transform-unicode-escapes@^7.22.5":
version "7.22.5"
resolved "https://registry.npmjs.org/@babel/plugin-transform-unicode-escapes/-/plugin-transform-unicode-escapes-7.22.5.tgz"
Expand Down Expand Up @@ -1078,6 +1088,17 @@
"@babel/types" "^7.4.4"
esutils "^2.0.2"

"@babel/preset-typescript@^7.22.5":
version "7.22.5"
resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.22.5.tgz#16367d8b01d640e9a507577ed4ee54e0101e51c8"
integrity sha512-YbPaal9LxztSGhmndR46FmAbkJ/1fAsw293tSU+I5E5h+cnJ3d4GTwyUgGYmOXJYdGA+uNePle4qbaRzj2NISQ==
dependencies:
"@babel/helper-plugin-utils" "^7.22.5"
"@babel/helper-validator-option" "^7.22.5"
"@babel/plugin-syntax-jsx" "^7.22.5"
"@babel/plugin-transform-modules-commonjs" "^7.22.5"
"@babel/plugin-transform-typescript" "^7.22.5"

"@babel/regjsgen@^0.8.0":
version "0.8.0"
resolved "https://registry.npmjs.org/@babel/regjsgen/-/regjsgen-0.8.0.tgz"
Expand Down

0 comments on commit 26b2b71

Please sign in to comment.