Skip to content

Commit

Permalink
Update: ローラー作戦のChartData生成を共通化
Browse files Browse the repository at this point in the history
  • Loading branch information
a01sa01to committed May 4, 2021
1 parent ffb1300 commit c9f9532
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 93 deletions.
37 changes: 6 additions & 31 deletions components/roller/Mito.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,22 @@
</template>

<script>
import dayjs from 'dayjs'
import DataView from '@/components/DataView.vue'
import RollerChart from '@/components/RollerChart.vue'
import Data from '@/data/roller/mito.json'
import formatRollerInspection from '@/utils/formatRollerInspection'
export default {
components: {
DataView,
RollerChart,
},
data() {
// 検査陽性者の状況
const updatedAt = dayjs(Data.date).format('YYYY/MM/DD HH:mm')
const data = Data.data
const today = new Date()
const chartDataAccept = []
const chartDataCollect = []
let acSum = 0
let coSum = 0
data
.filter((d) => new Date(d.date) < today)
.forEach((d) => {
const date = new Date(d.date)
if (!isNaN(d.accept) && !isNaN(d.collect)) {
acSum += d.accept
coSum += d.collect
chartDataAccept.push({
label: `${date.getMonth() + 1}/${date.getDate()}`,
transition: d.accept,
cumulative: acSum,
})
chartDataCollect.push({
label: `${date.getMonth() + 1}/${date.getDate()}`,
transition: d.collect,
cumulative: coSum,
})
}
})
const {
chartDataAccept,
chartDataCollect,
updatedAt,
} = formatRollerInspection(Data)
return {
Data,
chartDataAccept,
Expand Down
37 changes: 6 additions & 31 deletions components/roller/TsuchiuraSakura.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,22 @@
</template>

<script>
import dayjs from 'dayjs'
import DataView from '@/components/DataView.vue'
import RollerChart from '@/components/RollerChart.vue'
import Data from '@/data/roller/tsuchiuraSakura.json'
import formatRollerInspection from '@/utils/formatRollerInspection'
export default {
components: {
DataView,
RollerChart,
},
data() {
// 検査陽性者の状況
const updatedAt = dayjs(Data.date).format('YYYY/MM/DD HH:mm')
const data = Data.data
const today = new Date()
const chartDataAccept = []
const chartDataCollect = []
let acSum = 0
let coSum = 0
data
.filter((d) => new Date(d.date) < today)
.forEach((d) => {
const date = new Date(d.date)
if (!isNaN(d.accept) && !isNaN(d.collect)) {
acSum += d.accept
coSum += d.collect
chartDataAccept.push({
label: `${date.getMonth() + 1}/${date.getDate()}`,
transition: d.accept,
cumulative: acSum,
})
chartDataCollect.push({
label: `${date.getMonth() + 1}/${date.getDate()}`,
transition: d.collect,
cumulative: coSum,
})
}
})
const {
chartDataAccept,
chartDataCollect,
updatedAt,
} = formatRollerInspection(Data)
return {
Data,
chartDataAccept,
Expand Down
37 changes: 6 additions & 31 deletions components/roller/TsukubaAmakubo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,22 @@
</template>

<script>
import dayjs from 'dayjs'
import DataView from '@/components/DataView.vue'
import RollerChart from '@/components/RollerChart.vue'
import Data from '@/data/roller/tsukubaAmakubo.json'
import formatRollerInspection from '@/utils/formatRollerInspection'
export default {
components: {
DataView,
RollerChart,
},
data() {
// 検査陽性者の状況
const updatedAt = dayjs(Data.date).format('YYYY/MM/DD HH:mm')
const data = Data.data
const today = new Date()
const chartDataAccept = []
const chartDataCollect = []
let acSum = 0
let coSum = 0
data
.filter((d) => new Date(d.date) < today)
.forEach((d) => {
const date = new Date(d.date)
if (!isNaN(d.accept) && !isNaN(d.collect)) {
acSum += d.accept
coSum += d.collect
chartDataAccept.push({
label: `${date.getMonth() + 1}/${date.getDate()}`,
transition: d.accept,
cumulative: acSum,
})
chartDataCollect.push({
label: `${date.getMonth() + 1}/${date.getDate()}`,
transition: d.collect,
cumulative: coSum,
})
}
})
const {
chartDataAccept,
chartDataCollect,
updatedAt,
} = formatRollerInspection(Data)
return {
Data,
chartDataAccept,
Expand Down
51 changes: 51 additions & 0 deletions utils/formatRollerInspection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import dayjs from 'dayjs'
type DataType = {
date: string
nowTotal: { ac: number; co: number }
data: { date: string; accept: number; collect: number }[]
}
type ChartDataType = {
label: string
transition: number
cumulative: number
}[]
export default (Data: DataType) => {
// 検査陽性者の状況
const updatedAt = dayjs(Data.date).format('YYYY/MM/DD HH:mm')

const data = Data.data
const today = new Date()
const chartDataAccept: ChartDataType = []
const chartDataCollect: ChartDataType = []
let acSum = 0
let coSum = 0
data
.filter((d) => new Date(d.date) < today)
.forEach((d) => {
const date = new Date(d.date)
if (!isNaN(d.accept) && !isNaN(d.collect)) {
acSum += d.accept
coSum += d.collect
chartDataAccept.push({
label: `${date.getFullYear()}/${
date.getMonth() + 1
}/${date.getDate()}`,
transition: d.accept,
cumulative: acSum,
})
chartDataCollect.push({
label: `${date.getFullYear()}/${
date.getMonth() + 1
}/${date.getDate()}`,
transition: d.collect,
cumulative: coSum,
})
}
})

return {
chartDataAccept,
chartDataCollect,
updatedAt,
}
}

0 comments on commit c9f9532

Please sign in to comment.