diff options
| -rw-r--r-- | package.json | 2 | ||||
| -rw-r--r-- | src/conversion/csv/excel.ts | 97 | ||||
| -rw-r--r-- | src/conversion/czi/czi.ts | 2 | ||||
| -rw-r--r-- | yarn.lock | 24 |
4 files changed, 109 insertions, 16 deletions
diff --git a/package.json b/package.json index d683178..1f0e52d 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "typescript": "^2.7.1", "uuid": "^3.2.1", "winston": "^2.4.0", - "xlsx": "^0.11.19", + "xlsx": "^0.12.10", "xml-parser": "^1.2.1" } } diff --git a/src/conversion/csv/excel.ts b/src/conversion/csv/excel.ts new file mode 100644 index 0000000..2764192 --- /dev/null +++ b/src/conversion/csv/excel.ts @@ -0,0 +1,97 @@ +import { logger } from '../../logger'; +import * as xlsx from 'xlsx'; +import * as fs from 'fs'; + +// const testDir: string = `/cs/scratch/cjd24/csv/`; +// const testFile: string = `test1.xlsx` + + +const toCSV: (file: string) => Promise<string[]> = async (file: string): Promise<string[]> => { + logger.info(`xls convertor received new file to convert to csv: ${file}`); + + let book: xlsx.WorkBook = xlsx.readFile(file); + try { + let sheetnames: string[] = []; + for (let name of book.SheetNames) { + fs.writeFile(`${file.split('.')[0]}-${name}.csv`, xlsx.utils.sheet_to_csv(book.Sheets[name])); + sheetnames.push(`${file.split('.')[0]}-${name}.csv`); + logger.info(`Wrote ${file.split('.')[1]} subsheet {${file} : ${name}} as CSV.`); + } + return sheetnames === [] ? ["__Empty_Book_Error"] : sheetnames; + } catch (err) { + logger.error(err); + return ["__Conversion_to_csv_Error_Occurred: " + err] + } +} + +const toJSON: (file: string) => Promise<string[]> = async (file: string): Promise<string[]> => { + logger.info(`xls convertor received new file to convert to json: ${file}`); + + let book: xlsx.WorkBook = xlsx.readFile(file); + try { + let sheetnames: string[] = []; + for (let name of book.SheetNames) { + fs.writeFile(`${file.split('.')[0]}-${name}.json`, xlsx.utils.sheet_to_json(book.Sheets[name])); + sheetnames.push(`${file.split('.')[0]}-${name}.json`); + logger.info(`Wrote ${file.split('.')[1]} subsheet {${file} : ${name}} as JSON.`); + } + return sheetnames === [] ? ["__Empty_Book_Error"] : sheetnames; + } catch (err) { + logger.error(err); + return ["__Conversion_to_json_Error_Occurred: " + err] + } +} + +const toHTML: (file: string) => Promise<string[]> = async (file: string): Promise<string[]> => { + logger.info(`xls convertor received new file to convert to html: ${file}`); + + let book: xlsx.WorkBook = xlsx.readFile(file); + try { + let sheetnames: string[] = []; + for (let name of book.SheetNames) { + fs.writeFile(`${file.split('.')[0]}-${name}.html`, xlsx.utils.sheet_to_html(book.Sheets[name])); + sheetnames.push(`${file.split('.')[0]}-${name}.html`); + logger.info(`Wrote ${file.split('.')[1]} subsheet {${file} : ${name}} as HTML.`); + } + return sheetnames === [] ? ["__Empty_Book_Error"] : sheetnames; + } catch (err) { + logger.error(err); + return ["__Conversion_to_html_Error_Occurred: " + err] + } +} + +const toAll: (file: string) => +Promise<{csv: string[], json: string[], html: string[]}> = +async (file: string): +Promise<{csv: string[], json: string[], html: string[]}> => { + return { + csv: await toCSV(file), + json: await toCSV(file), + html: await toCSV(file) + } +} + + +// const main: () => void = async (): Promise<void> => { +// +// try { +// let file: xlsx.WorkBook = xlsx.readFile(`${testDir}${testFile}`); +// +// for (let name of file.SheetNames) { +// fs.writeFileSync(`${testDir}${testFile.split('.')[0]}-${name}.csv`, xlsx.utils.sheet_to_csv(file.Sheets[name])); +// logger.info(`Wrote ${testFile.split('.')[1]} subsheet {${testFile} : ${name}} as CSV.`); +// fs.writeFileSync(`${testDir}${testFile.split('.')[0]}-${name}.json`, xlsx.utils.sheet_to_json(file.Sheets[name])); +// logger.info(`Wrote ${testFile.split('.')[1]} subsheet {${testFile} : ${name}} as json.`); +// fs.writeFileSync(`${testDir}${testFile.split('.')[0]}-${name}.html`, xlsx.utils.sheet_to_html(file.Sheets[name])); +// logger.info(`Wrote ${testFile.split('.')[1]} subsheet {${testFile} : ${name}} as HTML.`); +// } +// +// logger.success(`Wrote ${testFile.split('.')[1]} {${testFile}} as CSV.`); +// logger.success(`Wrote ${testFile.split('.')[1]} {${testFile}} as JSON.`); +// logger.success(`Wrote ${testFile.split('.')[1]} {${testFile}} as HTML.`); +// } catch (err) { +// // console.log(err); +// logger.error(err); +// } +// }; +// main(); diff --git a/src/conversion/czi/czi.ts b/src/conversion/czi/czi.ts index 1d157ff..1a92fa6 100644 --- a/src/conversion/czi/czi.ts +++ b/src/conversion/czi/czi.ts @@ -715,7 +715,7 @@ const buildCustomPyramids: () => Promise<void> = async(): Promise<void> => { // Extract the base tiles and build up custom pyramid data await extrapolateDimension( Number.parseInt(cval.channel_id, 10), - supportedViews.scalable_image.channels.length * Math.log2(maxZoom), + supportedViews.scalable_image.channels.length * Math.log2(maxZoom * 2), maxZoom ).then((v: CZIHeightMap[]) => { // On success, add the new heightmap to the final json data block @@ -481,7 +481,7 @@ center-align@^0.1.1: align-text "^0.1.3" lazy-cache "^1.0.3" -cfb@~1.0.2: +cfb@~1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/cfb/-/cfb-1.0.6.tgz#d0107fa579a8d79c53a31074a755abcb898017f0" dependencies: @@ -547,7 +547,7 @@ code-point-at@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" -codepage@~1.12.0: +codepage@~1.12.1: version "1.12.2" resolved "https://registry.yarnpkg.com/codepage/-/codepage-1.12.2.tgz#fd4424448c8bf1db5d7e01f9ecf9e8346582a195" dependencies: @@ -602,10 +602,6 @@ commander@^2.12.1, commander@^2.14.1: version "2.15.1" resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f" -commander@~2.13.0: - version "2.13.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c" - commander@~2.14.1: version "2.14.1" resolved "https://registry.yarnpkg.com/commander/-/commander-2.14.1.tgz#2235123e37af8ca3c65df45b026dbd357b01b9aa" @@ -2065,7 +2061,7 @@ sqlite3@^4.0.0: nan "~2.9.2" node-pre-gyp "~0.9.0" -ssf@~0.10.1: +ssf@~0.10.2: version "0.10.2" resolved "https://registry.yarnpkg.com/ssf/-/ssf-0.10.2.tgz#65b2b4fcdfd967bc8e8383a41349009893115976" dependencies: @@ -2444,17 +2440,17 @@ wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" -xlsx@^0.11.19: - version "0.11.19" - resolved "https://registry.yarnpkg.com/xlsx/-/xlsx-0.11.19.tgz#2f019d9df756f6345aac5bc1af2442cf22a025e3" +xlsx@^0.12.10: + version "0.12.10" + resolved "https://registry.yarnpkg.com/xlsx/-/xlsx-0.12.10.tgz#c2e71be364d90ece2e08f0bae91563483c4897f8" dependencies: adler-32 "~1.2.0" - cfb "~1.0.2" - codepage "~1.12.0" - commander "~2.13.0" + cfb "~1.0.6" + codepage "~1.12.1" + commander "~2.14.1" crc-32 "~1.2.0" exit-on-epipe "~1.0.1" - ssf "~0.10.1" + ssf "~0.10.2" xml-parser@^1.2.1: version "1.2.1" |
