Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
v0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo2011 committed Mar 5, 2022
1 parent ecb0e2d commit 88f186a
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Confirm-Datas-Tests.html
covids.json
COVIDs.json
__pycache__/
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 中国疫情地图版本0.2.1 [修订]

- 1. [Pre] 城市查看功能。
- 2. [Optimize] 优化界面。

## 中国疫情地图版本0.2.0 [更新]

- 1. [Pre] 添加了主程序主题逻辑。
Expand Down
38 changes: 37 additions & 1 deletion covids.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
url = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&callback=&_=%d'%int(time.time()*1000)
r = requests.get(url=url)
data = json.loads(r.json()['data'])
json.dump(data, open("covids.json", "w"), indent=4)
json.dump(data, open("COVIDs.json", "w"), indent=4)
except:
print("Loading datas error. Please check your Internet. ")
sys.exit()
Expand All @@ -27,6 +27,16 @@
total_lst.append(area_confirm)
total_dead.append(area_dead)
total_dict[area_name] = [area_confirm, area_dead, area_heal]
"""
maxn = 0
a = ""
for d in data['areaTree'][0]['children']:
if len(d['children']) > maxn:
maxn = len(d['children'])
a = d['name']
print(maxn)
print(a)
"""
def get_key(obj, dct):
for key in dct:
if dct[key][0] == obj:
Expand All @@ -38,6 +48,30 @@ def get_key(obj, dct):
areas.append(get_key(num, total_dict))
new_dead.append(total_dict[get_key(num, total_dict)][1])
new_heal.append(total_dict[get_key(num, total_dict)][2])
cities = {}
for area in areas:
cities_data = []
for index, cs in enumerate(data['areaTree'][0]['children']):
if cs['name'] == area:
cities_data = (data['areaTree'][0]['children'][index]['children'])
new_data = {}
for city in cities_data:
name = city['name']
new_data[city['name']] = [city['total']['confirm'], city['total']['heal'], city['total']['dead']]
sort_data = {}
for key in new_data:
if key == "地区待确认":
sort_data[key] = new_data[key]
elif key == "境外输入":
sort_data[key] = new_data[key]
elif key.count("境外") == 1:
sort_data[key] = new_data[key]
elif key.count("外地") == 1:
sort_data[key] = new_data[key]
for key in new_data:
if not key in sort_data.keys():
sort_data[key] = new_data[key]
cities[area] = sort_data
total_lst = total_lst[::-1]
new_dead = new_dead[::-1]
new_heal = new_heal[::-1]
Expand All @@ -52,6 +86,8 @@ def get_key(obj, dct):
CONFIRM_SORT = total_lst
DEAD_SORT = new_dead
HEAL_SORT = new_heal
CITIES = cities
AREAS = areas

if __name__ == '__main__':
from plotly import offline
Expand Down
33 changes: 25 additions & 8 deletions map.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cv2
import numpy as np
from PIL import Image, ImageDraw, ImageFont
from covids import CHINA_TOTAL, CHINA_HEAL, CHINA_DEAD, CONFIRM_SORT, HEAL_SORT, DEAD_SORT
from covids import CHINA_TOTAL, CHINA_HEAL, CHINA_DEAD, CONFIRM_SORT, HEAL_SORT, DEAD_SORT, AREAS
from posits import COLORS, POS

def paint_chinese_opencv(im, chinese, pos, color, size):
Expand All @@ -24,8 +24,9 @@ def paint_chinese_opencv(im, chinese, pos, color, size):
select = ""
point = [0, 0]
evt = 0
select_asked = False
while True:
def mousecallback(event, x, y, flags, param):
def mousecallback(event, x, y, *args):
global point, evt
if event == cv2.EVENT_LBUTTONUP or event == cv2.EVENT_RBUTTONDOWN:
point = [x, y]
Expand All @@ -38,10 +39,19 @@ def mousecallback(event, x, y, flags, param):
points = POS[area]
mousepos = point
if mousepos in points:
select = area
if not select_asked:
select = area
if not select_asked and evt == 1:
select = area
select_asked = True
if select_asked and evt == 1:
select = area
flag = True
if not flag:
select = ""
if not select_asked:
select = ""
if select_asked and evt == 1:
select_asked = False
if point[0] >= 10 and point[0] <= 60 and point[1] >= 323 and point[1] <= 373 and evt == 1:
break
frame = cv2.imread("map_background.png")
Expand All @@ -53,10 +63,17 @@ def mousecallback(event, x, y, flags, param):
cv2.rectangle(frame, pos, pos, [125, 125, 125], thickness=1)
cv2.rectangle(frame, (35, 348), (35, 348), (0, 0, 0), 50)
frame = paint_chinese_opencv(frame, "退出", (16, 338), (255, 255, 255), 20)
cv2.rectangle(frame, (440, 190), (590, 225), (0, 0, 0), 2)
state_string = f"中国:\n确诊{CHINA_TOTAL}人"
frame = paint_chinese_opencv(frame, state_string, (445, 130), (0, 0, 0), 20)
frame = paint_chinese_opencv(frame, "已选择:" + select, (445, 200), (0, 0, 0), 20)
if not select_asked:
state_string = f" 中国:\n确诊{CHINA_TOTAL}人,\n治愈{CHINA_HEAL}人,\n死亡{CHINA_DEAD}人"
frame = paint_chinese_opencv(frame, state_string, (445, 130), (0, 0, 0), 20)
cv2.rectangle(frame, (440, 240), (590, 280), (0, 0, 0), 2)
frame = paint_chinese_opencv(frame, "已选择:" + select, (445, 250), (0, 0, 0), 20)
else:
state_string = f" {select}\n确诊{CONFIRM_SORT[AREAS.index(select)]}人,\n治愈{HEAL_SORT[AREAS.index(select)]}人,\n死亡{DEAD_SORT[AREAS.index(select)]}人"
frame = paint_chinese_opencv(frame, state_string, (445, 130), (0, 0, 0), 20)
area = select
cv2.rectangle(frame, (440, 235), (590, 255), [COLORS[area][2], COLORS[area][1], COLORS[area][0]], 2)
frame = paint_chinese_opencv(frame, " 详细信息", (445, 245),(0, 0, 0), 20)
cv2.setMouseCallback('COVID-19 Map of China', mousecallback)
cv2.namedWindow('COVID-19 Map of China', 0)
cv2.imshow('COVID-19 Map of China', frame)
Expand Down
68 changes: 34 additions & 34 deletions posits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@
import numpy

COLORS = {
"湖北":(133, 133, 208),
"湖南":(0, 168, 243),
"河北":(255, 210, 225),
"河南":(203, 124, 124),
"广西":(190, 33, 15),
"广东":(0, 0, 0),
"内蒙古":(14, 209, 69),
"新疆":(255, 242, 0),
"西藏":(184, 61, 186),
"宁夏":(136, 0, 27),
"福建":(129, 156, 173),
"吉林":(162, 82, 157),
"安徽":(211, 200, 248),
"浙江":(151, 209, 246),
"云南":(216, 227, 228),
"贵州":(255, 202, 24),
"辽宁":(116, 91, 118),
"黑龙江":(241, 114, 250),
"四川":(97, 109, 169),
"青海":(140, 255, 251),
"甘肃":(255, 127, 39),
"山西":(220, 186, 186),
"陕西":(88, 88, 88),
"山东":(1, 171, 157),
"海南":(63, 72, 204),
"台湾":(196, 255, 14),
"香港":(255, 174, 200),
"澳门":(90, 49, 127),
"江苏":(133, 246, 186),
"北京":(236, 28, 36),
"天津":(177, 162, 92),
"上海":(192, 153, 94),
"重庆":(82, 39, 34),
"江西":(252, 121, 121)
"湖北":(133, 133, 208),
"湖南":(0, 168, 243),
"河北":(255, 210, 225),
"河南":(203, 124, 124),
"广西":(190, 33, 15),
"广东":(0, 0, 0),
"内蒙古":(14, 209, 69),
"新疆":(255, 242, 0),
"西藏":(184, 61, 186),
"宁夏":(136, 0, 27),
"福建":(129, 156, 173),
"吉林":(162, 82, 157),
"安徽":(211, 200, 248),
"浙江":(151, 209, 246),
"云南":(216, 227, 228),
"贵州":(255, 202, 24),
"辽宁":(116, 91, 118),
"黑龙江":(241, 114, 250),
"四川":(97, 109, 169),
"青海":(140, 255, 251),
"甘肃":(255, 127, 39),
"山西":(220, 186, 186),
"陕西":(88, 88, 88),
"山东":(1, 171, 157),
"海南":(63, 72, 204),
"台湾":(196, 255, 14),
"香港":(255, 174, 200),
"澳门":(90, 49, 127),
"江苏":(133, 246, 186),
"北京":(236, 28, 36),
"天津":(177, 162, 92),
"上海":(192, 153, 94),
"重庆":(82, 39, 34),
"江西":(252, 121, 121)
}

POS = {
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# 中国疫情地图 COVID-19-MAP-CHINA

版本0.2.0(预发布)
版本0.2.1(预发布)

## Overview 预览

中国疫情一览地图。采用可视化设计,分为三个等级,一览感染人数、死亡人数等信息。
中国疫情一览地图。采用可视化设计,分为五个等级,一览感染人数、死亡人数等信息。

## Usage 用法

Expand Down
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@ numpy >= 1.1.0
opencv-python >= 4.0.0
pillow >= 8.0.0
requests >= 2.0.0
1
3
1
14
13
8
10
14

0 comments on commit 88f186a

Please sign in to comment.