Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
update utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdmaster committed Jan 26, 2022
1 parent a8a7936 commit c421400
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 94 deletions.
96 changes: 48 additions & 48 deletions utils/formatConfirmedCases.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
const DataType: type = {
const DataType = {
children: [
{
attr: '陽性患者数'
value: number
attr: '陽性患者数',
value: Number,
children: [
{
attr: '入院中'
value: number
attr: '入院中',
value: Number,
children: [
{
attr: '軽症・中等症'
value: number
attr: '軽症・中等症',
value: Number,
},
{
attr: '重症'
value: number
}
]
attr: '重症',
value: Number,
},
],
},
{
attr: '宿泊療養'
value: number
attr: '宿泊療養',
value: Number,
},
{
attr: '自宅療養'
value: number
attr: '自宅療養',
value: Number,
},
{
attr: '調査中'
value: number
attr: '調査中',
value: Number,
},
{
attr: '退院'
value: number
attr: '退院',
value: Number,
},
{
attr: '死亡'
value: number
}
]
}
]
attr: '死亡',
value: Number,
},
],
},
],
}

const ConfirmedCasesType: type = {
陽性者数: number
入院中: number
軽症中等症: number
重症: number
宿泊療養: number
自宅療養: number
調査中: number
死亡: number
退院: number
const ConfirmedCasesType = {
陽性者数: Number,
入院中: Number,
軽症中等症: Number,
重症: Number,
宿泊療養: Number,
自宅療養: Number,
調査中: Number,
死亡: Number,
退院: Number,
}

interface ChildData {
attr: string
value: number
const ChildData = {
attr: String,
value: Number,
}

const ChildDataType: type = {
attr?: string
value?: number
children?: ChildData[]
const ChildDataType = {
attr: String || null,
value: Number || null,
children: Array,
}

function getSelectedItem(data: DataType, key: string) {
let result: number | undefined
const recursiveSearch = (data: ChildDataType) => {
function getSelectedItem(data, key) {
let result = null
const recursiveSearch = (data) => {
if (result) {
return
}
if (data.attr === key) {
result = data.value
} else if (data.children) {
data.children.forEach((child: ChildDataType) => {
data.children.forEach((child) => {
if (result) {
return
}
Expand All @@ -93,7 +93,7 @@ function getSelectedItem(data: DataType, key: string) {
*
* @param data - Raw data
*/
export default (data: DataType) => {
export default (data) => {
return {
陽性者数: getSelectedItem(data, '陽性患者数'),
入院中: getSelectedItem(data, '入院中'),
Expand All @@ -104,5 +104,5 @@ export default (data: DataType) => {
調査中: getSelectedItem(data, '調査中'),
死亡: getSelectedItem(data, '死亡'),
退院: getSelectedItem(data, '退院'),
} as ConfirmedCasesType
}
}
88 changes: 42 additions & 46 deletions utils/formatConfirmedCasesAttributesTable.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const Header: type = {
text: string
value: string
align?: string
type?: 'date' | 'age'
const Header = {
text: String,
value: String,
align: String || null,
type: 'date' || 'age' || null,
}

const headers: Header[] = [
const headers = [
{ text: '公表日', value: '公表日', type: 'date' },
{ text: '居住地', value: '居住地' },
{ text: '年代', value: '年代', type: 'age' },
Expand All @@ -17,57 +17,53 @@ const headers: Header[] = [
{ text: '退院', value: '退院', align: 'center' },
]

export type DataType = {
公表_年月日: string
患者_居住地: string | undefined
患者_年代: string | undefined
患者_性別: '男性' | '女性' | string
患者_職業: string | undefined
患者_接触歴の有無フラグ: number | undefined
発症_年月日: string | undefined
確定_年月日: string | undefined
退院済フラグ: number | undefined
[key: string]: any
const DataType = {
公表_年月日: String,
患者_居住地: String || null,
患者_年代: String || null,
患者_性別: '男性' || '女性' || String || null,
患者_職業: String || null,
患者_接触歴の有無フラグ: Number || null,
発症_年月日: String || null,
確定_年月日: String || null,
退院済フラグ: Number || null,
}

const TableDataType: type = {
公表日: string
居住地: DataType['患者_居住地']
年代: DataType['患者_年代']
性別: DataType['患者_性別'] | '不明'
職業: DataType['患者_職業']
接触歴: string | undefined
発症日: DataType['発症_年月日']
確定日: DataType['確定_年月日']
退院: string | undefined
const TableDataType = {
公表日: String,
居住地: ['患者_居住地'],
年代: ['患者_年代'],
性別: ['患者_性別' || '不明'],
職業: ['患者_職業'],
接触歴: String || null,
発症日: ['発症_年月日'],
確定日: ['確定_年月日'],
退院: String || undefined,
}

export type TableDateType = {
headers: Header[]
datasets: TableDataType[]
export const TableDateType = {
headers: [Header],
datasets: {},
}

/**
* Format for DataTable component
*
* @param data - Raw data
*/
export function formatConfirmedCasesAttributesTable(
data: DataType[]
): TableDateType {
const datasets = data.map((d) => ({
公表日: d['公表_年月日'] ?? '不明',
居住地: d['患者_居住地'] ?? '調査中',
年代: d['患者_年代'] ?? '不明',
性別: d['患者_性別'] ?? '不明',
職業: d['患者_職業'] ?? '-',
接触歴: d['患者_接触歴の有無フラグ'] ? '〇' : '',
発症日: d['発症_年月日'] ?? '',
確定日: d['確定_年月日'] ?? '',
退院: d['退院済フラグ'] ? '〇' : '',
}))
export function formatConfirmedCasesAttributesTable(data) {
return {
headers,
datasets,
headers: [headers],
datasets: data.map((d) => {
const 公表日 = d['公表_年月日'] ?? '不明'
const 居住地 = d['患者_居住地'] ?? '調査中'
const 年代 = d['患者_年代'] ?? '不明'
const 性別 = d['患者_性別'] ?? '不明'
const 職業 = d['患者_職業'] ?? '-'
const 接触歴 = d['患者_接触歴の有無フラグ'] ? '〇' : ''
const 発症日 = d['発症_年月日'] ?? ''
const 確定日 = d['確定_年月日'] ?? ''
const 退院 = d['退院済フラグ'] ? '〇' : ''
}),
}
}

0 comments on commit c421400

Please sign in to comment.