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

Commit

Permalink
Merge pull request #56 from nishidayoshikatsu/hotfix/53-build_error
Browse files Browse the repository at this point in the history
buildエラーを修正
  • Loading branch information
nisshi-dev authored Jan 14, 2022
2 parents 2072e3c + fa2d9bb commit 82ccbf4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# covid19-yamaguchi-opendata

[![Deploy JSON Files](https://github.com/nishidayoshikatsu/covid19-yamaguchi-opendata/actions/workflows/deploy_json.yml/badge.svg)](https://github.com/nishidayoshikatsu/covid19-yamaguchi-opendata/actions/workflows/deploy_json.yml)

[![pages-build-deployment](https://github.com/nishidayoshikatsu/covid19-yamaguchi-opendata/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/nishidayoshikatsu/covid19-yamaguchi-opendata/actions/workflows/pages/pages-build-deployment)
## What is this

[山口県オープンデータカタログサイト](https://yamaguchi-opendata.jp/www/index.html)に掲載されている[新型コロナウイルス感染症の山口県内での発生状況](https://yamaguchi-opendata.jp/ckan/dataset/f6e5cff9-ae43-4cd9-a398-085187277edf)のデータをjsonとして出力するPythonスクリプトです
Expand Down
43 changes: 30 additions & 13 deletions dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,19 @@ def generate_patients(self, origin_directory='origin_data/', out_directory='data
dic["居住地"] = dic.pop("市区町村名")
dic["年代"] = dic.pop("患者_年代")
dic["性別"] = dic.pop("患者_性別")
dic["公表日"] = self.format_date(dic["公表日"]) + "T08:00:00.000Z"
dic["陽性確定日"] = self.format_date(dic["陽性確定日"]) + "T08:00:00.000Z"
#TODO: 例外処理ちゃんとかく
try:
dic["公表日"] = self.format_date(dic["公表日"]) + "T08:00:00.000Z"
except Exception as e:
print("公表日未検出")
dic["公表日"] = dic["公表日"]
pass
try:
dic["陽性確定日"] = self.format_date(dic["陽性確定日"]) + "T08:00:00.000Z"
except Exception as e:
print(str(e) + '陽性確定日未検出')
dic["陽性確定日"] = dic["陽性確定日"]
pass
del_list = ['都道府県名', '全国地方公共団体コード']
[dic.pop(d) for d in del_list]
out.append(dic)
Expand Down Expand Up @@ -289,7 +300,7 @@ def generate_querents(self, origin_directory='origin_data/', out_directory='data
json.dump(prev_data, f, ensure_ascii=False, indent=4, separators=(',', ': '))

def generate_maps(self, origin_directory='origin_data/', out_directory='data/'):

with open(origin_directory + "patients.json", encoding='utf-8') as f:
data = json.load(f)
city_list = [
Expand All @@ -306,13 +317,13 @@ def generate_maps(self, origin_directory='origin_data/', out_directory='data/'):
for key in city_dict.keys():
if city_dict[key] == 0:
color_dict[key] = "white"
elif city_dict[key] <= 50:
elif city_dict[key] <= 200:
color_dict[key] = "#DCF8DC"
elif city_dict[key] <= 100:
elif city_dict[key] <= 400:
color_dict[key] = "#95EA95"
elif city_dict[key] <= 150:
elif city_dict[key] <= 600:
color_dict[key] = "#2BD52B"
elif color_dict[key] <= 200:
elif color_dict[key] <= 800:
color_dict[key] = "#1D8D1D"
else:
color_dict[key] = "#0E470E"
Expand Down Expand Up @@ -388,9 +399,9 @@ def generate_maps(self, origin_directory='origin_data/', out_directory='data/'):
for i,heat in enumerate(heat_colorlist):
base.add_patch(patches.Rectangle(xy=(131.83, 35.12-i*0.1), width=0.25, height=0.1, fc=heat, ec="black", fill=True))
if i == 4:
base.text(132.09, 35.05-i*0.1+0.1, "・・・"+str(50*i+1)+"以上")
base.text(132.09, 35.05-i*0.1+0.1, "・・・"+str(200*i+1)+"以上")
else:
base.text(132.09, 35.05-i*0.1+0.1, "・・・"+str(50*i+1)+"-"+str(50*(i+1)))
base.text(132.09, 35.05-i*0.1+0.1, "・・・"+str(200*i+1)+"-"+str(200*(i+1)))

plt.savefig(out_directory+"yamaguchi-map.png", bbox_inches='tight')
#plt.show()
Expand Down Expand Up @@ -430,11 +441,14 @@ def interpolate_year(self, datestr):
return "2021/" + datestr

def format_date(self, date_str):
date_str = self.interpolate_year(date_str)
#print(datetime.datetime.now(datetime.timezone(datetime.timedelta(hours=+9), "JST")).isoformat())
date_dt = datetime.datetime.strptime(date_str, "%Y/%m/%d")
try:
date_str = self.interpolate_year(date_str)
#print(datetime.datetime.now(datetime.timezone(datetime.timedelta(hours=+9), "JST")).isoformat())
date_dt = datetime.datetime.strptime(date_str, "%Y/%m/%d")

return date_dt.strftime("%Y-%m-%d")
return date_dt.strftime("%Y-%m-%d")
except Exception:
raise

def format_date2(self, date_str):
#print(datetime.datetime.now(datetime.timezone(datetime.timedelta(hours=+9), "JST")).isoformat())
Expand Down Expand Up @@ -492,6 +506,9 @@ def daily_patients(self, data):
date_list = []
for d in data:
date_str = d.get("公表日")
#TODO: 例外処理周りちゃんとかく
if date_str == '欠番':
continue
dt = self.format_date(date_str)
dt = datetime.date(int(dt[:4]), int(dt[5:7]), int(dt[8:10]))
if '欠番' not in d.get('備考'):
Expand Down

0 comments on commit 82ccbf4

Please sign in to comment.