From ceb0993e814c9b7f161fa58c85d5bdc01ab3cf2a Mon Sep 17 00:00:00 2001 From: atsushi-sugasaki Date: Thu, 30 Apr 2020 23:55:24 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E6=A4=9C=E6=9F=BB=E9=99=BD=E6=80=A7?= =?UTF-8?q?=E8=80=85=E3=81=AE=E7=8A=B6=E6=B3=81=E3=81=AE=E5=85=A5=E9=99=A2?= =?UTF-8?q?=E4=B8=AD=E3=81=AE=E5=80=A4=E3=82=92BODIK=E3=81=AE=E5=80=A4?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E3=81=86=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cards/ConfirmedCasesDetailsCard.vue | 2 +- services/bodikApi.js | 7 +- store/index.js | 75 ++++++++++--------- store/mapToPatientsNotCruise.js | 19 +++++ 4 files changed, 63 insertions(+), 40 deletions(-) create mode 100644 store/mapToPatientsNotCruise.js diff --git a/brigade/nagasaki/components/cards/ConfirmedCasesDetailsCard.vue b/brigade/nagasaki/components/cards/ConfirmedCasesDetailsCard.vue index 437adae749043..14223a26468e8 100644 --- a/brigade/nagasaki/components/cards/ConfirmedCasesDetailsCard.vue +++ b/brigade/nagasaki/components/cards/ConfirmedCasesDetailsCard.vue @@ -66,7 +66,7 @@ export default { const summary = this.$store.state.patientsNotCruise ? this.$store.state.patientsNotCruise : formatConfirmedCases(Data.main_summary) - console.log(summary, 'summary') + // console.log(summary, 'summary') return summary } }, diff --git a/services/bodikApi.js b/services/bodikApi.js index af674627b6a5c..dcf3ad27e6921 100644 --- a/services/bodikApi.js +++ b/services/bodikApi.js @@ -9,7 +9,7 @@ const nagasakiPrefectureConfirmedCasesId = 'de7ce61e-1849-47a1-b758-bca3f809cdf8' const nagasakiCityNewsId = 'eb0ba50a-7a97-4029-9b75-9c6bab0568f6' -const aonyMouseId = '438f03f1-0ee8-466d-a5d9-e874f5367507' +const nagasakiOtherInfoId = '438f03f1-0ee8-466d-a5d9-e874f5367507' export const fetchNagasakiPrefectureTestedCases = () => callFetchJsonp(baseUrl, nagasakiPrefectureTestedCasesId) @@ -18,7 +18,8 @@ export const fetchNagasakiPrefectureConfirmedCases = () => export const fetchNagasakiCityNews = () => callFetchJsonp(baseUrl, nagasakiCityNewsId) -export const fetchonyMouseId = () => callFetchJsonp(baseUrl, aonyMouseId) +export const fetchNagasakiOtherInfo = () => + callFetchJsonp(baseUrl, nagasakiOtherInfoId) export const axiosNagasakiPrefectureTestedCases = axios => axios.$get(baseUrl + nagasakiPrefectureTestedCasesId) @@ -26,3 +27,5 @@ export const axiosNagasakiPrefectureConfirmedCases = axios => axios.$get(baseUrl + nagasakiPrefectureConfirmedCasesId) export const axiosNagasakiCityNews = axios => axios.$get(baseUrl + nagasakiCityNewsId) +export const axiosNagasakiOtherInfo = axios => + axios.$get(baseUrl + nagasakiOtherInfoId) diff --git a/store/index.js b/store/index.js index 2f905c32b62a2..af24046b2e248 100644 --- a/store/index.js +++ b/store/index.js @@ -1,6 +1,7 @@ import dayjs from 'dayjs' import { bodikApi } from '../services' -import { groupBy, reducer } from './util.js' +import { groupBy } from './util.js' +import { mapToPatientsNotCruise } from './mapToPatientsNotCruise.js' import { convertDateToSimpleFormat } from '@/utils/formatDate' export const state = () => ({ @@ -60,9 +61,11 @@ export const mutations = { // 非同期データのロード後に呼ばれます。 allDataUpdated(state, data) { + // console.log(data, 'allDataUpdated data') const testedCases = data.testedCases const confirmedCases = data.confirmedCases const otherData = data.otherData + if (!testedCases || !confirmedCases) return state.otherData = otherData @@ -94,28 +97,8 @@ export const mutations = { } }) - // 検査陽性者の状況のデータ作成 - const 退院者数 = otherData.filter(d => d.KEY === '県内_退院者数') - const 死亡者数 = otherData.filter(d => d.KEY === '県内_死亡者数') - - // console.log(otherData, 'otherData') - // console.log(死亡者数, '死亡者数') - const taiin = 退院者数 ? Number(退院者数[0].VALUE) : 0 - const dead = 死亡者数 ? Number(死亡者数[0].VALUE) : 0 - // console.log(taiin, 'taiin') - // グラフ表示用のデータ作成 - const formattedData = { - 検査実施人数: testedCases.map(x => Number(x.件数)).reduce(reducer), - 陽性者数: notCruise.length, - 入院中: confirmedCases.length - taiin, - 軽症中等症: 0, - 重症: 0, - 死亡: dead, - 退院: taiin - } - // console.log(formattedData, 'formattedData') - - state.patientsNotCruise = formattedData + // 検査陽性者の状況のデータ + state.patientsNotCruise = mapToPatientsNotCruise(otherData) } } @@ -123,36 +106,54 @@ export const actions = { // NuxtのFetchでビルド時にデータ取得するときはこっちを使う async GET_BODIK_AXIOS({ commit }, $axios) { try { - const res = await bodikApi.axiosNagasakiPrefectureTestedCases($axios) - // console.log(res, 'res') - if (res.result.records) commit('setBodicData1', res.result.records) - - const res2 = await bodikApi.axiosNagasakiPrefectureConfirmedCases($axios) - // console.log(res2, 'res') - if (res2.result.records) commit('setBodicData2', res2.result.records) + const result1 = await bodikApi.axiosNagasakiPrefectureTestedCases($axios) + // console.log(result1, 'result1') + if (result1.result.records) + commit('setPrefectureTestedCases', result1.result.records) + + const result2 = await bodikApi.axiosNagasakiPrefectureConfirmedCases( + $axios + ) + // console.log(result2, 'result2') + if (result2.result.records) + commit('PrefectureConfirmedCases', result2.result.records) const newsRes = await bodikApi.axiosNagasakiCityNews($axios) - if (res.result.records) + if (newsRes.result.records) commit('setNagasakiCityNews', newsRes.result.records) + + // 長崎県新型コロナウイルス感染症発生件数等のロード + const result3 = await bodikApi.axiosNagasakiOtherInfo($axios) + // console.log(result3, 'result3') + + // 非同期データのロード後処理 + commit('allDataUpdated', { + testedCases: result1.result.records, + confirmedCases: result2.result.records, + otherData: result3.result.records + }) } catch (e) {} }, // ブラウザから非同期でBODIKからデータ取得するさいにはこちらを使う async GET_BODIK_JSONP({ commit }) { try { + // 長崎県新型コロナウイルス感染症検査実施数のロード const result1 = await bodikApi.fetchNagasakiPrefectureTestedCases() // console.log(result1, 'fetchNagasakiPrefectureTestedCases') - commit('setPrefectureTestedCases', result1.records) + if (result1.records) commit('setPrefectureTestedCases', result1.records) + // 長崎県新型コロナウイルス感染症陽性患者発表情報のロード const result2 = await bodikApi.fetchNagasakiPrefectureConfirmedCases() - commit('PrefectureConfirmedCases', result2.records) + if (result2.records) commit('PrefectureConfirmedCases', result2.records) - const news = await bodikApi.fetchNagasakiCityNews() - commit('setNagasakiCityNews', news.records) + const newsRes = await bodikApi.fetchNagasakiCityNews() + if (newsRes.records) commit('setNagasakiCityNews', newsRes.records) - const result3 = await bodikApi.fetchonyMouseId() + // 長崎県新型コロナウイルス感染症発生件数等のロード + const result3 = await bodikApi.fetchNagasakiCityNews() - /// / 非同期データのロード後処理 + // 非同期データのロード後処理 commit('allDataUpdated', { testedCases: result1.records, confirmedCases: result2.records, diff --git a/store/mapToPatientsNotCruise.js b/store/mapToPatientsNotCruise.js new file mode 100644 index 0000000000000..6363d92e7f010 --- /dev/null +++ b/store/mapToPatientsNotCruise.js @@ -0,0 +1,19 @@ +export function mapToPatientsNotCruise(otherData) { + // console.log(otherData, 'otherData') + // 検査陽性者の状況のデータ作成 + const 感染者数 = otherData.filter(d => d.KEY === '県内_感染者数') + const 退院者数 = otherData.filter(d => d.KEY === '県内_退院者数') + const 死亡者数 = otherData.filter(d => d.KEY === '県内_死亡者数') + const 入院者数 = otherData.filter(d => d.KEY === '県内_入院者数') + + // グラフ表示用のデータ作成 + return { + 検査実施人数: 0, + 陽性者数: 感染者数 ? Number(感染者数[0].VALUE) : 0, + 入院中: 入院者数 ? Number(入院者数[0].VALUE) : 0, + 軽症中等症: 0, + 重症: 0, + 死亡: 死亡者数 ? Number(死亡者数[0].VALUE) : 0, + 退院: 退院者数 ? Number(退院者数[0].VALUE) : 0 + } +} From 72cd31e7219c72fac7f2cd896f303f6b29c77807 Mon Sep 17 00:00:00 2001 From: atsushi-sugasaki Date: Fri, 1 May 2020 00:09:50 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E6=A4=9C=E6=9F=BB=E9=99=BD=E6=80=A7?= =?UTF-8?q?=E8=80=85=E3=81=AE=E7=8A=B6=E6=B3=81=20=E5=85=A5=E9=99=A2?= =?UTF-8?q?=E8=80=85=E6=95=B0=E3=81=8C=E9=96=93=E9=81=95=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=82=8B=20#273?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index.vue | 2 +- store/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index cebbf2bb37c09..9d2dc12ee0f18 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -99,7 +99,7 @@ export default Vue.extend({ }, async mounted() { // 動的に最新情報を取得する - await sleep(50) + await sleep(5000) await this.$store.dispatch('GET_BODIK_JSONP') }, head(): MetaInfo { diff --git a/store/index.js b/store/index.js index af24046b2e248..4da22262dd44a 100644 --- a/store/index.js +++ b/store/index.js @@ -151,7 +151,7 @@ export const actions = { if (newsRes.records) commit('setNagasakiCityNews', newsRes.records) // 長崎県新型コロナウイルス感染症発生件数等のロード - const result3 = await bodikApi.fetchNagasakiCityNews() + const result3 = await bodikApi.fetchNagasakiOtherInfo() // 非同期データのロード後処理 commit('allDataUpdated', { From 3ce73247a1da78364a60170a2bd924cc3b9d751c Mon Sep 17 00:00:00 2001 From: atsushi-sugasaki Date: Fri, 1 May 2020 00:17:05 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E6=A4=9C=E6=9F=BB=E9=99=BD=E6=80=A7?= =?UTF-8?q?=E8=80=85=E3=81=AE=E7=8A=B6=E6=B3=81=20=E5=85=A5=E9=99=A2?= =?UTF-8?q?=E8=80=85=E6=95=B0=E3=81=8C=E9=96=93=E9=81=95=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=82=8B=20#273?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.vue b/pages/index.vue index 9d2dc12ee0f18..cebbf2bb37c09 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -99,7 +99,7 @@ export default Vue.extend({ }, async mounted() { // 動的に最新情報を取得する - await sleep(5000) + await sleep(50) await this.$store.dispatch('GET_BODIK_JSONP') }, head(): MetaInfo {