Skip to content

Commit

Permalink
Merge pull request #7 from mirumirumi/dev
Browse files Browse the repository at this point in the history
release
  • Loading branch information
mirumirumi authored Nov 26, 2023
2 parents dccab59 + b6d683f commit 3af2f2e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 4 additions & 5 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 All @@ -14,7 +15,7 @@ describe("ParseFileService", () => {
}
public override synonymMapping: { [key: string]: string } = {}

public override json(value: string): KLineSource {
public override json(value: string): Result<KLineSource, Error> {
return super.json(value)
}

Expand Down Expand Up @@ -70,7 +71,7 @@ describe("ParseFileService", () => {
volume: 233.359,
},
]
expect(service.json(_1)).toEqual(_1_e)
expect(service.json(_1).val).toEqual(_1_e)

const _2 = `[
{
Expand Down Expand Up @@ -108,11 +109,9 @@ describe("ParseFileService", () => {
volume: 233.359,
},
]
expect(service.json(_2)).toEqual(_2_e)
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 3af2f2e

Please sign in to comment.