This repository was archived by the owner on Sep 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Use v3 endpoint in csv exporter #61
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import * as response from '~/__mocks__/fixtures/v3/daily' | ||
| import { Daily } from '~/entities/v3/daily' | ||
|
|
||
| const daily = Daily.fromResponse(response) | ||
|
|
||
| test('period', () => { | ||
| expect(daily.period()).toEqual(new Date('2020-09-06')) | ||
| }) | ||
|
|
||
| test('propertyNames', () => { | ||
| expect(daily.propertyNames()).toEqual( | ||
| Object.keys(response['column_description']) | ||
| ) | ||
| }) | ||
|
|
||
| test('labelOf', () => { | ||
| expect(daily.labelOf('day')).toEqual('日付') | ||
| expect(daily.labelOf('market_capital')).toEqual('時価総額') | ||
| }) | ||
|
|
||
| test('unitOf', () => { | ||
| expect(daily.unitOf('day')).toEqual('単位無し') | ||
| expect(daily.unitOf('market_capital')).toEqual('円') | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| export interface HasColumnDescription { | ||
| propertyNames(): string[] | ||
|
|
||
| labelOf(propertyName: string): string | null | ||
|
|
||
| unitOf(propertyName: string): string | null | ||
| } | ||
|
|
||
| export interface HasPeriod<T> { | ||
| period(): T | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import * as response from '~/__mocks__/fixtures/v3/quarter' | ||
| import { Quarter } from '~/entities/v3/quarter' | ||
| import { YearQuarter } from '~/fiscal-periods/year-quarter' | ||
|
|
||
| const quarter = Quarter.fromResponse(response) | ||
|
|
||
| test('period', () => { | ||
| expect(quarter.period()).toEqual(new YearQuarter(2018, 1)) | ||
| }) | ||
|
|
||
| test('propertyNames', () => { | ||
| expect(quarter.propertyNames()).toEqual( | ||
| Object.keys(response['column_description']) | ||
| ) | ||
| }) | ||
|
|
||
| test('labelOf', () => { | ||
| expect(quarter.labelOf('fiscal_year')).toEqual('会計年度') | ||
| expect(quarter.labelOf('net_sales')).toEqual('売上') | ||
| }) | ||
|
|
||
| test('unitOf', () => { | ||
| expect(quarter.unitOf('fiscal_year')).toEqual('なし') | ||
| expect(quarter.unitOf('net_sales')).toEqual('円') | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| import { CompanyService } from '~/api/company-service' | ||
| import { OndemandApiPeriodRange } from '~/api/ondemand-api-period-range' | ||
| import { CachingBuffettCodeApiClientV2 } from '~/api/v2/caching-client' | ||
| import { CachingQuarterProperty } from '~/api/v2/caching-quarter-property' | ||
| import { CachingBuffettCodeApiClientV3 } from '~/api/v3/caching-client' | ||
| import { YearQuarter } from '~/fiscal-periods/year-quarter' | ||
| import { YearQuarterParam } from '~/fiscal-periods/year-quarter-param' | ||
| import { YearQuarterRange } from '~/fiscal-periods/year-quarter-range' | ||
|
|
@@ -23,7 +22,7 @@ export class CsvExporter { | |
| const range = new YearQuarterRange(fromYearQuarter, toYearQuarter) | ||
|
|
||
| const setting = Setting.load() | ||
| const client = new CachingBuffettCodeApiClientV2(setting.token) | ||
| const client = new CachingBuffettCodeApiClientV3(setting.token) | ||
| const companyService = new CompanyService(ticker, client, today) | ||
| if (!companyService.isSupportedTicker()) { | ||
| throw new Error('<<サポートされていないtickerです>>') | ||
|
|
@@ -65,8 +64,8 @@ export class CsvExporter { | |
| } | ||
|
|
||
| const sortedQuarters = quarters.slice().sort((a, b) => { | ||
| const labelA = `${a['fiscal_year']}Q${a['fiscal_quarter']}` | ||
| const labelB = `${b['fiscal_year']}Q${b['fiscal_quarter']}` | ||
| const labelA = a.period().toString() | ||
| const labelB = b.period().toString() | ||
|
Comment on lines
+67
to
+68
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| if (labelA > labelB) { | ||
| return 1 | ||
| } else if (labelA < labelB) { | ||
|
|
@@ -76,18 +75,14 @@ export class CsvExporter { | |
| } | ||
| }) | ||
|
|
||
| const quarterLabels = sortedQuarters.map( | ||
| quarter => `${quarter['fiscal_year']}Q${quarter['fiscal_quarter']}` | ||
| const quarter = quarters[0] | ||
| const quarterLabels = sortedQuarters.map(quarter => | ||
| quarter.period().toString() | ||
| ) | ||
| const header = [['キー', '項目名', '単位', ...quarterLabels]] | ||
| const values = CachingQuarterProperty.names().map(name => { | ||
| const data = sortedQuarters.map(quarter => quarter[name]) | ||
| return [ | ||
| name, | ||
| CachingQuarterProperty.labelOf(name), | ||
| CachingQuarterProperty.unitOf(name), | ||
| ...data | ||
| ] | ||
| const values = quarter.propertyNames().map(name => { | ||
| const data = sortedQuarters.map(quarter => quarter.data[name]) | ||
| return [name, quarter.labelOf(name), quarter.unitOf(name), ...data] | ||
|
Comment on lines
+83
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. なるほど |
||
| }) | ||
|
|
||
| return [...header, ...values] | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍