Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

都道府県の表記を統一 #67

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Components/BarChart.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ output$regionTimeSeries <- renderEcharts4r({

totalConfirmedByRegionData <- reactive({
dt <- fread(paste0(DATA_PATH, 'resultSummaryTable.csv'), sep = '@')
dt[, region := list(fix_prefecture_str(region))]
dt
})

Expand Down
9 changes: 5 additions & 4 deletions Components/ComfiredMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# Returns:
# data.table: データセット
cumSumConfirmedByDateAndRegion <- reactive({
dt <- data.frame(date = byDate$date)
dt <- data.frame(date = byDate$date, stringsAsFactors = FALSE)
for(i in 2:ncol(byDate)) {
dt[, i] = cumsum(byDate[, i, with = F])
dt[, i] = cumsum(byDate[, i, with = FALSE])
}
dt <- reshape2::melt(dt, id.vars = 'date')
dt <- data.table(dt)
dt <- data.table(dt, stringsAsFactors = FALSE)
dt[, variable := as.character(variable)]
# input <- list(mapDateRange = c(as.Date('2020-03-01'), as.Date('2020-03-10')), showPopupOnMap = T) # TEST
dt <- dt[date >= input$mapDateRange[1] & date <= input$mapDateRange[2]]
dt
Expand All @@ -17,7 +18,7 @@ output$echartsMap <- renderEcharts4r({
mapDt <- cumSumConfirmedByDateAndRegion()
# mapDt <- data.table(dt) # TEST
mapDt <- mapDt[!(variable %in% c('クルーズ船', 'チャーター便', '検疫職員'))]
mapDt <- merge(x = mapDt, y = provinceCode, by.x = 'variable', by.y = 'name-ja', all = T)
mapDt <- merge(x = mapDt, y = provinceCode, by.x = 'variable', by.y = 'name-ja', all = TRUE)
mapDt <- mapDt[, .(date, variable, `name-en`, value)]
colnames(mapDt) <- c('date', 'ja', 'en', 'count')
nameMap <- as.list(mapDt$ja)
Expand Down
7,860 changes: 3,930 additions & 3,930 deletions Data/resultSignateDetail.csv

Large diffs are not rendered by default.

2,456 changes: 1,228 additions & 1,228 deletions Data/resultSignateLink.csv

Large diffs are not rendered by default.

96 changes: 48 additions & 48 deletions Data/resultSummaryTable.csv

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions R/fix_prefecture_str.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
is_prefecture <- function(x) {
sapply(x,
grepl,
x = "(?<=東京都|北海道|(大阪|京都)府|(青森|岩手|宮城|秋田|山形|福島|茨城|栃木|群馬|埼玉|千葉|神奈川|新潟|富山|石川|福井|山梨|長野|岐阜|静岡|愛知|三重|滋賀|兵庫|奈良|和歌山|鳥取|島根|岡山|広島|山口|徳島|香川|愛媛|高知|福岡|佐賀|長崎|熊本|大分|宮崎|鹿児島|沖縄)県)",
simplify = TRUE,
USE.NAMES = FALSE
)
}

fix_prefecture_str <- function(x) {
x %>%
sapply(
function(x) {
if (is_prefecture(x)) {
if (grepl(x, "^京都")) {
"京都府"
} else {
prefecture_set <-
c("北海道", "青森県", "岩手県", "宮城県", "秋田県",
"山形県", "福島県", "茨城県", "栃木県", "群馬県",
"埼玉県", "千葉県", "東京都", "神奈川県", "新潟県",
"富山県", "石川県", "福井県", "山梨県", "長野県",
"岐阜県", "静岡県", "愛知県", "三重県", "滋賀県",
"京都府", "大阪府", "兵庫県", "奈良県", "和歌山県",
"鳥取県", "島根県", "岡山県", "広島県", "山口県",
"徳島県", "香川県", "愛媛県", "高知県", "福岡県",
"佐賀県", "長崎県", "熊本県", "大分県", "宮崎県",
"鹿児島県", "沖縄県")
str_dist <-
adist(x,
prefecture_set) %>%
c()
if (length(unique(str_dist)) == 1) {
x
} else {
prefecture_set[which.min(str_dist)]
}
}
} else {
x
}
},
simplify = TRUE,
USE.NAMES = FALSE)
}

set_prefecture_fullnames <- function(data) {
data %>%
setNames(fix_prefecture_str(names(data)))
}
29 changes: 17 additions & 12 deletions System/CreateTable.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
library(magrittr)
library(data.table)
library(sparkline)
source("R/fix_prefecture_str.R")

# ====準備部分====
DATA_PATH <- 'Data/'
# 感染者ソーステーブルを取得
byDate <- fread(paste0(DATA_PATH, 'byDate.csv'), header = T)
byDate <- fread(paste0(DATA_PATH, 'byDate.csv'), header = TRUE) %>%
set_prefecture_fullnames()
byDate[is.na(byDate)] <- 0
byDate$date <- lapply(byDate[, 1], function(x){as.Date(as.character(x), format = '%Y%m%d')})
# 死亡データ
death <- fread(paste0(DATA_PATH, 'death.csv'))
death <- fread(paste0(DATA_PATH, 'death.csv')) %>%
set_prefecture_fullnames()
death[is.na(death)] <- 0
# 国内の日報
domesticDailyReport <- fread(paste0(DATA_PATH, 'domesticDailyReport.csv'))
Expand All @@ -35,9 +39,9 @@ langCode <- 'ja'
# 都道府県人口密度
provinceAttr <- fread(paste0(DATA_PATH, 'SIGNATE COVID-2019 Dataset - 都道府県マスタ.csv'))
provinceAttr$人口 <- as.numeric(gsub(',', '', provinceAttr$人口))
provinceAttr[, `都道府県` := gsub('県', '', `都道府県`)]
provinceAttr[, `都道府県` := gsub('府', '', `都道府県`)]
provinceAttr[, `都道府県` := gsub('東京都', '東京', `都道府県`)]
# provinceAttr[, `都道府県` := gsub('県', '', `都道府県`)]
# provinceAttr[, `都道府県` := gsub('府', '', `都道府県`)]
# provinceAttr[, `都道府県` := gsub('東京都', '東京', `都道府県`)]
# 色設定
lightRed <- '#F56954'
middleRed <- '#DD4B39'
Expand Down Expand Up @@ -112,9 +116,9 @@ diffSparkline <- sapply(2:ncol(byDate), function(i) {
# 新規退院者カラム作成
detailByRegion <- fread(paste0(DATA_PATH, 'detailByRegion.csv'))
detailByRegion[, `日付` := as.Date(as.character(`日付`), '%Y%m%d')]
detailByRegion[, `都道府県名` := gsub('県', '', `都道府県名`)]
detailByRegion[, `都道府県名` := gsub('府', '', `都道府県名`)]
detailByRegion[, `都道府県名` := gsub('東京都', '東京', `都道府県名`)]
# detailByRegion[, `都道府県名` := gsub('県', '', `都道府県名`)]
# detailByRegion[, `都道府県名` := gsub('府', '', `都道府県名`)]
# detailByRegion[, `都道府県名` := gsub('東京都', '東京', `都道府県名`)]
detailByRegion[order(`日付`), dischargedDiff := `退院者` - shift(`退院者`), by = `都道府県名`]
detailByRegion[is.na(detailByRegion)] <- 0

Expand Down Expand Up @@ -283,13 +287,14 @@ fwrite(x = processData, file = paste0(DATA_PATH, 'resultProcessData.csv'))

# =====SIGNATE データ処理=====
provinceCode <- fread(paste0(DATA_PATH, 'prefectures.csv'))
provinceCode[, `name-ja` := list(fix_prefecture_str(`name-ja`))]
# svgIcon <- fread(paste0(DATA_PATH, 'svg.csv'))
# clusterPlace<- fread(paste0(DATA_PATH, 'SIGNATE COVID-2019 Dataset - 接触場所マスタ.csv'), header = T)

signateDetail<- fread(paste0(DATA_PATH, 'SIGNATE COVID-2019 Dataset - 罹患者.csv'), header = T)
signateDetail[, 受診都道府県 := gsub('県', '', 受診都道府県)]
signateDetail[, 受診都道府県 := gsub('府', '', 受診都道府県)]
signateDetail[, 受診都道府県 := gsub('東京都', '東京', 受診都道府県)]
signateDetail<- fread(paste0(DATA_PATH, '/SIGNATE COVID-2019 Dataset - 罹患者.csv'), header = T)
# signateDetail[, 受診都道府県 := gsub('県', '', 受診都道府県)]
# signateDetail[, 受診都道府県 := gsub('府', '', 受診都道府県)]
# signateDetail[, 受診都道府県 := gsub('東京都', '東京', 受診都道府県)]
signateDetail[, regionId := paste0(都道府県コード, '-', 都道府県別罹患者No)]

# 年代変換
Expand Down
10 changes: 8 additions & 2 deletions global.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ library(echarts4r)
library(echarts4r.maps)
library(sparkline)
library(shinyBS)
source("R/fix_prefecture_str.R")

# ====
# ファイルのパス設定
Expand All @@ -33,12 +34,14 @@ getFinalAndDiff <- function(vector) {
# ====
# データの読み込み
# ====
byDate <- fread(paste0(DATA_PATH, 'byDate.csv'), header = T)
byDate <- fread(paste0(DATA_PATH, 'byDate.csv'), header = T) %>%
set_prefecture_fullnames()
byDate[is.na(byDate)] <- 0
byDate$date <- lapply(byDate[, 1], function(x){as.Date(as.character(x), format = '%Y%m%d')})

# 死亡データ
death <- fread(paste0(DATA_PATH, 'death.csv'))
death <- fread(paste0(DATA_PATH, 'death.csv')) %>%
set_prefecture_fullnames()
death[is.na(death)] <- 0

# 行動歴データ
Expand Down Expand Up @@ -215,8 +218,11 @@ regionName <- as.list(regionName)


news <- fread(paste0(DATA_PATH, 'mhlw_houdou.csv'))
news[ , pre := list(fix_prefecture_str(pre))]


provinceCode <- fread(paste0(DATA_PATH, 'prefectures.csv'))
provinceCode[, `name-ja` := list(fix_prefecture_str(`name-ja`))]
provinceSelector <- provinceCode$id
names(provinceSelector) <- provinceCode$`name-ja`

Expand Down