Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2ae8989
Bump minimist, mkdirp and loader-fs-cache
dependabot[bot] Nov 11, 2022
85284df
Bump decode-uri-component from 0.2.0 to 0.2.2
dependabot[bot] Dec 4, 2022
eedf4b9
Bump qs from 6.5.2 to 6.5.3
dependabot[bot] Dec 10, 2022
12e1435
Add YearMonth
akiomik Dec 23, 2022
5f03def
Add type-helper
akiomik Dec 24, 2022
7136c16
Add PropertyPathResolver
akiomik Dec 24, 2022
99dddd2
Add Monthly
akiomik Dec 23, 2022
df09869
Add BuffettCodeApiClientV3#monthly
akiomik Dec 23, 2022
cde911e
Add MonthlyCache
akiomik Dec 23, 2022
3129592
Add CachingBuffettCodeApiClientV3#monthly
akiomik Dec 23, 2022
281e8c6
Add bcode-monthly
akiomik Dec 24, 2022
23e6c37
Merge pull request #105 from BuffettCode/dependabot/npm_and_yarn/qs-6…
akiomik Dec 26, 2022
51fae72
Merge pull request #104 from BuffettCode/dependabot/npm_and_yarn/deco…
akiomik Dec 26, 2022
d9c18ac
Merge pull request #101 from BuffettCode/dependabot/npm_and_yarn/mini…
akiomik Dec 26, 2022
f5d9dc8
Bump minimatch and recursive-readdir
dependabot[bot] Dec 26, 2022
631f758
Bump json5, eslint-loader, ts-loader, webpack and webpack-cli
dependabot[bot] Jan 1, 2023
859df7a
Merge pull request #108 from BuffettCode/dependabot/npm_and_yarn/json…
akiomik Jan 4, 2023
a6ad386
Merge pull request #107 from BuffettCode/dependabot/npm_and_yarn/mini…
akiomik Jan 4, 2023
2fda28b
Merge pull request #106 from BuffettCode/monthly
akiomik Jan 13, 2023
c54d32a
Bump http-cache-semantics from 4.1.0 to 4.1.1
dependabot[bot] Feb 4, 2023
e8bdc82
Bump minimist and mkdirp
dependabot[bot] Mar 3, 2023
a9e47bf
Bump webpack from 5.75.0 to 5.76.0
dependabot[bot] Mar 15, 2023
fb89f88
Improve error message
akiomik Jul 31, 2023
bd872bb
Merge pull request #112 from BuffettCode/improve-error-message
akiomik Jul 31, 2023
0941022
Merge pull request #111 from BuffettCode/dependabot/npm_and_yarn/webp…
akiomik Jul 31, 2023
b60b88e
Merge pull request #110 from BuffettCode/dependabot/npm_and_yarn/mini…
akiomik Jul 31, 2023
e710764
Merge pull request #109 from BuffettCode/dependabot/npm_and_yarn/http…
akiomik Jul 31, 2023
0340ef4
Bump word-wrap from 1.2.3 to 1.2.5
dependabot[bot] Jul 31, 2023
2c0557c
Add isOutOfQuarterApiRange and isOutOfDailyApiRange
akiomik Aug 19, 2023
b97110c
Add UnsupportedRangeError
akiomik Aug 19, 2023
83e9b51
Merge pull request #115 from BuffettCode/fix-out-of-range-error-messages
akiomik Aug 21, 2023
2691b71
Merge pull request #114 from BuffettCode/dependabot/npm_and_yarn/word…
akiomik Aug 21, 2023
a3f5c33
Bump version to v17
akiomik Aug 21, 2023
aaa48c2
Merge pull request #116 from BuffettCode/bump-v17
akiomik Aug 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5,321 changes: 1,893 additions & 3,428 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"eslint": "^6.7.2",
"eslint-config-prettier": "^6.7.0",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-loader": "^3.0.3",
"eslint-loader": "^4.0.2",
"eslint-plugin-import": "^2.24.0",
"eslint-plugin-prettier": "^3.1.1",
"gas-webpack-plugin": "^1.0.2",
Expand All @@ -22,11 +22,11 @@
"prettier": "^1.19.1",
"rimraf": "^3.0.0",
"ts-jest": "^24.2.0",
"ts-loader": "^6.2.1",
"ts-loader": "^9.4.2",
"tsconfig-paths-webpack-plugin": "^3.5.1",
"typescript": "^3.7.3",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.12"
"webpack": "^5.76.0",
"webpack-cli": "^5.0.1"
},
"scripts": {
"update-api-json": "npm run update-api-json:quarter && npm run update-api-json:indicator",
Expand Down
13 changes: 13 additions & 0 deletions src/__mocks__/api/v3/client.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { HTTPResnpose } from '~/__mocks__/api/v3/http-response'
import { default as company } from '~/__mocks__/fixtures/v3/company.js'
import { default as daily } from '~/__mocks__/fixtures/v3/daily.js'
import { default as monthly } from '~/__mocks__/fixtures/v3/monthly.js'
import { default as quarter } from '~/__mocks__/fixtures/v3/quarter.js'
import { HttpError } from '~/api/http-error'
import { Company } from '~/entities/v3/company'
import { Daily } from '~/entities/v3/daily'
import { Monthly } from '~/entities/v3/monthly'
import { Quarter } from '~/entities/v3/quarter'

export class BuffettCodeApiClientV3 {
public mockCompany = jest.fn()
public mockDaily = jest.fn()
public mockMonthly = jest.fn()
public mockQuarter = jest.fn()

constructor(readonly token: string) {
this.mockCompany.mockReturnValue(company)
this.mockDaily.mockReturnValue(daily)
this.mockMonthly.mockReturnValue(monthly)
this.mockQuarter.mockReturnValue(quarter)
}

Expand Down Expand Up @@ -62,4 +66,13 @@ export class BuffettCodeApiClientV3 {

return Quarter.fromResponse(this.mockQuarter())
}

monthly(ticker: string): Monthly {
if (ticker !== '2371') {
const res = new HTTPResnpose()
throw new HttpError('/v3/company', res)
}

return Monthly.fromResponse(this.mockMonthly())
}
}
155 changes: 155 additions & 0 deletions src/__mocks__/fixtures/v3/monthly.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
module.exports = {
data: {
ticker: "2371",
year: 2022,
month: 5,
beta: {
years_2: {
start_date: "2020-06-01",
end_date: "2022-05-31",
beta: -0.16,
alpha: -0.01,
r: -0.19,
r_squared: 0.04,
count: 24
},
years_3: {
start_date: "2019-06-01",
end_date: "2022-05-31",
beta: 0.07,
alpha: 0.0,
r: 0.11,
r_squared: 0.01,
count: 36
},
years_5: {
start_date: "2017-06-01",
end_date: "2022-05-31",
beta: 0.12,
alpha: 0.0,
r: 0.19,
r_squared: 0.04,
count: 60
}
},
kpi: [{
name: "全店 売上(円)",
value: 3477000000.0
}]
},
column_description: {
ticker: {
name_jp: "ティッカー",
unit: "なし"
},
year: {
name_jp: "年",
unit: "なし"
},
month: {
name_jp: "月",
unit: "なし"
},
beta: {
years_2: {
start_date: {
name_jp: "開始日",
unit: "日付"
},
end_date: {
name_jp: "終了日",
unit: "日付"
},
beta: {
name_jp: "β",
unit: "なし"
},
alpha: {
name_jp: "α",
unit: "なし"
},
r: {
name_jp: "相関係数",
unit: "なし"
},
r_squared: {
name_jp: "決定係数",
unit: "なし"
},
count: {
name_jp: "利用データ数",
unit: "個"}
},
years_3: {
start_date: {
name_jp: "開始日",
unit: "日付"
},
end_date: {
name_jp: "終了日",
unit: "日付"
},
beta: {
name_jp: "β",
unit: "なし"
},
alpha: {
name_jp: "α",
unit: "なし"
},
r: {
name_jp: "相関係数",
unit: "なし"
},
r_squared: {
name_jp: "決定係数",
unit: "なし"
},
count: {
name_jp: "利用データ数",
unit: "個"
}
},
years_5: {
start_date: {
name_jp: "開始日",
unit: "日付"
},
end_date: {
name_jp: "終了日",
unit: "日付"
},
beta: {
name_jp: "β",
unit: "なし"
},
alpha: {
name_jp: "α",
unit: "なし"
},
r: {
name_jp: "相関係数",
unit: "なし"
},
r_squared: {
name_jp: "決定係数",
unit: "なし"
},
count: {
name_jp: "利用データ数",
unit: "個"
}
}
},
kpi: {
name: {
name_jp: "指標",
unit: "なし"
},
value: {
name_jp: "値",
unit: "指標による"
}
}
}
}
44 changes: 44 additions & 0 deletions src/__mocks__/services/monthly-cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Monthly } from '~/entities/v3/monthly'
import { YearMonth } from '~/fiscal-periods/year-month'

export class MonthlyCache {
static readonly cache = {}

static get(ticker: string, yearMonth: YearMonth): Monthly | null {
const cachedData = this.getData(ticker, yearMonth)
const cachedColumnDescription = this.getColumnDescription()
if (cachedData == undefined || cachedColumnDescription == undefined) {
return null
}

return new Monthly(cachedData, cachedColumnDescription)
}

private static getData(ticker: string, yearMonth: YearMonth): object | null {
const cached = this.cache[`${ticker}-${yearMonth}`]
return cached === undefined ? null : cached
}

private static getColumnDescription(): object | null {
const cached = this.cache['column-description']
return cached === undefined ? null : cached
}

static put(ticker: string, monthly: Monthly): void {
this.putData(ticker, monthly)
this.putColumnDescription(monthly.columnDescription)
}

private static putData(ticker: string, monthly: Monthly): void {
this.cache[`${ticker}-${monthly.period()}`] = monthly.data
}

private static putColumnDescription(columnDescription: object): void {
this.cache['column-description'] = columnDescription
}

// for testing
static clearAll(): void {
Object.keys(this.cache).forEach(key => delete this.cache[key])
}
}
25 changes: 25 additions & 0 deletions src/api/company-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,28 @@ test('isOndemandDailyApiPeriod', () => {
expect(service.isOndemandDailyApiPeriod(DateParam.from(new Date()))).toBe(false)
expect(service.isOndemandDailyApiPeriod(DateParam.from('latest'))).toBe(false)
})

test('isOutOfQuarterApiRange', () => {
const client = new CachingBuffettCodeApiClientV3('token')
const service = new CompanyService('2371', client)

expect(service.isOutOfQuarterApiRange(new YearQuarter(2001, 3))).toBe(true)
expect(service.isOutOfQuarterApiRange(new YearQuarter(2001, 4))).toBe(false)
expect(service.isOutOfQuarterApiRange(new YearQuarterParam(LY, 3))).toBe(false)
expect(service.isOutOfQuarterApiRange(new YearQuarterParam(2001, LQ))).toBe(true)
expect(service.isOutOfQuarterApiRange(new YearQuarterParam(LY, LQ))).toBe(false)
expect(service.isOutOfQuarterApiRange(new YearQuarterParam(new LyWithOffset(-20), 3))).toBe(true)
expect(service.isOutOfQuarterApiRange(new YearQuarterParam(new LyWithOffset(-20), 4))).toBe(false)
expect(service.isOutOfQuarterApiRange(new YearQuarterParam(new LyWithOffset(-20), LQ))).toBe(true)
})

test('isOutOfDailyApiRange', () => {
const client = new CachingBuffettCodeApiClientV3('token')
const service = new CompanyService('2371', client)

expect(service.isOutOfDailyApiRange(DateParam.from(new Date('2003-10-09')))).toBe(true)
expect(service.isOutOfDailyApiRange(DateParam.from(new Date('2003-10-10')))).toBe(false)
expect(service.isOutOfDailyApiRange(DateParam.from(new Date()))).toBe(false)
expect(service.isOutOfDailyApiRange(DateParam.from(new Date('2999-12-31')))).toBe(true)
expect(service.isOutOfDailyApiRange(DateParam.from('latest'))).toBe(false)
})
30 changes: 30 additions & 0 deletions src/api/company-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,34 @@ export class CompanyService {

return date.toDate().valueOf() < fixedTierOldestDate.valueOf()
}

public isOutOfQuarterApiRange(_period: YearQuarter | YearQuarterParam): boolean {
let period: YearQuarter
if (_period instanceof YearQuarterParam) {
period = this.convertYearQuarterParamToYearQuarter(_period)
} else {
period = _period
}

const oldestPeriod = new YearQuarter(
this.company.data['oldest_fiscal_year'],
this.company.data['oldest_fiscal_quarter']
)

return !period.isAfterOrEqual(oldestPeriod)
}

public isOutOfDailyApiRange(dateParam: DateParam): boolean {
if (dateParam.isLatest()) {
return false
}

const date = dateParam.toDate()
if (date.valueOf() > new Date().valueOf()) {
return true
}

const oldestDate = new Date(this.company.data['oldest_date'])
return date.valueOf() < oldestDate.valueOf()
}
}
36 changes: 36 additions & 0 deletions src/api/v3/caching-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { CompanyCache } from '~/__mocks__/services/company-cache'
import { DailyCache } from '~/__mocks__/services/daily-cache'
import { MonthlyCache } from '~/__mocks__/services/monthly-cache'
import { QuarterCache } from '~/__mocks__/services/quarter-cache'
import { CachingBuffettCodeApiClientV3 } from '~/api/v3/caching-client'
import { DateParam } from '~/fiscal-periods/date-param'
import { LqWithOffset } from '~/fiscal-periods/lq-with-offset'
import { LyWithOffset } from '~/fiscal-periods/ly-with-offset'
import { YearMonth } from '~/fiscal-periods/year-month'
import { YearQuarter } from '~/fiscal-periods/year-quarter'
import { YearQuarterParam } from '~/fiscal-periods/year-quarter-param'

jest.mock('~/api/v3/client', () => jest.requireActual('~/__mocks__/api/v3/client'))
jest.mock('~/services/company-cache', () => jest.requireActual('~/__mocks__/services/company-cache'))
jest.mock('~/services/daily-cache', () => jest.requireActual('~/__mocks__/services/daily-cache'))
jest.mock('~/services/monthly-cache', () => jest.requireActual('~/__mocks__/services/monthly-cache'))
jest.mock('~/services/quarter-cache', () => jest.requireActual('~/__mocks__/services/quarter-cache'))

const LY = new LyWithOffset()
Expand Down Expand Up @@ -208,3 +211,36 @@ describe('ondemandDaily', () => {
expect(DailyCache.get(ticker, period)).toEqual(cached)
})
})

describe('monthly', () => {
const ticker = '2371'

beforeAll(() => {
MonthlyCache.clearAll()
})

const period = new YearMonth(2022, 5)

test('(uncached)', () => {
expect(MonthlyCache.get(ticker, period)).toBeNull()

const client = new CachingBuffettCodeApiClientV3('token')
const res = client.monthly(ticker, period)
expect(res).not.toBeNull()
expect(res.period()).toEqual(period)

expect(MonthlyCache.get(ticker, period)).toEqual(res)
})

test('(cached)', () => {
const cached = MonthlyCache.get(ticker, period)
expect(cached).not.toBeNull()

const client = new CachingBuffettCodeApiClientV3('token')
const res = client.monthly(ticker, period)
expect(res).toEqual(cached)
expect(res.period()).toEqual(period)

expect(MonthlyCache.get(ticker, period)).toEqual(cached)
})
})
Loading