Skip to content

Commit

Permalink
Fix parsing directly bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mirumirumi committed Nov 26, 2023
1 parent 24a9364 commit b6d683f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/app/services/parse-file.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Result } from "ts-results"

import { KLineSource } from "../shared/types"
import { ParseFileService } from "./parse-file.service"

Expand Down Expand Up @@ -111,8 +112,6 @@ describe("ParseFileService", () => {
expect(service.json(_2).val).toEqual(_2_e)
})

test("raw()", () => {})

test("extractKLineFromParsed()", () => {
const _1 = [
["1696497780000", "27687.9", "27718.5", "27687.9", "27698.5", "1041.273"],
Expand Down
6 changes: 4 additions & 2 deletions src/app/services/parse-file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class ParseFileService {
// csv, tsv, txt: As is (TOHLCV is assumed to be in order)

if (file.ext !== "json") {
if (!/^[0-9,\s\[\]]+$/.test(file.value)) {
if (!/^[0-9,\.\s\[\]]+$/.test(file.value)) {
return new Err(new ParseError(`${file.name}.${file.ext}`))
}
}
Expand Down Expand Up @@ -143,7 +143,7 @@ export class ParseFileService {
}

protected raw(value: string): Result<KLineSource, Error> {
const parsed = Papa.parse(value, { delimiter: "," })
const parsed = Papa.parse(value)
if (0 < parsed.errors.length) {
return new Err(Error())
}
Expand All @@ -163,6 +163,8 @@ export class ParseFileService {
)
} else if (value.includes(",")) {
result = parsed.data as Array<Array<string>>
} else if (value.includes("\t")) {
result = parsed.data as Array<Array<string>>
} else {
return new Err(Error())
}
Expand Down

0 comments on commit b6d683f

Please sign in to comment.