用java和python進行疫情分析,分析治癒率

 

 

數據 通過rest接口https://c.m.163.com/ug/api/wuhan/app/data/list-total?t=1582418617382 可以獲得。

將獲得的json數據存成data.json文件。json文件格式很容易找到自己需要的數據,該數據比較全。 

pom文件中加依賴jar

   <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.5.3</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.5.3</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.5.3</version>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.8</version>
        </dependency>

 編寫數據項代碼


import java.text.DecimalFormat;

/**
 * Created by zhangxp on 2020/2/23.
 */
public class DataItem implements Comparable<DataItem>{
    public  String name;
    public  int confirm;
    public int suspect;
    public int heal;
    public int dead;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getConfirm() {
        return confirm>0?confirm:1;
    }

    public void setConfirm(int confirm) {
        this.confirm = confirm;
    }

    public int getSuspect() {
        return suspect;
    }

    public void setSuspect(int suspect) {
        this.suspect = suspect;
    }

    public int getHeal() {
        return heal;
    }

    public void setHeal(int heal) {
        this.heal = heal;
    }

    public int getDead() {
        return dead;
    }

    public void setDead(int dead) {
        this.dead = dead;
    }

    public int compareTo(DataItem o) {
        return confirm-o.confirm;
    }
    public String toLine(){
        StringBuilder sb=new StringBuilder();
        sb.append(name);
        sb.append("\t"+confirm);
        sb.append("\t"+suspect);
        sb.append("\t"+heal);
        sb.append("\t"+dead);
        double d=heal*1.0/getConfirm();
        DecimalFormat df = new DecimalFormat("#.##%");
        String str = df.format(d);
        sb.append("\t"+str);
        return sb.toString();
    }
}

編寫json分析代碼


import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.*;
import java.util.*;
import java.util.regex.Pattern;

/**
 * Created by zhangxp on 2020/2/23.
 */
public class DataAnalysis {
   static final  String bitcities[]={"北京","上海","廣州","深圳"};
   static class SortByKey implements Comparator<DataItem>{
       public int compare(DataItem o1, DataItem o2) {
           // TODO Auto-generated method stub
              int ix=0;
               double age1 = o1.getHeal() * 1.0 / o1.getConfirm();
               double age2 = o2.getHeal() * 1.0 / o2.getConfirm();
               ix = age1 < age2 ? 1 : (age1 == age2 ? 0 : -1);
               int tt = ix;
               if (ix == 0) {
                   int iy=o2.confirm-o1.confirm;
                   tt =(iy>0)?1:(iy==0?0:-1);
               }

           return tt;

       }
    }
    public static boolean  isBigCity(String name){
      List<String> lst= Arrays.asList(bitcities);
      return lst.contains(name);
    }
    public static void main(String[] args) {
        String path="data.json";
       String json=readToString(path);
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            Map<String,Object> aa=objectMapper.readValue(json, LinkedHashMap.class);
            Map<String,Object> ab=(Map<String,Object>)readPath(aa,"data.areaTree.0");
            String name=(String)readPath(ab,"name");
            List<Object> shenlst=(List)readPath(ab,"children");
           // System.out.println("aaa: "+ ab);
            List<DataItem> lst=new ArrayList<DataItem>() ;
            List<DataItem> citylst=new ArrayList<DataItem>() ;
            List<DataItem> bigcitylst=new ArrayList<DataItem>();
            for(Object ob:shenlst){
                Map ma=(Map)ob;
                DataItem item=getfromMap(ma);
                lst.add(item);
                if(isBigCity(item.name)){
                    bigcitylst.add(item);
                }
                List<Object> shenlst2=(List)readPath(ma,"children");
                for(Object ob2:shenlst2) {
                    Map ma2 = (Map) ob2;
                    DataItem item2=getfromMap(ma2);
                    citylst.add(item2);
                    if(isBigCity(item2.name)){
                        bigcitylst.add(item2);
                    }
                }
            }
            SortByKey sbk=new SortByKey();
            Collections.sort(lst,sbk);
            outputData(lst);
            System.out.println("=======bigcity==========");
            Collections.sort(bigcitylst,sbk);
            outputData(bigcitylst);
            System.out.println("=======city==========");
            Collections.sort(citylst,sbk);
            outputData(citylst);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void outputData( List<DataItem> lst){
       // System.out.println("place  confirm   suspect  heal  dead  healrate");
        System.out.println("地方  確診 疑似  治癒  死亡 治癒率");
        for(DataItem di:lst){
            System.out.println(di.toLine());
        }
    }
    public static DataItem getfromMap(Map mo){
        DataItem item=new DataItem();
        item.setName((String)mo.get("name"));
        Map mt=(Map)mo.get("total");
        item.setConfirm(readPathInt(mt,"confirm"));
        item.setSuspect(readPathInt(mt,"suspect"));
        item.setHeal(readPathInt(mt,"heal"));
        item.setDead(readPathInt(mt,"dead"));
        return item;
    }
    public static  int readPathInt(Map mo,String path)
    {
       int ires=-1;
        Integer sd=(Integer)readPath(mo,path);

        return sd.intValue();
    }
    public static Object readPath(Map mo,String path){
        String fields[]=path.split("\\.");
        Object ob=mo;
        Map m1=null;
        List a1=null;
        for(String fd : fields){
            if( ob instanceof  Map){
                m1=(Map) ob;
                ob=m1.get(fd);
            }else if( ob instanceof  List){
                a1=(List) ob;
                if(isNumber(fd)){
                    int index=Integer.parseInt(fd.trim());
                    ob=a1.get(index);
                }else {

                }
            }

        }
      return ob;
    }
    public static boolean isNumber(String str){
        Pattern pattern = Pattern.compile("[0-9]*");
        return pattern.matcher(str).matches();
    }
    public static String readToString(String fileName) {
        String encoding = "UTF-8";
        File file = new File(fileName);
        Long filelength = file.length();
        byte[] filecontent = new byte[filelength.intValue()];
        try {
            FileInputStream in = new FileInputStream(file);
            in.read(filecontent);
            in.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            return new String(filecontent, encoding);
        } catch (UnsupportedEncodingException e) {
            System.err.println("The OS does not support " + encoding);
            e.printStackTrace();
            return null;
        }
    }

分析結果,截止2020-02-23 08:39:23各省的治癒率

地方  確診 疑似  治癒  死亡 治癒率
青海	18	0	18	0	100%
西藏	1	0	1	0	100%
甘肅	91	0	76	2	83.52%
寧夏	71	0	56	0	78.87%
上海	335	0	249	3	74.33%
河北	311	0	219	6	70.42%
湖南	1016	0	710	4	69.88%
貴州	146	0	102	2	69.86%
河南	1271	0	867	19	68.21%
山西	132	0	89	0	67.42%
陝西	245	0	163	1	66.53%
江蘇	631	0	418	0	66.24%
雲南	174	0	115	2	66.09%
江西	934	0	613	1	65.63%
安徽	989	0	637	6	64.41%
海南	168	0	106	4	63.1%
浙江	1205	0	758	1	62.9%
遼寧	121	0	73	1	60.33%
天津	135	0	81	3	60%
澳門	10	0	6	0	60%
吉林	91	0	54	1	59.34%
福建	293	0	170	1	58.02%
重慶	573	0	328	6	57.24%
廣東	1342	0	755	6	56.26%
四川	526	0	260	3	49.43%
北京	399	0	189	4	47.37%
黑龍江	480	0	217	12	45.21%
山東	754	0	320	4	42.44%
廣西	249	0	105	2	42.17%
內蒙古	75	0	27	0	36%
新疆	76	0	25	2	32.89%
湖北	64084	0	15340	2346	23.94%
香港	74	0	11	2	14.86%
臺灣	28	0	2	1	7.14%

各個城市的治癒率

=======city==========
地方  確診 疑似  治癒  死亡 治癒率
未明確地區	0	0	180	4	18000%
未明確地區	0	0	16	2	1600%
未明確地區	0	0	12	5	1200%
未明確地區	0	0	11	0	1100%
未明確地區	0	0	8	0	800%
未明確地區	0	0	2	0	200%
瀋陽	28	0	33	0	117.86%
攀枝花	16	0	16	0	100%
佳木斯	15	0	15	0	100%
西寧	15	0	15	0	100%
天水	12	0	12	0	100%
銅仁	10	0	10	0	100%
湘西自治州	8	0	8	0	100%
衡水	8	1	8	0	100%
延安	8	0	8	0	100%
承德	7	0	7	0	100%
麗江	7	0	7	0	100%
廣元	6	0	6	0	100%
呂梁	6	0	6	0	100%
張家界	5	0	5	0	100%
青浦	5	0	5	0	100%
梧州	5	0	5	0	100%
吉林	5	0	5	0	100%
梁平區	4	0	4	0	100%
普洱	4	0	4	0	100%
楚雄	4	0	4	0	100%
陵水	4	0	4	0	100%
黔西南州	4	0	4	0	100%
西青	4	0	4	0	100%
隴南	4	0	4	0	100%
榆林	3	0	3	0	100%
文昌	3	0	3	0	100%
本溪	3	0	3	0	100%
遼陽	3	0	3	0	100%
臨夏	3	0	3	0	100%
中衛	3	0	3	0	100%
海北州	3	0	3	0	100%
黔江	2	0	2	0	100%
城口縣	2	0	2	0	100%
大興安嶺	2	0	2	0	100%
樂東	2	0	2	0	100%
紅橋	2	0	2	0	100%
張掖	2	0	2	0	100%
松原	2	0	2	0	100%
武隆區	1	0	1	0	100%
秀山縣	1	0	1	0	100%
阿壩州	1	0	1	0	100%
韓城市	1	0	1	0	100%
臨滄	1	0	1	0	100%
瓊中縣	1	0	1	0	100%
津南	1	0	1	0	100%
營口	1	0	1	0	100%
金昌	1	0	1	0	100%
梅河口	1	0	1	0	100%
阿克蘇	1	0	1	0	100%
兵團第七師	1	0	1	0	100%
石嘴山	1	0	1	0	100%
寧東	1	0	1	0	100%
拉薩	1	0	1	0	100%
懷化	40	0	38	0	95%
長寧	13	0	12	0	92.31%
神農架林區	11	0	10	0	90.91%
保定	32	0	29	0	90.62%
廊坊	30	0	27	0	90%
臨沂	49	0	44	0	89.8%
運城	19	0	17	0	89.47%
定西	9	0	8	0	88.89%
益陽	59	0	52	0	88.14%
邵陽	102	0	88	1	86.27%
永州	43	0	37	0	86.05%
忠縣	21	0	18	0	85.71%
三門峽	7	0	6	1	85.71%
大渡口區	7	0	6	0	85.71%
丹東	7	0	6	0	85.71%
銀川	33	0	28	0	84.85%
寶雞	13	0	11	0	84.62%
大理	13	0	11	0	84.62%
閔行	19	0	16	0	84.21%
汕頭	25	0	21	0	84%
徐州	79	0	66	0	83.54%
駐馬店	139	0	116	0	83.45%
菏澤	18	0	15	0	83.33%
徐匯	18	0	15	0	83.33%
清遠	12	0	10	0	83.33%
鎮江	12	0	10	0	83.33%
河北	12	0	10	0	83.33%
邢臺	23	0	19	1	82.61%
張家口	34	0	28	0	82.35%
麗水	17	0	14	0	82.35%
咸陽	17	0	14	0	82.35%
蕪湖	33	0	27	0	81.82%
邯鄲	32	0	26	0	81.25%
蘭州	36	0	29	2	80.56%
浦東新區	60	0	48	0	80%
南通	40	0	32	0	80%
西雙版納	15	0	12	1	80%
儋州	15	0	12	0	80%
黔東南州	10	0	8	0	80%
永川	5	0	4	0	80%
鶴崗	5	0	4	0	80%
延邊	5	0	4	0	80%
郴州	39	0	31	0	79.49%
杭州	169	0	133	0	78.7%
安慶	83	0	65	0	78.31%
璧山區	9	0	7	0	77.78%
自貢	9	0	7	0	77.78%
南昌	229	0	178	0	77.73%
衡陽	48	0	37	0	77.08%
寧德	26	0	20	0	76.92%
陽江	13	0	10	0	76.92%
開州	21	0	16	1	76.19%
雲陽縣	25	0	19	0	76%
棗莊	24	0	18	0	75%
渝中	20	0	15	0	75%
太原	20	0	15	0	75%
靜安	16	0	12	0	75%
錦州	12	0	9	0	75%
眉山	8	0	6	0	75%
欽州	8	0	6	0	75%
銅川	8	0	6	0	75%
甘南	8	0	6	0	75%
江津	4	0	3	0	75%
河西	4	0	3	0	75%
陽泉	4	0	3	0	75%
白銀	4	0	3	0	75%
昌吉州	4	0	3	0	75%
商丘	91	0	68	3	74.73%
福州	71	0	53	1	74.65%
常德	82	0	61	0	74.39%
中山	66	0	49	0	74.24%
惠州	62	0	46	0	74.19%
亳州	108	0	80	0	74.07%
鹽城	27	0	20	0	74.07%
揚州	23	0	17	0	73.91%
南陽	155	0	114	3	73.55%
濱州	15	0	11	0	73.33%
石柱縣	15	0	11	0	73.33%
新餘	130	0	95	0	73.08%
外地來滬	111	0	81	0	72.97%
普陀	11	0	8	0	72.73%
平頂山	58	0	42	1	72.41%
石家莊	29	0	21	0	72.41%
上饒	123	0	88	0	71.54%
衢州	14	0	10	0	71.43%
松江	14	0	10	0	71.43%
虹口	7	0	5	0	71.43%
商洛	7	0	5	0	71.43%
婁底	76	0	54	0	71.05%
金華	55	0	39	0	70.91%
無錫	55	0	39	0	70.91%
常州	51	0	36	0	70.59%
黔南州	17	0	12	0	70.59%
漳州	20	0	14	0	70%
湖州	10	0	7	0	70%
六盤水	10	0	7	1	70%
安陽	53	0	37	0	69.81%
寧波	157	0	109	0	69.43%
宿遷	13	0	9	0	69.23%
曲靖	13	0	9	0	69.23%
萬寧	13	0	9	0	69.23%
梅州	16	0	11	0	68.75%
宜春	106	0	72	0	67.92%
泰州	37	0	25	0	67.57%
西安	120	0	81	1	67.5%
台州	146	0	98	0	67.12%
許昌	39	0	26	0	66.67%
廣安	30	0	20	0	66.67%
宜賓	12	0	8	0	66.67%
大同	12	0	8	0	66.67%
黃山	9	0	6	0	66.67%
楊浦	9	0	6	0	66.67%
嘉定	9	0	6	0	66.67%
澄邁縣	9	0	6	1	66.67%
平涼	9	0	6	0	66.67%
宣城	6	0	4	0	66.67%
黃浦	6	0	4	0	66.67%
龍巖	6	0	4	0	66.67%
瓊海	6	0	4	1	66.67%
臨高縣	6	0	4	0	66.67%
外地來津	6	0	4	0	66.67%
和平	6	0	4	0	66.67%
樂山	3	0	2	0	66.67%
資陽	3	0	2	0	66.67%
金山	3	0	2	0	66.67%
百色	3	0	2	0	66.67%
東方	3	0	2	0	66.67%
定安縣	3	0	2	1	66.67%
濱海新區	3	0	2	0	66.67%
慶陽	3	0	2	0	66.67%
巴州	3	0	2	0	66.67%
阜陽	155	0	102	0	65.81%
安康	26	0	17	0	65.38%
撫州	72	0	47	0	65.28%
紹興	42	0	27	0	64.29%
大足	14	0	9	0	64.29%
巫溪縣	14	0	9	0	64.29%
黑河	14	0	9	0	64.29%
玉溪	14	0	9	1	64.29%
湛江	22	0	14	0	63.64%
鄂爾多斯	11	0	7	0	63.64%
宿州	41	0	26	0	63.41%
周口	76	0	48	0	63.16%
聊城	38	0	24	0	63.16%
蚌埠	160	0	101	5	63.12%
漯河	35	0	22	0	62.86%
株洲	80	0	50	0	62.5%
日照	16	0	10	0	62.5%
朔州	8	0	5	0	62.5%
鄭州	157	0	98	0	62.42%
信陽	274	0	171	2	62.41%
六安	69	0	43	0	62.32%
贛州	76	0	47	1	61.84%
綏化	47	0	29	4	61.7%
開封	26	0	16	0	61.54%
滁州	13	0	8	0	61.54%
涼山	13	0	8	0	61.54%
新鄉	57	0	35	3	61.4%
晉中	36	0	22	0	61.11%
淮安	66	0	40	0	60.61%
昆明	53	0	32	0	60.38%
長春	45	0	27	0	60%
泰安	35	0	21	1	60%
四平	15	0	9	1	60%
韶關	10	0	6	0	60%
巫山縣	10	0	6	0	60%
秦皇島	10	0	6	1	60%
潮州	5	0	3	0	60%
濟源	5	0	3	0	60%
固原	5	0	3	0	60%
三亞	54	0	32	1	59.26%
池州	17	0	10	0	58.82%
渝北	17	0	10	0	58.82%
兩江新區	17	0	10	0	58.82%
遂寧	17	0	10	0	58.82%
七臺河	17	0	10	0	58.82%
滄州	48	0	28	3	58.33%
湘潭	36	0	21	0	58.33%
長沙	242	0	141	2	58.26%
洛陽	31	0	18	0	58.06%
合肥	174	0	101	1	58.05%
溫州	504	0	292	1	57.94%
鶴壁	19	0	11	0	57.89%
青島	59	0	34	1	57.63%
蘇州	87	0	50	0	57.47%
寶山	21	0	12	0	57.14%
雅安	7	0	4	0	57.14%
忻州	7	0	4	0	57.14%
呼倫貝爾	7	0	4	0	57.14%
廣州	345	0	197	0	57.1%
深圳	417	0	237	3	56.83%
合川	23	0	13	0	56.52%
畢節	23	0	13	0	56.52%
遵義	32	0	18	0	56.25%
昭通	25	0	14	0	56%
萬州	118	0	66	4	55.93%
南京	93	0	52	0	55.91%
岳陽	156	0	87	1	55.77%
淮南	27	0	15	0	55.56%
淮北	27	0	15	0	55.56%
榮昌區	9	0	5	0	55.56%
奉賢	9	0	5	0	55.56%
保山	9	0	5	0	55.56%
威海	38	0	21	0	55.26%
九龍坡	20	0	11	1	55%
成都	143	0	78	3	54.55%
綿陽	22	0	12	0	54.55%
玉林	11	0	6	0	54.55%
廈門	35	0	19	0	54.29%
齊齊哈爾	43	0	23	1	53.49%
嘉興	45	0	24	0	53.33%
河東	15	0	8	0	53.33%
焦作	32	0	17	1	53.12%
桂林	32	0	17	0	53.12%
珠海	98	0	52	1	53.06%
黃岡	2904	0	1540	98	53.03%
南寧	55	0	29	0	52.73%
南充	38	0	20	0	52.63%
肇慶	19	0	10	1	52.63%
長壽	21	0	11	0	52.38%
綦江	23	0	12	0	52.17%
銅陵	29	0	15	0	51.72%
濟南	47	0	24	0	51.06%
濰坊	44	0	22	0	50%
馬鞍山	38	0	19	0	50%
貴陽	36	0	18	1	50%
吉安	22	0	11	0	50%
墊江縣	20	0	10	0	50%
南平	20	0	10	0	50%
舟山	10	0	5	0	50%
晉城	10	0	5	0	50%
揭陽	8	0	4	0	50%
景德鎮	6	0	3	0	50%
巴南	6	0	3	0	50%
朝陽	6	0	3	0	50%
公主嶺	6	0	3	0	50%
高新區	4	0	2	0	50%
崇明縣	4	0	2	0	50%
賀州	4	0	2	0	50%
東麗	4	0	2	0	50%
通化	4	0	2	0	50%
文山州	2	0	1	0	50%
武清	2	0	1	0	50%
臨汾	2	0	1	0	50%
恩施州	251	0	123	3	49%
海口	39	0	19	0	48.72%
咸寧	836	0	398	11	47.61%
大連	19	0	9	0	47.37%
天門	494	0	232	13	46.96%
黃石	1001	0	468	29	46.75%
淄博	30	0	14	0	46.67%
渭南	15	0	7	0	46.67%
連雲港	48	0	22	0	45.83%
柳州	24	0	11	0	45.83%
泉州	46	0	21	0	45.65%
奉節縣	22	0	10	0	45.45%
內江	22	0	10	0	45.45%
鷹潭	18	0	8	0	44.44%
紅河	9	0	4	0	44.44%
莆田	55	0	24	0	43.64%
烏魯木齊	23	0	10	0	43.48%
仙桃	571	0	248	19	43.43%
荊州	1574	0	681	41	43.27%
九江	118	0	51	0	43.22%
佛山	84	0	36	0	42.86%
吳忠	28	0	12	0	42.86%
茂名	14	0	6	0	42.86%
牡丹江	14	0	6	0	42.86%
昌江	7	0	3	0	42.86%
巴中	24	0	10	0	41.67%
葫蘆島	12	0	5	1	41.67%
濮陽	17	0	7	0	41.18%
潛江	191	0	78	8	40.84%
煙臺	47	0	19	0	40.43%
十堰	667	0	267	2	40.03%
銅梁區	10	0	4	0	40%
豐都縣	10	0	4	0	40%
汕尾	5	0	2	0	40%
涪陵	5	0	2	0	40%
德宏	5	0	2	0	40%
襄陽	1173	0	463	28	39.47%
萍鄉	33	0	13	0	39.39%
荊門	918	0	361	37	39.32%
江門	23	0	9	0	39.13%
哈爾濱	198	0	77	3	38.89%
德陽	18	0	7	0	38.89%
雙鴨山	52	0	20	3	38.46%
漢中	26	0	10	0	38.46%
隨州	1300	0	498	30	38.31%
貴港	8	0	3	0	37.5%
長治	8	0	3	0	37.5%
巴彥淖爾	8	0	3	0	37.5%
包頭	11	0	4	0	36.36%
江北	28	0	10	0	35.71%
三明	14	0	5	0	35.71%
唐山	58	0	20	1	34.48%
瀘州	24	0	8	0	33.33%
潼南區	18	0	6	0	33.33%
伊犁州	18	0	6	0	33.33%
南岸	15	0	5	0	33.33%
赤峯	9	0	3	0	33.33%
南開	6	0	2	0	33.33%
北辰	6	0	2	0	33.33%
保亭縣	3	0	1	0	33.33%
吐魯番	3	0	1	0	33.33%
烏蘭察布	3	0	1	0	33.33%
東莞	94	0	31	1	32.98%
德州	37	0	12	2	32.43%
北海	44	0	14	1	31.82%
達州	41	0	13	0	31.71%
寶坻	60	0	19	1	31.67%
防城港	19	0	6	0	31.58%
宜昌	917	0	289	29	31.52%
孝感	3443	0	1078	102	31.31%
大慶	26	0	8	1	30.77%
雞西	46	0	14	0	30.43%
鄂州	1379	0	417	40	30.24%
呼和浩特	7	0	2	0	28.57%
河源	4	0	1	0	25%
安順	4	0	1	0	25%
寧河縣	4	0	1	0	25%
兵團第八師石河子市	4	0	1	1	25%
錫林郭勒盟	9	0	2	0	22.22%
武漢	46201	0	8186	1856	17.72%
甘孜州	69	0	12	0	17.39%
河池	25	0	4	1	16%
鐵嶺	7	0	1	0	14.29%
遼源	7	0	1	0	14.29%
通遼	7	0	1	0	14.29%
沙坪壩	8	0	1	0	12.5%
濟寧	257	0	31	0	12.06%
外地來京	26	0	2	0	7.69%
豐臺	41	0	3	0	7.32%
石景山	14	0	1	0	7.14%
通州	19	0	1	0	5.26%
大興	39	0	2	0	5.13%
監獄系統	253	0	3	0	1.19%
海淀	62	0	0	0	0%
朝陽	60	0	0	0	0%
西城	53	0	0	0	0%
省十里豐監獄	36	0	0	0	0%
昌平	29	0	0	0	0%
房山	16	0	0	0	0%
東城	12	0	0	0	0%
來賓	11	0	0	0	0%
盤錦	11	0	0	0	0%
順義	10	0	0	0	0%
兵團第四師	10	0	0	0	0%
阜新	8	0	0	0	0%
懷柔	7	0	0	0	0%
密雲	7	0	0	0	0%
鞍山	4	0	0	0	0%
兵團第九師	4	0	0	1	0%
門頭溝	3	0	0	0	0%
兵團第十二師	3	0	0	0	0%
彭水縣	2	0	0	0	0%
兵團第六師五家渠市	2	0	0	0	0%
烏海	2	0	0	0	0%
贛江新區	1	0	0	0	0%
酉陽縣	1	0	0	0	0%
萬盛經開區	1	0	0	0	0%
伊春	1	0	0	0	0%
延慶	1	0	0	0	0%
楊淩示範區	1	0	0	0	0%
白城	1	0	0	0	0%
興安盟	1	0	0	0	0%

大城市的治癒率

地方  確診 疑似  治癒  死亡 治癒率
上海	335	0	249	3	74.33%
廣州	345	0	197	0	57.1%
深圳	417	0	237	3	56.83%
北京	399	0	189	4	47.37%

 python通過rest接口獲得json數據。 

import urllib3
import json
def readdict(dic,path):
  fds=path.split(".")
  mo=dic
  for fd in fds:
      if isinstance(mo,list):
          ix=int(fd);
          mo=mo[ix]
      elif isinstance(mo,dict):
          mo=mo[fd]
  return mo;

def Write_Text(file_name,contant):
    # file_name = 'test.txt'
    with open(file_name,"w",encoding='utf-8') as f:
        f.writelines(contant)
        f.writelines("\n")
class DataItem(object):
    name = "kirin"
    confirm=0
    suspect=0
    heal=0
    dead=0;
    # # self.屬性寫入 等價於調用dict.__setitem__
    __setitem__ = object.__setattr__
    # # self.屬性讀取 等價於調用dict.__setitem__
    __getitem__ = object.__getattribute__
    def getConfirm(self):
        return 1 if self.confirm==0 else self.confirm;

    def toLine(self):
        sd="{:.4f}".format(self.heal*1.0/self.getConfirm())
        print(self.name,self.confirm,self.suspect,self.heal,self.dead,sd)

def dict2DataItem(dictObj):
    inst=DataItem();
    inst.name=dictObj['name']
    total=dictObj['total']
    for k, v in total.items():
        inst[k] = v
    return inst

url = "https://c.m.163.com/ug/api/wuhan/app/data/list-total?t=1582418617382";
http = urllib3.PoolManager()
r = http.request('GET', url,headers={'accept': 'application/json'})
print(r.status)
r.encoding = 'utf-8'
html=r.data.decode( );
#tm=json.decoder(html)
dict1=json.loads(html)
#print(dict1);
print(dict1['msg']);
art=dict1['data']['areaTree'];
print(dict1['data']['areaTree'][0]['name']);
china=readdict(dict1,"data.areaTree.0.name")
print(china)
tm=readdict(dict1,"data.areaTree.0.lastUpdateTime")
aa=tm.split(" ");
print(aa[0])
fp="data"+aa[0]+".json"
Write_Text(fp,html);
fdp="data.json"
Write_Text(fdp,html);
children=readdict(dict1,"data.areaTree.0.children")
plst=[]
for pe in children:
    dt=dict2DataItem(pe)
    plst.append(dt)

plst.sort(key=lambda x:x.heal/x.getConfirm() ,reverse=True)
print("地方  確診 疑似  治癒  死亡 治癒率")
for pe in plst:
    pe.toLine()
print(len(plst))
#html = json.dumps(html).encode('utf-8')
#print(html)

python輸出如下,之後類似java處理。 

200
成功
中國
中國
2020-02-23
地方  確診 疑似  治癒  死亡 治癒率
青海 18 0 18 0 1.0000
西藏 1 0 1 0 1.0000
甘肅 91 0 78 2 0.8571
寧夏 71 0 56 0 0.7887
上海 335 0 249 3 0.7433
。。。。。。

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章