# 列表中嵌套字典。按字典键值实现去重复
l3 = [
    {
        "id": 848,
        "name": "张仁杰",
        "planType": "百万终身抗癌互助计划",
        "helpMoney": "150000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/24db3b4892894e33899bf8c657b0961c.jpeg",
        "noticeNo": "256776c370a14289",
        "eventType": "鼻咽癌",
        "joinDays": 268,
        "totalShareAmount": "0.00",
        "totalShareTimes": 0,
        "hide": "true"
    },
    {
        "id": 849,
        "name": "张仁杰",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "250000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/24db3b4892894e33899bf8c657b0961c.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "鼻咽癌",
        "joinDays": 271,
        "totalShareAmount": "9.19",
        "totalShareTimes": 18,
        "hide": "true"
    },
    {
        "id": 855,
        "name": "叶泽民",
        "planType": "综合意外互助计划",
        "helpMoney": "10000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/dca983f17b3143c2ae9618bac8efaa11.jpeg",
        "noticeNo": "1dcd7bfdf90543b3",
        "eventType": "十级伤残",
        "joinDays": 444,
        "totalShareAmount": "12.04",
        "totalShareTimes": 36,
        "hide": "true"
    },
    {
        "id": 856,
        "name": "于吉波",
        "planType": "综合意外互助计划",
        "helpMoney": "20000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/dd781cb30a08405ea6099270a59d37b0.jpeg",
        "noticeNo": "1dcd7bfdf90543b3",
        "eventType": "九级伤残",
        "joinDays": 432,
        "totalShareAmount": "12.04",
        "totalShareTimes": 36,
        "hide": "true"
    },
    {
        "id": 857,
        "name": "邬喜梅",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "50000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/231810e753e64baaa5eca20889d16be2.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "甲状腺乳头状癌",
        "joinDays": 426,
        "totalShareAmount": "19.47",
        "totalShareTimes": 35,
        "hide": "true"
    },
    {
        "id": 858,
        "name": "张民治",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "100000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/db5bd9f8dbda4bf6a5f473d21c377c7c.jpeg",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "肺癌",
        "joinDays": 450,
        "totalShareAmount": "25.77",
        "totalShareTimes": 25,
        "hide": "true"
    },
    {
        "id": 859,
        "name": "万后永",
        "planType": "综合意外互助计划",
        "helpMoney": "10000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/3bd1e85297fc443ab7848e0a47a946b3.png!hz_mtr_200_nw",
        "noticeNo": "1dcd7bfdf90543b3",
        "eventType": "十级伤残",
        "joinDays": 472,
        "totalShareAmount": "12.61",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 860,
        "name": "章星江",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "200000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/48a986ce0091486baada70da895e98de.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "胆囊癌",
        "joinDays": 518,
        "totalShareAmount": "20.78",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 861,
        "name": "黄海华",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "200000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/8d72dd87873c411b9c49d0da8a44473d.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "鼻咽癌",
        "joinDays": 399,
        "totalShareAmount": "13.73",
        "totalShareTimes": 21,
        "hide": "true"
    },
    {
        "id": 862,
        "name": "邵春利",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "50000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/c9cf6798260e43689725f2ba1621aa15.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "甲状腺乳头状癌",
        "joinDays": 690,
        "totalShareAmount": "20.78",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 863,
        "name": "马承燕",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "50000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/9b0bb92cbe23415987dbdfa1940e5e23.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "卵巢粘液性囊腺癌",
        "joinDays": 717,
        "totalShareAmount": "20.78",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 864,
        "name": "黄兴珍",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "200000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/b6a8d14b6ef3487a95061dbb012a171d.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "食管癌",
        "joinDays": 504,
        "totalShareAmount": "22.69",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 865,
        "name": "崔灿",
        "planType": "综合意外互助计划",
        "helpMoney": "20000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/14cc212683da404fa0c678fcfb8857e1.jpeg",
        "noticeNo": "1dcd7bfdf90543b3",
        "eventType": "九级伤残",
        "joinDays": 507,
        "totalShareAmount": "12.61",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 866,
        "name": "王士军",
        "planType": "百万终身抗癌互助计划",
        "helpMoney": "100000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/b53d90c81c584fd9a780cbb19159200c.jpeg",
        "noticeNo": "256776c370a14289",
        "eventType": "肺癌",
        "joinDays": 300,
        "totalShareAmount": "0.00",
        "totalShareTimes": 0,
        "hide": "true"
    },
    {
        "id": 867,
        "name": "王士军",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "200000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/b53d90c81c584fd9a780cbb19159200c.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "肺癌",
        "joinDays": 427,
        "totalShareAmount": "16.02",
        "totalShareTimes": 26,
        "hide": "true"
    },
    {
        "id": 868,
        "name": "杨桂芬",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "200000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/2b8369d5836a42028c6aef780a597955.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "乳腺癌",
        "joinDays": 355,
        "totalShareAmount": "14.08",
        "totalShareTimes": 25,
        "hide": "true"
    },
    {
        "id": 869,
        "name": "李常胜",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "250000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/cc7789e23ed5404b928326aa194761b9.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "结肠癌",
        "joinDays": 607,
        "totalShareAmount": "20.78",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 870,
        "name": "刘春旭",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "50000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/598c0e47d8664f20823526cfca29cb51.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "甲状腺乳头状癌",
        "joinDays": 756,
        "totalShareAmount": "20.78",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 871,
        "name": "余明芳",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "100000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/7c70d4080c254eabb36f9a7ddb953920.png!hz_mtr_200_nw",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "卵巢癌",
        "joinDays": 663,
        "totalShareAmount": "40.21",
        "totalShareTimes": 77,
        "hide": "true"
    },
    {
        "id": 872,
        "name": "杨开云",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "250000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/b02188ec2d1b44af8d91cf5c122683dc.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "间变性室管膜瘤（WHOIII级）",
        "joinDays": 446,
        "totalShareAmount": "18.49",
        "totalShareTimes": 34,
        "hide": "true"
    },
    {
        "id": 873,
        "name": "石岩",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "100000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/2e2eacd5e9534dea879f29944be3f53e.jpeg",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "腹股沟恶性肿瘤",
        "joinDays": 647,
        "totalShareAmount": "28.05",
        "totalShareTimes": 30,
        "hide": "true"
    },
    {
        "id": 874,
        "name": "韩天福",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "250000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/f9dfef242d2b4a2db1bc4afeaf826a48.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "鼻咽癌",
        "joinDays": 354,
        "totalShareAmount": "17.76",
        "totalShareTimes": 33,
        "hide": "true"
    },
    {
        "id": 875,
        "name": "赵立东",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "200000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/ad7d664888624076b415277daa65a9f4.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "输尿管高级别浸润性尿路上皮癌",
        "joinDays": 430,
        "totalShareAmount": "20.28",
        "totalShareTimes": 36,
        "hide": "true"
    },
    {
        "id": 876,
        "name": "王丹",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "200000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/bdecd621a0d441d4824fe6f4c6ad4459.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "胸腺癌",
        "joinDays": 461,
        "totalShareAmount": "20.74",
        "totalShareTimes": 37,
        "hide": "true"
    },
    {
        "id": 877,
        "name": "封喆文",
        "planType": "少儿健康互助计划",
        "helpMoney": "300000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/4850e64b28f744c3b3093a9250965d25.jpeg",
        "noticeNo": "edf399fe5cb649a2",
        "eventType": "急性白血病",
        "joinDays": 488,
        "totalShareAmount": "7.72",
        "totalShareTimes": 22,
        "hide": "true"
    },
    {
        "id": 878,
        "name": "高明",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "100000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/4e4c755eb3a14c378fd250a58cf7c4c3.jpeg",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "肝癌",
        "joinDays": 385,
        "totalShareAmount": "24.83",
        "totalShareTimes": 26,
        "hide": "true"
    },
    {
        "id": 879,
        "name": "温纪明",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "30134.25",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/64756257b5864f48a92824d93c720ad4.jpeg",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "肝癌",
        "joinDays": 631,
        "totalShareAmount": "32.79",
        "totalShareTimes": 39,
        "hide": "true"
    },
    {
        "id": 880,
        "name": "付国生",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "30128.85",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/ca25a4d134d24aafbe67d1869f0222d7.jpeg",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "胃癌",
        "joinDays": 443,
        "totalShareAmount": "31.71",
        "totalShareTimes": 36,
        "hide": "true"
    },
    {
        "id": 881,
        "name": "陈铁全",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "100000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/e866d569426f4329a5b73aaf55821a55.jpeg",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "胃癌",
        "joinDays": 523,
        "totalShareAmount": "32.56",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 882,
        "name": "高树华",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "100000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/ed819478f65142cf83f131ec00a9dbd1.jpeg",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "甲状腺髓样癌",
        "joinDays": 313,
        "totalShareAmount": "19.07",
        "totalShareTimes": 31,
        "hide": "true"
    },
    {
        "id": 883,
        "name": "龚佳瑶",
        "planType": "少儿健康互助计划",
        "helpMoney": "300000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/fe06e132b0644772946d3eb56e2a0e13.jpeg",
        "noticeNo": "edf399fe5cb649a2",
        "eventType": "急性淋巴细胞白血病",
        "joinDays": 507,
        "totalShareAmount": "7.72",
        "totalShareTimes": 22,
        "hide": "true"
    },
    {
        "id": 884,
        "name": "邬志灵",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "50000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/9e2de6edb6ff4a0d9c1246ba3d385511.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "甲状腺乳头状癌",
        "joinDays": 430,
        "totalShareAmount": "20.28",
        "totalShareTimes": 36,
        "hide": "true"
    },
    {
        "id": 885,
        "name": "邢保印",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "200000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/eaef39b92ebc49be9c773026ed82cd46.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "直肠腺癌",
        "joinDays": 342,
        "totalShareAmount": "19.13",
        "totalShareTimes": 32,
        "hide": "true"
    },
    {
        "id": 886,
        "name": "唐汉芬",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "30116.10",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/8c13ccd2449d4ca29e0733aab242cdc8.jpeg",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "肺腺癌",
        "joinDays": 402,
        "totalShareAmount": "29.16",
        "totalShareTimes": 34,
        "hide": "true"
    },
    {
        "id": 887,
        "name": "黄汉泉",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "30109.40",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/af3165f029fb496b84950aace21ebe1c.jpeg",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": " 直肠癌",
        "joinDays": 378,
        "totalShareAmount": "27.82",
        "totalShareTimes": 33,
        "hide": "true"
    },
    {
        "id": 888,
        "name": "赵阳春",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "100000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/da5d9ee055214a1abd04a4e1706fe262.png!hz_mtr_200_nw",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "肺癌",
        "joinDays": 635,
        "totalShareAmount": "28.05",
        "totalShareTimes": 30,
        "hide": "true"
    },
    {
        "id": 889,
        "name": "郑晓洲",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "250000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/a24dc3db0fe14228874a067c1e7056a7.jpeg!hz_mtr_200_nw",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "乳腺癌",
        "joinDays": 679,
        "totalShareAmount": "20.78",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 890,
        "name": "李海",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "200000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/6f98d8a4860f49548acfa559356b3636.png!hz_mtr_200_nw",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "急性髓系白血病",
        "joinDays": 374,
        "totalShareAmount": "17.76",
        "totalShareTimes": 33,
        "hide": "true"
    },
    {
        "id": 891,
        "name": "陈敏",
        "planType": "综合意外互助计划",
        "helpMoney": "100000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/31cc02d9951a47b894c0d0e74027ede4.jpeg",
        "noticeNo": "1dcd7bfdf90543b3",
        "eventType": "意外身故",
        "joinDays": 505,
        "totalShareAmount": "12.61",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 892,
        "name": "叶海燕",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "50000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/11920d545b874d3c9a92f5ab129375fc.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "甲状腺滤泡癌",
        "joinDays": 340,
        "totalShareAmount": "17.09",
        "totalShareTimes": 32,
        "hide": "true"
    },
    {
        "id": 893,
        "name": "王红",
        "planType": "综合意外互助计划",
        "helpMoney": "10000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/6f9a3c2f7b8f4028a828d2343e0cad5b.png!hz_mtr_200_nw",
        "noticeNo": "1dcd7bfdf90543b3",
        "eventType": "十级伤残",
        "joinDays": 592,
        "totalShareAmount": "34.42",
        "totalShareTimes": 79,
        "hide": "true"
    },
    {
        "id": 894,
        "name": "宋诚",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "200000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/cae1d54a665b4eb58719bc98eaddad36.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "舌癌",
        "joinDays": 665,
        "totalShareAmount": "20.78",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 895,
        "name": "豆伯安",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "200000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/921a96b9b4134f5cba30fa2542612ed5.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "食管癌",
        "joinDays": 656,
        "totalShareAmount": "22.82",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 896,
        "name": "高彩华",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "200000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/715f5bbc1aed4e38bd2ec3d0d8581bd9.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "子宫内膜腺癌",
        "joinDays": 534,
        "totalShareAmount": "20.78",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 897,
        "name": "王彩",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "30134.25",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/4abf27af0e3a4892ad6667ded3bf5220.jpeg",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "左肺癌",
        "joinDays": 597,
        "totalShareAmount": "40.92",
        "totalShareTimes": 68,
        "hide": "true"
    },
    {
        "id": 898,
        "name": "邓文强",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "50000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/a6edaa451f0a454a90ae1ad0908feab1.png!hz_mtr_200_nw",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "甲状腺乳头状癌",
        "joinDays": 393,
        "totalShareAmount": "14.38",
        "totalShareTimes": 24,
        "hide": "true"
    },
    {
        "id": 899,
        "name": "陈桂芳",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "50000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/13eda640c6b14a36bac178ec7a09cef7.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "甲状腺乳头状癌",
        "joinDays": 424,
        "totalShareAmount": "20.28",
        "totalShareTimes": 36,
        "hide": "true"
    },
    {
        "id": 900,
        "name": "曲燕妮",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "250000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/41cd4a856ddb4fd0bacc43e3bb332c58.png!hz_mtr_200_nw",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "急性B淋巴细胞白血病",
        "joinDays": 678,
        "totalShareAmount": "20.78",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 901,
        "name": "程秀月",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "100000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/888e67ced38f4f688c8b62a964946189.jpeg",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "宫颈癌",
        "joinDays": 402,
        "totalShareAmount": "29.16",
        "totalShareTimes": 34,
        "hide": "true"
    },
    {
        "id": 902,
        "name": "周卫",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "100000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/c88231d1fe4d4286bd5827cbe8902c96.jpeg",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "乳腺恶性肿瘤（左乳腺癌）",
        "joinDays": 674,
        "totalShareAmount": "29.48",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 903,
        "name": "李洪兰",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "200000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/e97e036473384297a7e3b6b349ac0d73.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "结肠癌",
        "joinDays": 390,
        "totalShareAmount": "18.64",
        "totalShareTimes": 34,
        "hide": "true"
    },
    {
        "id": 904,
        "name": "项良年",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "100000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/89c3e734498a4df392544cf48a47ab0e.jpeg",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "肺癌",
        "joinDays": 613,
        "totalShareAmount": "32.79",
        "totalShareTimes": 39,
        "hide": "true"
    },
    {
        "id": 905,
        "name": "许缓缓",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "300000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/96ee80a9f3e646adb4b7b132e0276366.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "急性淋巴细胞白血病",
        "joinDays": 670,
        "totalShareAmount": "20.78",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 906,
        "name": "刘丽丽",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "50000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/fc5be77f1f4f4d9ba28c51ca8281349e.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "甲状腺乳头状癌",
        "joinDays": 243,
        "totalShareAmount": "11.91",
        "totalShareTimes": 26,
        "hide": "true"
    },
    {
        "id": 907,
        "name": "卜勇",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "50000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/05eeb53c82b140bca7d3eb68da1876c0.png!hz_mtr_200_nw",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "甲状腺乳头状癌",
        "joinDays": 297,
        "totalShareAmount": "14.38",
        "totalShareTimes": 29,
        "hide": "true"
    },
    {
        "id": 908,
        "name": "毕佳佳",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "50000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/88e80ec4bd264e05a8f31ad9d090773b.png!hz_mtr_200_nw",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "甲状腺乳头状癌",
        "joinDays": 545,
        "totalShareAmount": "20.78",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 909,
        "name": "韩金峰",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "250000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/a7769e70146a4c99b26f098568469a68.png!hz_mtr_200_nw",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "结肠癌",
        "joinDays": 319,
        "totalShareAmount": "16.46",
        "totalShareTimes": 31,
        "hide": "true"
    },
    {
        "id": 910,
        "name": "何旭",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "250000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/4bdc329b3da4440599945fc1ccd83171.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "乳腺癌",
        "joinDays": 277,
        "totalShareAmount": "13.45",
        "totalShareTimes": 28,
        "hide": "true"
    },
    {
        "id": 911,
        "name": "吴强",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "200000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/eabfc36b1ecc46c6a33c252b7bdea313.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "直肠癌",
        "joinDays": 476,
        "totalShareAmount": "20.74",
        "totalShareTimes": 37,
        "hide": "true"
    },
    {
        "id": 912,
        "name": "罗福江",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "100000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/300b54ee83234b648526a86eeaed3a1b.jpeg!hz_mtr_200_nw",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "食管癌",
        "joinDays": 405,
        "totalShareAmount": "25.19",
        "totalShareTimes": 31,
        "hide": "true"
    },
    {
        "id": 913,
        "name": "马艳沙",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "50000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/8f8a3cc43a8a4e0aa23e32af1f95652a.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "肾透明细胞癌（II级）",
        "joinDays": 392,
        "totalShareAmount": "18.64",
        "totalShareTimes": 34,
        "hide": "true"
    },
    {
        "id": 914,
        "name": "操璐",
        "planType": "百万终身抗癌互助计划",
        "helpMoney": "150000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/94bb94fccd8f42efbcb878ac7ececd00.jpeg",
        "noticeNo": "256776c370a14289",
        "eventType": "乳腺癌",
        "joinDays": 306,
        "totalShareAmount": "0.00",
        "totalShareTimes": 0,
        "hide": "true"
    },
    {
        "id": 915,
        "name": "操璐",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "250000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/94bb94fccd8f42efbcb878ac7ececd00.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "乳腺癌",
        "joinDays": 307,
        "totalShareAmount": "11.08",
        "totalShareTimes": 20,
        "hide": "true"
    },
    {
        "id": 916,
        "name": "周萍",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "200000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/6c5b7bebd91945da9634ec8bdff1a18f.jpeg",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "直肠癌",
        "joinDays": 677,
        "totalShareAmount": "20.78",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 917,
        "name": "陈秋玲",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "250000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/0265bfe7cfb74ccba7621465814c969e.png!hz_mtr_200_nw",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "肺腺癌",
        "joinDays": 700,
        "totalShareAmount": "20.78",
        "totalShareTimes": 38,
        "hide": "true"
    },
    {
        "id": 918,
        "name": "耿燕燕",
        "planType": "中青年抗癌互助计划",
        "helpMoney": "250000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/2c844275e7594c72a7c81196df202dc8.png!hz_mtr_200_nw",
        "noticeNo": "fc2fe76e24aa4cfb",
        "eventType": "乳腺癌",
        "joinDays": 391,
        "totalShareAmount": "13.50",
        "totalShareTimes": 23,
        "hide": "true"
    },
    {
        "id": 928,
        "name": "王宝有",
        "planType": "中老年抗癌互助计划",
        "helpMoney": "100000.00",
        "imgUrl": "http://alioss.shuidihuzhu.com/apply/46583c2faf974b4ca4f5ab11e34958d2.jpeg!hz_mtr_200_nw",
        "noticeNo": "5f7dc8f09a264841",
        "eventType": "胰腺癌",
        "joinDays": 491,
        "totalShareAmount": "26.48",
        "totalShareTimes": 27,
        "hide": "true"
    }
]
l4 = []
l4.append(l3[0])
for dict in l3:
    print(len(l4))
    k = 0
    for item in l4:
        # print 'item'
        if dict['planType'] != item['planType']:
            k = k + 1
            # continue
        else:
            break
        if k == len(l4):
            l4.append(dict)
print("l4: ", l4)

python字典/列表中嵌套字典。按字典键值实现去重复.py

列表中嵌套字典。按字典键值实现去重复.py


# -*- coding: utf-8 -*-
from openerp import api, fields, models, _
from openerp.exceptions import UserError
from datetime import datetime, date
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT

class crm_lead(models.Model):
    _inherit = "crm.lead"

    @api.multi
    @api.depends('fal_activity_follow_up_ids', 'fal_activity_follow_up_ids.cam_logo')
    def _get_show_follow_up_in_portal(self):
        fal_show_follow_up_in_portal = False
        for lead in self:
            for activity_follow_up in lead.fal_activity_follow_up_ids:
                if activity_follow_up.cam_logo:
                    fal_show_follow_up_in_portal = True
        self.fal_show_follow_up_in_portal = fal_show_follow_up_in_portal

    fal_last_call_boolean = fields.Boolean('Color this button when you want to show this on portal.', help='Color this button when you want to show this on portal.')
    fal_regional_mutual_diffusion = fields.Boolean('Regional Mutual Diffusion')
    fal_show_follow_up_in_portal = fields.Boolean('Show Follow Up in Portal', compute=_get_show_follow_up_in_portal)

    @api.multi
    def toogle_fal_regional_mutual_diffusion(self):
        if self.fal_regional_mutual_diffusion:
            self.fal_regional_mutual_diffusion = False
            self.fal_last_call_boolean = False
            for activity_follow_up_id in self.fal_activity_follow_up_ids:
                activity_follow_up_id.cam_logo = False
        else:
            self.fal_regional_mutual_diffusion = True

    @api.multi
    def toogle_fal_last_call_boolean(self):
        if self.fal_regional_mutual_diffusion:
            if self.fal_last_call_boolean:
                self.fal_last_call_boolean = False
            else:
                self.fal_last_call_boolean = True

    @api.multi
    def action_customer_project_send(self):
        '''
        This function opens a window to compose an email, with the edi sale template message loaded by default
        '''
        self.ensure_one()
        ir_model_data = self.env['ir.model.data']
        try:
            template_id = ir_model_data.get_object_reference('gleize_portal_ext', 'email_template_portal_customer_project')[1]
        except ValueError:
            template_id = False
        try:
            compose_form_id = ir_model_data.get_object_reference('mail', 'email_compose_message_wizard_form')[1]
        except ValueError:
            compose_form_id = False
        ctx = dict()
        ctx.update({
            'default_model': 'crm.lead',
            'default_res_id': self.ids[0],
            'default_use_template': bool(template_id),
            'default_template_id': template_id,
            'default_composition_mode': 'comment',
            'mark_so_as_sent': True
        })
        return {
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'mail.compose.message',
            'views': [(compose_form_id, 'form')],
            'view_id': compose_form_id,
            'target': 'new',
            'context': ctx,
        }

    def get_signup_url(self, cr, uid, ids, context=None):
        assert len(ids) == 1
        document = self.browse(cr, uid, ids[0], context=context)
        contex_signup = dict(context, signup_valid=True)
        return self.pool['res.partner']._get_signup_url_for_action(
            cr, uid, [document.partner_id.id], action='/mail/view',
            model=self._name, res_id=document.id, context=contex_signup,
        )[document.partner_id.id]

class FalActivityFollowUp(models.Model):
    _inherit = 'fal.activity.follow.up'

    cam_logo = fields.Boolean("CAM Logo")

    @api.multi
    def toggle_activity_status(self):
        self.ensure_one()
        if self.lead_id.fal_regional_mutual_diffusion:
            if self.cam_logo:
                self.cam_logo = False
            else:
                self.cam_logo = True
        return True


import json
import pickle

import jieba
import os
import re
from gensim.models import word2vec

jieba.load_userdict("dict/dict.txt.big.txt")
jieba.load_userdict("dict/NameDict_Ch_v2")
jieba.load_userdict("dict/ntusd-negative.txt")
jieba.load_userdict("dict/ntusd-positive.txt")
jieba.load_userdict("dict/鄉民擴充辭典.txt")

print("--- 測試斷詞 ---")
print('/'.join(jieba.cut('柯P是柯市長', HMM=False)))
print("--- 測試斷詞 end ---")

# stop word
stopword_path = "dict/stopwords.json"
stopword_set = set()
with open(stopword_path, 'r') as csv:
    j_list = json.load(csv)
    for word in j_list:
        stopword_set.add(word)
print("讀取stop words")

# 情緒字詞
p_word_path = "dict/ntusd-positive.txt"
p_word_set = set()
with open(p_word_path, 'r') as csv:
    for line in csv:
        p_word_set.add(line)

n_word_path = "dict/ntusd-negative.txt"
n_word_set = set()
with open(n_word_path, 'r') as csv:
    for line in csv:
        n_word_set.add(line)

p_n_word_set = p_word_set.union(n_word_set)

comma_tokenizer = lambda x: [y for y in jieba.cut(x, cut_all=False, HMM=True) if y not in stopword_set]
#comma_tokenizer = lambda x: [y for y in jieba.cut(x, cut_all=False, HMM=True) if y in p_n_word_set]
#comma_tokenizer = lambda x: jieba.cut(x, cut_all=False, HMM=True)
#comma_tokenizer = lambda x: [y for y in x]

def clear_doc(doc):
    # 去除網址和符號
    r2 = r'https://[a-zA-Z0-9.?/&=:]*'
    r = '[’!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~]+'
    r3 = r'\n'
    text = re.sub(r2, '', doc)
    text = re.sub(r, '', text)
    # text = re.sub(r3, ' ', text)
    return text

def stream_docs(path, label):
    x = []
    y = []
    with open(path, 'r') as csv:
        for line in csv:
            text = clear_doc(line)
            if len(text) == 0:
                continue
            x.append([i for i in comma_tokenizer(text)])
            y.append(label)
    return x, y

def get_docs_labels(doc_streams):
    docs, y = [], []
    for doc_stream in doc_streams:
        try:
            t_x, t_y = doc_stream
            docs.extend(t_x)
            y.extend(t_y)
        except Exception:
            return None, None
    return docs, y

doc_streams = [stream_docs(path='data/n/broken-heart.txt', label=0), stream_docs(path='data/p/adulation.txt', label=1),
               stream_docs(path='data/p/kindness.txt', label=1)]

documents = get_docs_labels(doc_streams)[0]

word2vec_model_path = "model/word2vec.bin"

if not os.path.exists(word2vec_model_path):
    model = word2vec.Word2Vec(documents, size=250)
    model.save(word2vec_model_path)
else:
    model = word2vec.Word2Vec.load(word2vec_model_path)

result = model.most_similar("傷心")
print(result)
#print(model.similarity("傷心", "的"))


import discord, json, requests, pymysql.cursors
from discord.ext import commands
from utils import rpc_module, mysql_module, parsing
import math

rpc = rpc_module.Rpc()
mysql = mysql_module.Mysql()

class Withdraw:
    def __init__(self, bot):
        self.bot = bot
        config = parsing.parse_json('config.json')
        self.currency_symbol = config["currency_symbol"]
        self.explorer_url = config["explorer_url"]

    @commands.command(pass_context=True)
    async def withdraw(self, ctx, address: str, amount: float):
        """Withdraw coins from your account to any MyMn address"""
        snowflake = ctx.message.author.id
        if amount <= 0.0:
            await self.bot.say("{} **:warning:You cannot withdraw <= 0!:warning:**".format(ctx.message.author.mention))
            return

        abs_amount = abs(amount)
        if math.log10(abs_amount) > 8:
            await self.bot.say(":warning:**Invalid amount!**:warning:")
            return

        mysql.check_for_user(snowflake)

        conf = rpc.validateaddress(address)
        if not conf["isvalid"]:
            await self.bot.say("{} **:warning:Invalid address!:warning:**".format(ctx.message.author.mention))
            return

        ownedByBot = False
        for address_info in rpc.listreceivedbyaddess(0, True):
            if address_info["address"] == address:
                ownedByBot = True
                break

        if ownedByBot:
            await self.bot.say("{} **:warning:You cannot withdraw to an address owned by this bot!:warning:** Please use tip instead!".format(ctx.message.author.mention))
            return

        balance = mysql.get_balance(snowflake, check_update=True)
        if float(balance) < amount:
            await self.bot.say("{} **:warning:You cannot withdraw more money than you have!:warning:**".format(ctx.message.author.mention))
            return

        txid = mysql.create_withdrawal(snowflake, address, amount)
        if txid is None:
            await self.bot.say("{} your withdraw failed despite having the necessary balance! Please contact the support team".format(ctx.message.author.mention))
        else:
            await self.bot.say("{} **Withdrew {} {}! :moneybag:**\nView the transaction here: http://{}{}".format(ctx.message.author.mention, str(amount), self.currency_symbol, self.explorer_url, txid))

def setup(bot):
    bot.add_cog(Withdraw(bot))


"""
Docstring for this application
"""
from flask import Flask, render_template
from opt_seeker import list_of_functions_per_module, read_fnc

functions_cache = {}
attributes_cache = {}

# FLASK APP initialization
app = Flask(__name__)

@app.before_first_request
def  read_in_functions():
    """
    read in opt directory with all functions and their attributes
    :return:
    functions_cache: dict - list of all functions keyed by their module
    attributes_cache: dict - list of header data keyed by (module,function)
    """
    global functions_cache, attributes_cache
    result_dict = list_of_functions_per_module(return_attributes=True)
    functions_cache, attributes_cache = result_dict['functions'], result_dict['attributes']

# ROUTES
@app.route('/')
@app.route('/functions')
def opt_overview():
    """
    render all modules and their associated functions
    """

    return render_template(
        'page-functions.html',
        title='Functions',
        functions=functions_cache,
        attributes=attributes_cache,
    )

@app.route('/functions/<string:module>/<string:fnc>')
def opt_function_header(module, fnc):
    """
    read in function specified by module and fnc
    :param module: name of the module
    :param fnc: name of the function
    :return:
    """
    return_dict = read_fnc(module, fnc, return_attributes=False)
    fnc_name_full = 'fnc_{0}.sqf'.format(fnc)

    return render_template(
        'page-function-header.html',
        title=fnc_name_full,
        module=module,
        function=fnc,
        functions=functions_cache,
        attributes=attributes_cache,
        header=return_dict['header'],
        content=return_dict['content']
    )

if __name__ == '__main__':
    app.run()


#快手笔试 数学科学家 数据科学题目1
#求ROC曲线以及AUC的计算逻辑

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

data=pd.read_csv('C:/Users/Administrator/Desktop/label_score.csv')

#需要的值
FPR=[]
TPR=[]

#计算之前对于data按照score进行排序
da=data.sort_values(by='score',ascending=False)
n=len(da)
for i in range(n):
    ui=0
    tp=0
    fp=0
    fn=0
    tn=0
    for j ,row in da.iterrows():
        if ui<=i:
            if row['label']==1:
                tp+=1
            else:
                fp+=1
        else:
            if row['label']==1:
                fn+=1
            else:
                tn+=1
        ui+=1
    TPR.append(tp/(tp+tn))
    FPR.append(fp/(fp+fn))
sns.pointplot(x=FPR,y=TPR)
plt.xticks(rotation=270)
plt.show()

#计算AUC
#AUC表示了正例样本被分为正例的概率大于负利
#因此需要统计正例大于负利的概率
da1=da[da['label']==1]
da2=da[da['label']==-1]
m1=len(da1)
m2=len(da2)
kk=0
for i,row1 in da1.iterrows():
    for j ,row2 in da2.iterrows() :
        if row1['score']>row2['score']:
            kk+=1
AUC=kk/(m1*m2)

#如果要使用sklearn的话，则需要预测出来的label
#使用的包有：
from sklearn.metrics import accuracy_score
from sklearn import metrics
from sklearn.metrics import confusion_matrix
#confusion_matrix(y_true, y_pred)
from sklearn.metrics import classification_report
from sklearn.metrics import roc_auc_score#计算Roc的值


import sys
import os
import numpy as np
from queue import Queue
import time

from predictor_ultra96 import Predictor

_LIMIT = 16384

# definitons
DANCEMOVENAMES = ("dab","elbowkick","gun","hair","listen","pointhigh","sidepump","wipetable")
NUMVIEWSAMPLES = 400

THRESHOLD_ACTIVATION = 0.3
RECENT_ACTIVATION_THRESHOLD = 10
COOLDOWN_THRESHOLD = 20
GRAVITY_THRESHOLD = 0.2
GRAVITY_Z = -1.0

NUMBER_OF_AFTER_SAMPLES = 5
NUMBER_OF_BEFORE_SAMPLES = 5

assert NUMBER_OF_AFTER_SAMPLES < RECENT_ACTIVATION_THRESHOLD

class DeviceDataBuffer():
    def __init__(self, name , predict = False ):
        self.name = name
        self.a_xList = []
        self.a_yList = []
        self.a_zList = []

        self.g_xList = []
        self.g_yList = []
        self.g_zList = []

        self.activation_List = []
        self.activationFlag = False
        self.readyFlag = False
        self.activeCooldown = 0

        self.gravityQuarrel = [[0,0,0,1,1,1]]

        self.recordingBuffer = []
        self.recording = False

        self.predictor = Predictor() if predict else None

        for i in range(NUMVIEWSAMPLES):
            self.a_xList.append(0)
            self.a_yList.append(0)
            self.a_zList.append(0)

            self.g_xList.append(0)
            self.g_yList.append(0)
            self.g_zList.append(0)

            self.activation_List.append(0)

    def updatePlots(self,aX,aY,aZ, gX,gY,gZ):

        def recentlyActive(Threshold):
            return 2 in self.activation_List[-Threshold:]

        def update_activation(coords):

            magnitude = (coords[0]**2 +coords[1]**2 +coords[2]**2)**(0.5)
            # Print Magnitude - gravity??
            # print(magnitude-1)

            # StartOfMoveDetection
            if (not self.activationFlag):
                # IF not currently doing a move
                if abs( coords[2] - (GRAVITY_Z) ) < GRAVITY_THRESHOLD and (not recentlyActive(RECENT_ACTIVATION_THRESHOLD)):
                    self.readyFlag = True
                else:
                    self.readyFlag = False

                if abs(magnitude - 1) > THRESHOLD_ACTIVATION and self.readyFlag:
                    self.activationFlag = True
                    self.activeCooldown = COOLDOWN_THRESHOLD

                    if not self.predictor == None:
                        self.predictor.startRecording()

                    print("ACTIVE!!!!")
            else:
                # IF currently doing a move
                self.readyFlag = False
                self.activeCooldown-=1
                if abs(magnitude - 1) > THRESHOLD_ACTIVATION or not (abs( coords[2] - (GRAVITY_Z) ) < GRAVITY_THRESHOLD):
                    self.activationFlag = True
                    self.activeCooldown = COOLDOWN_THRESHOLD
                elif self.activeCooldown <= 0 and abs( coords[2] - (GRAVITY_Z) ) < GRAVITY_THRESHOLD:
                    self.activationFlag = False

                    if not self.predictor == None:
                        self.predictor.stopRecording()

            # calculating Activation Value
            # 2 == Activated
            # 1 == Ready
            # 0 == Idle

            updateValue = 0
            if self.readyFlag:
                updateValue = 1
            if self.activationFlag:
                updateValue = 2
            self.activation_List.pop(0)
            self.activation_List.append(updateValue)

        def movingAverage(coords):
            # moving AVG Filter
            NEWWEIGHT = 0.4 #Incoming Data Weightage
            OLDWEIGHT = 1 - NEWWEIGHT #Previous Data Weightage

            coords[0] = coords[0]*NEWWEIGHT + self.a_xList[-1]*OLDWEIGHT
            coords[1] = coords[1]*NEWWEIGHT + self.a_yList[-1]*OLDWEIGHT
            coords[2] = coords[2]*NEWWEIGHT + self.a_zList[-1]*OLDWEIGHT
            return coords

        coords = [aX,aY,aZ]
        rotations =[gX,gY,gZ]

        update_activation(coords)

        self.gravityQuarrel[0] = coords

        self.a_xList.pop(0)
        self.a_yList.pop(0)
        self.a_zList.pop(0)

        self.g_xList.pop(0)
        self.g_yList.pop(0)
        self.g_zList.pop(0)

        self.a_xList.append(coords[0])
        self.a_yList.append(coords[1])
        self.a_zList.append(coords[2])

        self.g_xList.append(rotations[0])
        self.g_yList.append(rotations[1])
        self.g_zList.append(rotations[2])

        if not self.predictor==None:
            self.predictor.updateCurrentMove(self)

class DeviceDataBufferMyoWare():
    def __init__(self):
        self.RMSList = []
        self.MAVList = []
        self.ZCSList = []

        for i in range(NUMVIEWSAMPLES):
            self.RMSList.append(0)
            self.MAVList.append(0)
            self.ZCSList.append(0)

    def updatePlots(self,R,M,Z):
        self.RMSList.pop(0)
        self.MAVList.pop(0)
        self.ZCSList.pop(0)
        self.RMSList.append(R)
        self.MAVList.append(M)
        self.ZCSList.append(Z)

class classificationEngine():
    def __init__(self):
        self.DEV1_PLOT_BUFFER = DeviceDataBuffer("dev1", predict=True)
        self.DEV2_PLOT_BUFFER = DeviceDataBuffer("dev2")
        self.DEV3_PLOT_BUFFER = DeviceDataBuffer("dev3")
        self.MYOWARE_PLOT_BUFFER = DeviceDataBufferMyoWare()

        self.PLOT_BUFFER_LIST = [self.DEV1_PLOT_BUFFER,self.DEV2_PLOT_BUFFER,self.DEV3_PLOT_BUFFER]

    def add_data(self, packet_type, d):
        if packet_type == "EMG":
            rms,mav,zcr = d

            self.MYOWARE_PLOT_BUFFER.updatePlots(rms,mav,zcr)
        if packet_type == "DATA":
            DeviceID,aX,aY,aZ, gX,gY,gZ = d
            DeviceID = int(DeviceID)
            self.PLOT_BUFFER_LIST[DeviceID-1].updatePlots(aX,aY,aZ, gX,gY,gZ)


import random
def merge(li, start, mid, end):
    merged=[]
    left=start
    right=mid+1
    while left <= mid and right <= end:#경계를 벗어니지 않는다면,
        if li[left] < li[right]:
            merged.append(li[left])
            left+=1
        else:
            merged.append(li[right])
            right+=1
    while left <= mid:
        merged.append(li[left])
        left+=1

    while right <= end:
        merged.append(li[right])
        right+=1

    li[start : end+1]= merged
#     for idx in range(start,end):
#         li[idx]=merged.pop(0) 이렇게도 쓸 수 있음

def merge_sort(li, start, end):
    if start >= end:
        return

    mid=(start+end)//2
    merge_sort(li, start, mid)
    merge_sort(li, mid+1, end)

    merge(li,start,mid,end)

if __name__=="__main__":
    while True:
        num_data=int(input('데이터 개수(종료:0):'))
        if not num_data:
            break
        data=[random.randint(1, 100) for _ in range(num_data)]
        print(data)
        merge_sort(data, 0, len(data)-1)
        print(data)


import os
from itertools import takewhile
import subprocess

import ranger.api
import ranger.core.runner
from ranger.api.commands import Command

old_hook_init = ranger.api.hook_init

def fullpath(path):
    return os.path.normpath(os.path.abspath(os.path.expanduser(path)))

def splitpath(path):
    """
    Split path into components, discard empty ones (produced by double slashes
    for instance.
    """
    return list(filter(None, directory(path).split(os.path.sep)))

def directory(path):
    """
    Returns a directory name of the supplied path, in case it's not directory
    already.
    """
    if os.path.exists(path) and not os.path.isdir(path):
        path = os.path.dirname(path)
    return path

def dirs(path):
    """
    List directories in supplied path
    """
    path = directory(path)
    return (f for f in os.listdir(path)
            if os.path.isdir(os.path.join(path, f)))

def allnamesequal(name):
    return all(n == name[0] for n in name[1:])

def commonprefix(paths, sep=os.path.sep):
    """
    Due to a bug in os.path.commonprefix implementation, we use this instead
    """
    bydirectorylevels = zip(*[p.split(sep) for p in paths])
    return sep.join(x[0] for x in takewhile(allnamesequal, bydirectorylevels))

def find_subpath(src, dst):
    srcdir, substring = os.path.split(src)
    common_prefix = commonprefix([src, dst])
    srcdir = srcdir[len(common_prefix):]
    if dst in src:
        # search left to right
        # skip the very first directory (otherwise pointless)
        searchlist = splitpath(srcdir)[1:]
        ltr = True
    else:
        # search right to left
        searchlist = reversed(splitpath(srcdir))
        ltr = False
    for destdir in searchlist:
        if destdir in dirs(dst):
            if ltr:
                pos = src[src.find(destdir):]
                substring = src[pos:]
                break
            else:
                pos = src.rfind(destdir)
                substring = src[pos:]
    return substring

class paste_subtree(Command):
    """
    :paste_subree

    Paste from copy_buffer to current directory. Try to find the common subpath
    and preserve as much of the original directory structure as possible
    """

    def reload_dir(self, dst):
        dst = self.fm.get_directory(dst)
        dst.unload()
        dst.load_content()

    def execute(self):
        dst = str(self.fm.thisdir)
        try:
            for src in (str(p) for p in self.fm.copy_buffer):
                paste_subtree_call(self.fm, src, dst)
                self.reload_dir(dst)
        finally:
            self.fm.copy_buffer.clear()
            self.fm.cut_buffer = False

def paste_subtree_call(fm, src, dst):
    """
    # cd dstdir
    # rsync -Ravz a/b/c/d.ext /home/username/Documents
    # rsync ^args ^relpath    ^dstdir
    # cd -
    """

    src = fullpath(src)
    if not os.path.exists(src):
        raise OSError('[ERROR] not found: {}'.format(src))

    subpath = find_subpath(src, dst)
    chdir = src[:-len(subpath)]

    # # DEBUG:
    result = os.path.join(dst, subpath)
    fm.notify(' chdir: {}'.format(chdir))
    fm.notify('subpth: {}{}'.format(' ' * (len(chdir)), subpath))
    fm.notify('   src: {}'.format(src))
    fm.notify('   dst: {}'.format(dst))
    fm.notify('result: {}'.format(result))

    # FIXME: this fails with ' i paths
    command = "cd '{chdir}' && rsync -Ravz '{subpath}' '{dst}' ; cd -".format(
        chdir=chdir,
        subpath=subpath,
        dst=dst)
    fm.notify(command)
    proc = fm.execute_command(command, stdout=subprocess.PIPE)
    stdout, stderr = proc.communicate()
    if stdout:
        for line in reversed(stdout.decode().split('\n')):
            fm.notify('rsync: {}'.format(line))
    if stderr:
        fm.notify(stderr.decode(), bad=True)

def hook_init(fm):
    fm.commands.commands['paste_subtree'] = paste_subtree
    return old_hook_init(fm)

ranger.api.hook_init = hook_init


#!/usr/bin/env python

import rospy
import sys
import tf
# from control_msgs.msg import GripperCommandAction
from giskardpy.python_interface import GiskardWrapper
from giskardpy.utils_constraints import Utils
from geometry_msgs.msg import PoseStamped, Point, Quaternion
from iai_naive_kinematics_sim.srv import SetJointState, SetJointStateRequest, SetJointStateResponse  # comment this line
from sensor_msgs.msg import JointState
import numpy as np
from tf.transformations import quaternion_about_axis
import tf2_ros
import tf2_geometry_msgs
from giskardpy.qp_problem_builder import SoftConstraint
from collections import OrderedDict
from geometry_msgs.msg import Vector3Stamped, Vector3
from rospy_message_converter.message_converter import convert_dictionary_to_ros_message
from giskardpy import constraints as cnst
from giskardpy import god_map as gm
from giskardpy import tfwrapper as tf_wrapper
from giskardpy import symbolic_wrapper as w
from urdf_parser_py.urdf import URDF
import math
import yaml
from giskardpy import utils_constraints as uc
from giskardpy.tfwrapper import lookup_pose, pose_to_kdl, np_to_kdl, kdl_to_pose
import actionlib
from control_msgs.msg import GripperCommandAction, GripperCommandGoal
from pr2_controllers_msgs.msg import Pr2GripperCommandAction, Pr2GripperCommandActionGoal, Pr2GripperCommandGoal

class MotionTaskWithConstraint:
    """
    the class helps to select the necessary constraints, to select the gripper and to check the orientation of the base.
    """
    # list of Gripper
    _list_grippers = []
    # Torso of robot
    _torso = ""
    # Reference frame to basefootprint
    _origin = ""
    # goal frame
    _goal = ""

    def __init__(self):
        print("MotionTaskWithConstraint is initialized !")
        self._giskard = GiskardWrapper()

        rospy.logout("- Set pose kitchen")
        kitchen_pose = tf_wrapper.lookup_pose("map", "iai_kitchen/world")
        kitchen_pose.header.frame_id = "map"
        # setup kitchen
        rospy.logout("- Get urdf")
        self.urdf = rospy.get_param("kitchen_description")
        self.parsed_urdf = URDF.from_xml_string(self.urdf)
        self.config_file = None

        rospy.logout("- clear urdf and add kitchen urdf")
        self._giskard.clear_world()
        self._giskard.add_urdf(name="kitchen", urdf=self.urdf, pose=kitchen_pose, js_topic="kitchen/cram_joint_states")

    def set_gripper_for_real_roboter(self):
        # setup gripper as actionlib
        self.rgripper = actionlib.SimpleActionClient('r_gripper/gripper_command', GripperCommandAction)
        self.lgripper = actionlib.SimpleActionClient('l_gripper/gripper_command', GripperCommandAction)
        self.rgripper.wait_for_server()
        self.lgripper.wait_for_server()

    def r_action_gripper(self, value=0):
        goal = Pr2GripperCommandGoal() #GripperCommandGoal()
        goal.command.position = value
        goal.command.max_effort = 40
        self.rgripper.send_goal_and_wait(goal)

    def l_action_gripper(self, value=0):
        goal = Pr2GripperCommandGoal() #GripperCommandGoal()
        goal.command.position = value
        goal.command.max_effort = 40
        self.lgripper.send_goal_and_wait(goal)

    def execute_open_translational_motion_on_real_robot(self, goal, body, action, joint, joint_value):
        self.r_action_gripper(0.08)
        self.l_action_gripper(0.08)
        self._giskard.set_json_goal("MoveToPoseConstraint", goal_name=goal, body_name=body)
        self._giskard.allow_all_collisions()
        self._giskard.plan_and_execute()
        self.r_action_gripper(0.012)
        self.l_action_gripper(0.012)
        self._giskard.set_json_goal("OpenCloseDrawerConstraint", goal_name=goal, body_name=body, action=action)
        self._giskard.allow_all_collisions()
        # self.giskard.avoid_all_collisions()
        self._giskard.plan_and_execute()
        self._giskard.set_object_joint_state(object_name='kitchen',
                                             joint_states={joint: joint_value})

    def execute_close_translational_motion_on_real_robot(self, goal, body, action, joint, joint_value):
        self.r_action_gripper(0.08)
        self.l_action_gripper(0.08)
        self._giskard.set_json_goal("MoveToPoseConstraint", goal_name=goal, body_name=body)
        self._giskard.allow_all_collisions()
        self._giskard.plan_and_execute()
        self._giskard.set_json_goal("OpenCloseDrawerConstraint", goal_name=goal, body_name=body, action=action)
        self._giskard.allow_all_collisions()
        # self.giskard.avoid_all_collisions()
        self._giskard.plan_and_execute()
        self._giskard.set_object_joint_state(object_name='kitchen',
                                             joint_states={joint: joint_value})

    def execute_open_circular_motion_on_real_robot(self, goal, body, action, joint, joint_value):
        self.r_action_gripper(0.08)
        self.l_action_gripper(0.08)
        self._giskard.set_json_goal("MoveToPoseConstraint", goal_name=goal, body_name=body)
        self._giskard.allow_all_collisions()
        self._giskard.plan_and_execute()
        self.r_action_gripper(0.012)
        self.l_action_gripper(0.012)
        self._giskard.set_json_goal("OpenCloseDoorConstraint", goal_name=goal, body_name=body, action=action)
        self._giskard.allow_all_collisions()
        # self.giskard.avoid_all_collisions()
        self._giskard.plan_and_execute()
        self._giskard.set_object_joint_state(object_name='kitchen',
                                             joint_states={joint: joint_value})

    def execute_close_circular_motion_on_real_robot(self, goal, body, action, joint, joint_value):
        self.r_action_gripper(0.08)
        self.l_action_gripper(0.08)
        self._giskard.set_json_goal("MoveToPoseConstraint", goal_name=goal, body_name=body)
        self._giskard.allow_all_collisions()
        self._giskard.plan_and_execute()
        self._giskard.set_json_goal("OpenCloseDoorConstraint", goal_name=goal, body_name=body, action=action)
        self._giskard.allow_all_collisions()
        # self.giskard.avoid_all_collisions()
        self._giskard.plan_and_execute()
        self._giskard.set_object_joint_state(object_name='kitchen',
                                             joint_states={joint: joint_value})

    def execute_open_rotational_motion_on_real_robot(self, goal, body, action, joint, joint_value):
        self.r_action_gripper(0.08)
        self.l_action_gripper(0.08)
        self._giskard.set_json_goal("MoveToPoseConstraint", goal_name=goal, body_name=body)
        self._giskard.allow_all_collisions()
        self._giskard.plan_and_execute()
        self.r_action_gripper(0.012)
        self.l_action_gripper(0.012)
        self._giskard.set_json_goal("TurnRotaryKnobConstraint", goal_name=goal, body_name=body, action=action)
        self._giskard.allow_all_collisions()
        # self.giskard.avoid_all_collisions()
        self._giskard.plan_and_execute()
        self._giskard.set_object_joint_state(object_name='kitchen',
                                             joint_states={joint: joint_value})

    def execute_close_rotational_motion_on_real_robot(self, goal, body, action, joint, joint_value):
        self.r_action_gripper(0.08)
        self.l_action_gripper(0.08)
        self._giskard.set_json_goal("MoveToPoseConstraint", goal_name=goal, body_name=body)
        self._giskard.allow_all_collisions()
        self._giskard.plan_and_execute()
        self._giskard.set_json_goal("TurnRotaryKnobConstraint", goal_name=goal, body_name=body, action=action)
        self.giskard.allow_all_collisions()
        # self.giskard.avoid_all_collisions()
        self.giskard.plan_and_execute()
        self._giskard.set_object_joint_state(object_name='kitchen',
                                            joint_states={joint: joint_value})

    def setup_orientation_basis(self, basis_frame="odom_combined", torso="torso_lift_link",
                                list_grippers=["r_gripper_tool_frame", "l_gripper_tool_frame"]):
        """
        This method set the parameter for the orientations verification of the basis
        :param basis_frame: origin frame to the basis
        :type: str
        :param torso: torso of robot
        :type: str
        :param list_grippers: List of gripper
        :type: array of str
        :return:
        """
        self._list_grippers = list_grippers
        self._torso = torso
        self._origin = basis_frame

    def set_goal(self, goal=""):
        """
        set the goal in relation to which the base is to be oriented
        :param goal: goal
        :type: str
        :return:
        """
        self._goal = goal

    def update_basis_orientation(self):
        """
        This function update the orientation of the basis and get the next Gripper in short distance from goal
        :return:
        """
        x, y, r = self.get_current_base_position()
        rospy.logout("The basis is at position :")
        rospy.logout(x)
        rospy.logout(y)
        rospy.logout(r)
        # get pose torso
        pose_torso = tf_wrapper.lookup_pose(self._origin, self._torso)
        # get pose goal
        pose_goal = tf_wrapper.lookup_pose(self._origin, self._goal)
        # get list of pose of gripper
        list_pose_gripper = [tf_wrapper.lookup_pose(self._origin, p) for p in self._list_grippers]
        # get angle to G
        angle = [float(w.get_angle_casadi(self.get_x_y(pose_torso), self.get_x_y(pose_goal), self.get_x_y(p)))
                 for p in list_pose_gripper]
        # max angle G to goal
        max_angle = np.amax(angle)
        rospy.logout("Max angle is :")
        rospy.logout(max_angle)
        # update old and new orientation
        max_angle = r + max_angle
        rospy.logout("Max angle + r is :")
        rospy.logout(max_angle)
        # get selected Gripper
        gripper = np.where(np.array(angle) == np.amax(angle))
        rospy.logout("Farther away Gripper:")
        rospy.logout(gripper[0][0])
        # convert angle in axis
        q = w.quaternion_from_axis_angle([0, 0, 1], max_angle)
        # update basis orientation
        #self.set_cart_goal_for_basis(x, y, 0, q)

    #@staticmethod
    def get_x_y(self, pose):
        return [pose.pose.position.x, pose.pose.position.y, 0]

    def get_current_base_position(self):
        """
        the method check the current pose of base_footprint to odom and get it
        :return: x, y, rotation
        """
        basis = tf_wrapper.lookup_pose(self._origin, "base_footprint")
        t, r = [basis.pose.position.x, basis.pose.position.y, basis.pose.position.z], \
               [basis.pose.orientation.x, basis.pose.orientation.y, basis.pose.orientation.z,
                basis.pose.orientation.w]  # self.get_msg_translation_and_rotation(self._basis, "map")
        return self.base_position(t, r)

    def base_position(self, translation, rotation):
        """
        the method take the translation and rotation from tf_ros and calculate the rotation in euler
        :param translation: vector
        :param rotation: quaternion (from tf_ros)
        :return: vector[x, y, rotation], current base position
        """
        euler = tf.transformations.euler_from_quaternion(rotation)
        return translation[0], translation[1], euler[2]

    def set_cart_goal_for_basis(self, x, y, z, q):
        """
        this function send goal to the basis of robot
        :param x: position on x axis
        :type: float
        :param y: position on y axis
        :type: float
        :param z: position on z axis
        :type: float
        :param q: quaternion orientation
        :type: array float
        :return:
        """
        # take base_footprint
        poseStamp = lookup_pose(self._origin, "base_footprint")
        poseStamp.header.frame_id = self._origin
        # set goal pose
        poseStamp.pose.position.x = x
        poseStamp.pose.position.y = y
        poseStamp.pose.position.z = z
        poseStamp.pose.orientation.x = q[0]
        poseStamp.pose.orientation.y = q[1]
        poseStamp.pose.orientation.z = q[2]
        poseStamp.pose.orientation.w = q[3]
        self._giskard.set_cart_goal(self._origin, "base_footprint", poseStamp)
        self._giskard.avoid_all_collisions()
        self._giskard.plan_and_execute()

    def reset_kitchen(self, list_joints):
        for j in list_joints:
            self._giskard.set_object_joint_state(object_name='kitchen',
                                                 joint_states={j: 0.0})

if __name__ == '__main__':
    rospy.init_node('do_test_constraint')
    list_joint = [
        "sink_area_trash_drawer_main_joint",
        "sink_area_left_upper_drawer_main_joint",
        "sink_area_left_middle_drawer_main_joint",
        "sink_area_left_bottom_drawer_main_joint",
        "sink_area_dish_washer_main_joint",
        "sink_area_dish_washer_door_joint",
        "oven_area_oven_door_joint",
        "oven_area_oven_knob_stove_1_joint",
        "oven_area_oven_knob_stove_2_joint",
        "oven_area_oven_knob_stove_3_joint",
        "oven_area_oven_knob_stove_4_joint",
        "oven_area_oven_knob_oven_joint",
        "oven_area_area_middle_upper_drawer_main_joint",
        "oven_area_area_middle_lower_drawer_main_joint",
        "oven_area_area_left_drawer_main_joint",
        "oven_area_area_right_drawer_main_joint",
        "kitchen_island_left_upper_drawer_main_joint",
        "kitchen_island_left_lower_drawer_main_joint",
        "kitchen_island_middle_upper_drawer_main_joint",
        "kitchen_island_middle_lower_drawer_main_joint",
        "kitchen_island_right_upper_drawer_main_joint",
        "kitchen_island_right_lower_drawer_main_joint",
        "fridge_area_lower_drawer_main_joint",
        "iai_fridge_door_joint"
    ]
    rospy.logout("START SOME MOVE as Test")
    mc = MotionTaskWithConstraint()
    mc.set_gripper_for_simulator()
    # fridge door
    #mc.execute_open_circular_motion_on_real_robot('iai_kitchen/iai_fridge_door_handle', 'r_gripper_tool_frame', 0.5,
                                                 #'iai_fridge_door_joint', 0.758)
    #mc.execute_close_circular_motion_on_real_robot('iai_kitchen/iai_fridge_door_handle', 'r_gripper_tool_frame', -0.5,
                                                  #'iai_fridge_door_joint', 0.0)

    #mc.reset_kitchen(list_joint)

    # kitchen_island_left_upper_drawer
    #mc.execute_open_translational_motion_on_real_robot("iai_kitchen/kitchen_island_left_upper_drawer_handle",
                                                      #"r_gripper_tool_frame", 1,
                                                      #"kitchen_island_left_upper_drawer_main_joint", 0.48)
    #mc.execute_close_translational_motion_on_real_robot("iai_kitchen/kitchen_island_left_upper_drawer_handle",
                                                       #"r_gripper_tool_frame", -1,
                                                       #"kitchen_island_left_upper_drawer_main_joint", 0.0)
    #mc.reset_kitchen(list_joint)

    # iai_kitchen/oven_area_oven_door_handle
    #mc.execute_open_circular_motion_on_real_robot('iai_kitchen/oven_area_oven_door_handle', 'l_gripper_tool_frame', -1,
                                                 #'oven_area_oven_door_joint', 1.57)
    #mc.execute_close_circular_motion_on_real_robot('iai_kitchen/oven_area_oven_door_handle', 'l_gripper_tool_frame', 1,
                                                  #'oven_area_oven_door_joint', 0.0)
    #mc.reset_kitchen(list_joint)

    # iai_kitchen/sink_area_dish_washer_door_handle
    mc.execute_open_circular_motion_on_real_robot('iai_kitchen/sink_area_dish_washer_door_handle',
                                                 'r_gripper_tool_frame',
                                                 -0.5, 'sink_area_dish_washer_door_joint', 0.758)
    mc.execute_close_circular_motion_on_real_robot('iai_kitchen/sink_area_dish_washer_door_handle',
                                                  'r_gripper_tool_frame',
                                                  0.5, 'sink_area_dish_washer_door_joint', 0)
    #mc.reset_kitchen(list_joint)

    # iai_kitchen/sink_area_left_middle_drawer_handle
    #mc.execute_open_translational_motion_on_real_robot('iai_kitchen/sink_area_left_middle_drawer_handle',
                                                      #'r_gripper_tool_frame', -1,
                                                      #'sink_area_left_middle_drawer_main_joint', 0.48)
    #mc.execute_close_translational_motion_on_real_robot('iai_kitchen/sink_area_left_middle_drawer_handle',
                                                       #'r_gripper_tool_frame', 1,
                                                       #'sink_area_left_middle_drawer_main_joint', 0.0)
    #mc.reset_kitchen(list_joint)

    # iai_kitchen/oven_area_oven_knob_stove_4
    #mc.execute_rotational_motion_on_real_robot('iai_kitchen/oven_area_oven_knob_stove_4', 'l_gripper_tool_frame', -1,
                                              #"oven_area_oven_knob_stove_4_joint", 1.57)

    # set_cart_goal_test()
    rospy.spin()


import logbook
import re
import requests
import requests.exceptions
import sys
import time

# LOGGING #
app_log = logbook.Logger('Movie Query App')

URL = 'http://movie_service.talkpython.fm/api/search/'

def get_query() -> str:
    user_query = input('What movie do you want to search for?: ')
    if not user_query or not user_query.strip():
        raise ValueError('Please enter search text.')
    return user_query

def get_movie_titles(search_query : str) -> list:
    try:
        # LOGGING #
        # start time of query
        start_time = time.time()
        app_log.trace(f'Starting search for query: {search_query}')

        response = requests.get(URL + search_query)

        # LOGGING #
        # log response status code
        app_log.trace(f'Request over with status code {response.status_code}')

        title_pattern = re.compile(r"\"title[\"\:\s]+([\w\s\-'\.]+)")
        title_search = title_pattern.findall(response.text)

        year_pattern = re.compile(r"\"year[\"\:\s]+(\d*)\,")
        year_search = year_pattern.findall(response.text)

        if not title_search:
            raise ValueError('No movie found')

        movie_list = zip(year_search, title_search)
        year_movie_list = sorted(movie_list, key=lambda x: x[0], reverse=True)

        # LOGGING #
        # time required for query completion
        end_time = time.time()
        app_log.trace(f'Finished search for query: {search_query}: ' + \
                f'{len(year_movie_list)} results in {int((end_time - start_time) * 1000)} ms')

        return year_movie_list

    except requests.exceptions.ConnectionError:
        raise ConnectionError('Your network is down')

def main():
    try:
        user_query = get_query()
        movie_list = get_movie_titles(user_query)
        for year, movie in movie_list:
            print(f'{year}: {movie}')
    except Exception as e:
        e_class = e.__class__.__name__
        e_msg = str(e)

        # LOGGING #
        # WARN if ConnectionError or ValueError
        if e_class == 'ConnectionError' or e_class == 'ValueError':
            app_log.warn(e_msg)
        else:
            app_log.exception(e_msg)

        print(e_msg)

# LOGGING #
def init_logging(filename=None):
    level = logbook.TRACE

    # new logfile if date change
    if filename:
        handler = logbook.TimedRotatingFileHandler(filename, level=level)
    else:
        handler = logbook.StreamHandler(sys.stdout, level=level)
    handler.push_application()

    if filename:
        msg = f'Logging initialized, level: {level}, mode: file_mode: {filename}'
    else:
        msg = f'Logging initialized, level: {level}, mode: stdout_mode'
    logger = logbook.Logger('Startup')
    logger.notice(msg)

if __name__=='__main__':
    # LOGGING #
    init_logging('movie-query.log')

    main()


import pandas as pd
from sklearn.metrics import confusion_matrix
from sklearn.tree import DecisionTreeClassifier

if __name__ == "__main__":
    train_data = pd.read_csv("train.csv", sep=',', header=0)
    train_features = train_data.values[:, 0:8]
    train_outcome = train_data.values[:, 8]
    decision_tree = DecisionTreeClassifier(criterion="entropy", min_samples_split=9, class_weight={1: 4, 0: 1})
    decision_tree.fit(train_features, train_outcome)
    test_data = pd.read_csv("test.csv", sep=',', header=0)
    test_features = test_data.values[:, 0:8]
    test_real_outcome = test_data.values[:, 8]
    test_outcome = decision_tree.predict(test_features)
    print(confusion_matrix(test_real_outcome, test_outcome))


#A palindromic number reads the same both ways.
# The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
#Find the largest palindrome made from the product of two 3-digit numbers.
def palindromics_six_3dig_prod():
    limit = 998001 # 999*999
    for i in range(limit,1,-1):
        palind_numb = str(i)
        group1 = palind_numb[0] == palind_numb[-1]
        group2 = palind_numb[1] == palind_numb[-2]
        group3 = palind_numb[2] == palind_numb[-3]
        if (group1 and group2) and group3:
            for j in range(999,100,-1):
                if i%j == 0:
                    factor = i/j
                    if (factor > 99) and (factor < 1000):
                        return i
print(palindromics_six_3dig_prod())


# -*- coding:utf-8 -*-

from threading import Thread
import multiprocessing
import time
import subprocess
import sys

from function import console

class MinecraftServerProcess(multiprocessing.Process):
    ''' MinecraftServerProcess '''
    def __init__(self,servername,cwd,run_command):
        multiprocessing.Process.__init__(self)
        self.servername = servername
        self.console_queue = None
        self.subproc = None
        self.run_command = run_command
        self.console_code = 'gbk'
        self.subexit = False
        self.cwd = cwd

    def command_queue(self):
        '''
        服务器进程 通信获取
        通过这个来管理中心可以自由的压入任务到队列，其中的一个线程会进行处理
        '''
        self.command_queue = multiprocessing.Queue()
        return self.command_queue

    def set_cosole_queue(self,queue):
        self.console_queue = queue

    def _command_thread_loop(self):
        ''' 此线程负责读入命令 管理中心 发来的命令 '''
        while self.subexit == False:
            command = self.command_queue.get()
            if command['command'] == 'exec':
                subproc_command = command['msg'] + '\r\n'
                self.subproc.stdin.write(subproc_command.encode(self.console_code))
                self.subproc.stdin.flush()

            if command['command'] == 'exit':
                self.subexit = True
                break
        console.log(-1,'[',self.servername,'] 服务器 command_thread_loop 线程回收')

    def _console_thread_loop(self):
        ''' 此线程负责写入控制台到 管理中心 的队列 '''
        while self.subexit == False:
            #读取 Minecraft 子进程 stdout
            output = self.subproc.stdout.readline()
            output = output.decode(self.console_code)
            #output = output.strip('\n').strip('\r\n')
            if not output:
                self.subexit = True
                self.command_queue.put({'command':'exit'})
                break
            if output != '' or len(output) > 1:
                self.console_queue.put({
                    'servername' : self.servername,
                    'command'    : 'console',
                    'msg'        : output
                })

        console.log(-1,'[',self.servername,'] 服务器 console_thread_loop 线程回收')

    def run(self):
        console.log(-1,'[',self.servername,'] 服务器 MinecraftServerProcess 进程开启')
        #创建命令读取线程
        self.subproc = subprocess.Popen(
            self.run_command,
            cwd = self.cwd,
            stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr = subprocess.PIPE,
            shell=True
            )
        self._command_thread_loop = Thread(target=self._command_thread_loop)
        self._console_thread_loop = Thread(target=self._console_thread_loop)
        self._command_thread_loop.start()
        self._console_thread_loop.start()
        self._console_thread_loop.join()
        self._command_thread_loop.join()
        self._server_exit_event()
        console.log(-1,'[',self.servername,'] 服务器 MinecraftServerProcess 进程回收')
        # exit(0)

    def _server_exit_event(self):
        self.console_queue.put({
                    'servername' : self.servername,
                    'command'    : 'close',
                })

class MinecraftServer(MinecraftServerProcess):
    ''' MinecraftServerProcess '''
    def __init__(self,servername,cwd,run_command,premssion_dict={}):
        super().__init__(servername,cwd,run_command)
        self.start_time = time.time()
        self.start_time_str = time.strftime('%Y-%m-%d %H:%M:%I',time.localtime(self.start_time))
        self._permission = premssion_dict

    def get_run_time(self):
        now = time.time()
        all_time = now - self.start_time
        return round(all_time)
        #return time.strftime('%Y-%m-%d %H:%M:%I',time.localtime(all_time))

    def get_start_time_str(self):
        return self.start_time_str

    def edit_user_premssion(self,username,premssion_dict):
        '''
        premssion_dict
        {'PlayerName':{
            'view' : True ,     #查看服务器界面权限
            'command' : True,   #向服务器发送命令权限
            'button' : True,      #控制服务器开关 开启 关闭 重启 强制 权限
        }}
        '''
        self._permission[username] = premssion_dict

    def get_info(self):
        ''' 获取这个 Minecraft 服务器的所有显示信息 '''
        return {
            'servername' : self.servername,
            'start_time' : self.start_time_str,
            'run_time'   : self.get_run_time(),
            'cwd'        : self.cwd,
            'subexit'    : self.subexit,
            'run_command': self.run_command,
            'permission' : self._permission
        }


import datetime
""" from rest_framework.serializers import ValidationError
from .utils import * """

class ValidationUtils:
    @staticmethod
    def list_duplicates(seq):
        seen = set()
        seen_add = seen.add
        # adds all elements it doesn't know yet to seen and
        # all other to seen_twice
        seen_twice = set(x for x in seq if x in seen or seen_add(x))
        # turn the set into a list (as requested)
        return list(seen_twice)

    @staticmethod
    def Find_Duplicates(fields_data, field_name, strType, usesForeignKey):
        strCombinedErrorMessage = None
        field_names = []
        for field_data in fields_data:
            str_data = field_data[field_name]
            if usesForeignKey is True:
                field_names.append(str_data.id)
            else:
                field_names.append(str_data)
        field_dupes = ValidationUtils.list_duplicates(field_names)
        if field_dupes is not None:
            if len(field_dupes) > 0:
                strErrorMessage = '[' + ','.join(map(str, field_dupes)) + '].'
                strCombinedErrorMessage = "Following duplicate " + field_name \
                                          + " found " + strErrorMessage + \
                                          " Duplicate " + field_name + \
                                          " not allowed within " + strType
        return strCombinedErrorMessage

    @staticmethod
    def IsValidField(oRiskFieldData):
        strErrorMessage = None

        # Check if
        if(oRiskFieldData is None):
            strErrorMessage = "riskfield is not found. Post valid riskfield"
        # print("In ValidationUtil IsValidField")
        # print(oRiskFieldData)
        if oRiskFieldData.risk_type_field_enum == "integer":
            bIsInteger = ValidationUtils.isanumber(
                        oRiskFieldData.risk_field_value)
            if bIsInteger is False:
                strErrorMessage = oRiskFieldData.risk_type_field_name + \
                                  " configured as " + \
                                  oRiskFieldData.risk_type_field_enum + \
                                  " This field must be valid integer."

        elif (oRiskFieldData.risk_type_field_enum == "number" or
              oRiskFieldData.risk_type_field_enum == "currency"):
            bIsNumber = ValidationUtils.isanumber(
                         oRiskFieldData.risk_field_value)
            if bIsNumber is False:
                strErrorMessage = oRiskFieldData.risk_type_field_name + \
                                 " configured as " + \
                                 oRiskFieldData.risk_type_field_enum + \
                                 " This field must be an real number."

        elif oRiskFieldData.risk_type_field_enum == "date":
            bIsDate = ValidationUtils.isadate(
                        oRiskFieldData.risk_field_value)
            if bIsDate is False:
                strErrorMessage = oRiskFieldData.risk_type_field_name + \
                 " configured as " + \
                 oRiskFieldData.risk_type_field_enum + \
                 " Enter date in MM/dd/yyyy format"

        elif oRiskFieldData.risk_type_field_enum == "string":
            bIsString = ValidationUtils.isastring(
                          oRiskFieldData.risk_field_value)
            if bIsString is False:
                strErrorMessage = oRiskFieldData.risk_type_field_name + \
                  " configured as " + \
                  oRiskFieldData.risk_type_field_enum + \
                  " Enter valid string"
        # print(strErrorMessage)
        return strErrorMessage

    @staticmethod
    def isanumber(inp):
        try:
            val = int(inp)
            return True
        except ValueError:
            try:
                val = float(inp)
                return True
            except ValueError:
                return False

    @staticmethod
    def isadate(inp):
        try:
            month, day, year = inp.split('/')
            isValidDate = True
            datetime.datetime(int(year), int(month), int(day))
        except ValueError:
            isValidDate = False
        return isValidDate

    @staticmethod
    def isastring(inp):
        isValidString = bool(inp and inp.strip())
        return isValidString


# -*- coding: utf-8 -*-
# @Time    : 2019/7/17 12:32
# @Author  : Valette
# @Email   : foxmail
# @File    : present.py
# @Software: PyCharm

# 模块功能：
# 数据可视化
import numpy as np
import json
from pyecharts.charts import BMap
from pyecharts import options as opts
from pyecharts.charts import Geo

from mysql_connection import cur, conn
from Config import json_file, BAIDU_AK

def get_pie_type(sql_price_data, json_file) -> BMap:
    c = (
        BMap()
        .add_schema(
            baidu_ak=BAIDU_AK,
            center=[120.1222120000,36.0031470000],
            zoom = 12
        )
        .add_coordinate_json(json_file)
        .add(
            "在售楼盘",
            [[name, int(price)] for name, price in sql_price_data],
            label_opts=opts.LabelOpts(formatter="{b}"),
        )
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(title_opts=opts.TitleOpts(title="黄岛楼盘地理分布"))
    )
    return c

def get_pie_type() -> Pie:
    '''
        楼盘类型 饼状图
        :return:
        '''
    sql = "SELECT `类型` FROM `楼盘`"
    cur.execute(sql)
    data = cur.fetchall()
    x = {}
    for i in data:
        if i[0] is not None:
            if i[0] in x:
                x[i[0]] += 1
            else:
                x[i[0]] = 1

    c = (
        Pie()
            .add("", [(k,x[k]) for k in x.keys()])
            .set_global_opts(title_opts=opts.TitleOpts(title="Pie-楼盘类型"))
            .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
    )
    return c

def geo_distribution():
    cur.execute("SELECT `楼盘名称`, `参考单价`FROM `楼盘` WHERE `坐标` IS NOT NULL AND `参考单价` IS NOT NULL")
    sql_price_data = cur.fetchall()
    map = get_bmap_geo(sql_price_data, json_file)
    map.render("outputs/地理分布.html")

def type_distribution():
    diagram = get_pie_type()
    diagram.render("outputs/楼盘类型分布.html")

if __name__ == '__main__':
    # price_tendence()
    # type_pie()
    geo_distribution()
    type_distribution()
    # cur.close()
    # conn.close()


import plotly.figure_factory as ff
import plotly.graph_objects as go
import statistics
import random
import pandas as pd
import csv

df=pd.read_csv("D:/C-111/data1.csv")
data=df["Math_score"].tolist()

#Plotting the Graph
#fig=ff.create_distplot([data],["Math Scores"],show_hist=False)
#fig.show()

#Calculating the Mean and Standard Deviation of The Population Data
mean=statistics.mean(data)
std_deviation=statistics.stdev(data)

print("Mean of Population --> ",mean)
print("Standard Devaition of Population --> ",std_deviation)

def random_set_of_mean(counter):
    dataset=[]
    for i in range(0,counter):
        random_index=random.randint(0,len(data)-1)
        value=data[random_index]
        dataset.append(value)
    mean=statistics.mean(dataset)
    return mean

#Pass the number of time you want the mean of data points as a parameter in range function in for loop
mean_list=[]
for i in range(0,1000):
    set_of_means=random_set_of_mean(100)
    mean_list.append(set_of_means)

#Calculating the mean and std_deviation of the sampling distribution
std_deviation=statistics.stdev(mean_list)
mean=statistics.mean(mean_list)

print("Mean of sampling distribution --> ",mean)

#Plotting the mean of the sampling
fig=ff.create_distplot([mean_list],["student marks"],show_hist=False)
fig.add_trace(go.Scatter(x=[mean,mean],y=[0,0.20],mode="lines",name="MEAN"))

#Finding the standard deviaitions starting and ending value
first_std_deviation_start,first_std_deviation_end=mean-std_deviation,mean+std_deviation
second_std_deviation_start,second_std_deviation_end=mean-(2*std_deviation),mean+(2*std_deviation)
third_std_deviation_start,third_std_deviation_end=mean-(3*std_deviation),mean+(3*std_deviation)

print("Std 1",first_std_deviation_start,first_std_deviation_end)
print("Std 2",second_std_deviation_start,second_std_deviation_end)
print("Std 3",third_std_deviation_start,third_std_deviation_end)

#Plotting the graph with traces

fig.show()


# Copyright 2017 Carlo Attardi
import CarboSem_JSON_converter

demo="./demo_path/"

"""
the function "make_converter()" constructs a converter
with file path as parameters (neo4jJSON pathfile, CarboSemJSON pathfile).
convert_to_carbosem() converts the input file in the output file.
"""
converter = CarboSem_JSON_converter.make_converter(demo+"neo4j_JSONs/result.json", demo+"static/json/data.json")
converter.convert_to_carbosem()

"""
manual change of attributes and conversion of the file pointed from first
into the file pointed from second (the first file is not deleted).
"""
converter.jsonDB = demo+"neo4j_JSONs/result(2).json"
converter.jsonCarboSem = demo+"static/json/data(2).json"
converter.convert_to_carbosem()

"""
the function "change_files_and_convert()" automatically changes attributes
and convert the input file into the output file.
"""
converter.change_files_and_convert(demo+"neo4j_JSONs/result(1).json", demo+"static/json/data(1).json")

"""
simple conversion of the first file into the second without creating an object.
"""
CarboSem_JSON_converter.simple_conversion(demo+"neo4j_JSONs/result(3).json", demo+"static/json/data(3).json")


from pymatgen.core import Structure
from pymatgen.analysis.magnetism.analyzer import MagneticStructureEnumerator, CollinearMagneticStructureAnalyzer
from pymatgen.io.vasp.inputs import Poscar, Incar, Kpoints
from pymatgen.io.vasp.sets import MPRelaxSet, MPStaticSet, MPSOCSet
import os

def create_job_script(out_path, job_id='JobName'):
    """
    Args:
        out_path (str)   -   folder where job script will be created.
        job_id   (str)   -   preferable name of your job in squeue,
        and also the name of the folder for your vasp files.
        As a result in the folder with name 'job_id' will be created job script
    """
    job_script_text = f"""#!/bin/bash
#SBATCH --nodes=1
#SBATCH --ntasks=8
#SBATCH --time=06:00:00
#SBATCH --job-name={job_id}
#SBATCH --output=log
#SBATCH --error=err
#SBATCH -p lenovo
module load mpi/impi-5.0.3 intel/mkl-11.2.3 vasp/vasp-5.4.4
mpirun vasp_std"""
    if not os.path.exists(out_path):
        os.mkdir(out_path)
    with open(f'{out_path}/jobscript.sh', 'w') as job:
        job.writelines(job_script_text)

def get_VASP_inputs(input_path, mag_prec=0.1, enum_prec=0.00001):
    init_structure = Structure.from_file(os.path.join(input_path, 'POSCAR'))
    enum_struct_list = MagneticStructureEnumerator(init_structure, transformation_kwargs={
                                                   'symm_prec': mag_prec, 'enum_precision_parameter': enum_prec})

    for i, magnetic_structure in enumerate(enum_struct_list.ordered_structures):
        magnetic_type = enum_struct_list.ordered_structure_origins[i]
        str_id = magnetic_type + str(i)
        vasp_out_path = os.path.join(input_path, 'vasp_inputs', str_id)
        relax_set = MPStaticSet(structure=magnetic_structure)
        relax_set.get_vasp_input().write_input(vasp_out_path)
        create_job_script(vasp_out_path, job_id=str_id)

def afm_atom_creator(in_data: list, custom_atom='Po') -> list:
    """
    Args:
        in_data (list) - list of rows from POSCAR type file.

    Add one type of "Fake" atom into the POSCAR structure.
    This allows it to be treated as an atoms with spin up and down respectively,
    thus estimate number of positive and negative contributions into the total energy.
    """
    out_data = in_data.copy()
    out_data[5] = 'Po ' + out_data[5]
    return out_data

def up_down_spin_counter(in_data: list) -> list:
    spin_down = 0
    spin_up = 0
    no_spin = 0
    for row in in_data[8:]:
        if 'spin=-' in row:
            spin_down += 1
        elif 'spin=' in row:
            spin_up += 1
        else:
            no_spin += 1
    return [spin_up, spin_down, no_spin]

def spin_row_replacer(in_data: list) -> list:
    out_data = in_data.copy()
    out_data[6] = ' '.join(str(i) for i in up_down_spin_counter(in_data)) + '\n'
    return out_data

def siman_POSCAR_writer(in_path: str, out_path: str) -> None:
    """
    Args:
        in_path  (str)  -   path to the POSCAR type file which needs to be made
                            readable for siman
        out_path (str)  -   path where refactored version of this file will be
                            written
    """
    with open(in_path) as in_f:
        in_data = in_f.readlines()

    out_data = spin_row_replacer(afm_atom_creator(in_data))

    with open(out_path, 'w+') as out_f:
        out_f.writelines(out_data)

def get_siman_inputs(input_path: str):
    out_path = os.path.join(input_path, 'siman_inputs')
    if not os.path.exists(out_path):
        os.mkdir(out_path)
    vasp_inputs_path = os.path.join(input_path, 'vasp_inputs')
    afm_foldrs = [os.path.join(vasp_inputs_path, i)
                  for i in [i for i in os.listdir(vasp_inputs_path) if 'afm' in i]]
    for folder in afm_foldrs:
        tmp_out_path = os.path.join(out_path, 'POSCAR_' + folder.split("/")[-1])
        siman_POSCAR_writer(in_path=os.path.join(folder, 'POSCAR'), out_path=tmp_out_path)

def submit_all_jobs(input_folder: str) -> None:
    vasp_inputs_path = os.path.join(input_folder, 'vasp_inputs')
    initial_path = os.getcwd()
    for folder_name in os.listdir(vasp_inputs_path):
        os.chdir(initial_path)
        tmp_path = os.path.join(vasp_inputs_path, folder_name)
        os.chdir(tmp_path)
        os.system('sbatch jobscript.sh')
    os.chdir(initial_path)

def main_runner(input_path):
    assert os.path.exists(input_path), f'Input path: {input_path} does not exist!'
    assert os.path.exists(os.path.join(input_path, 'POSCAR')
                          ), f'Please specify POSCAR file in you input folder: {input_path}'
    get_VASP_inputs(input_path=input_path)
    get_siman_inputs(input_path=input_path)
    submit_all_jobs(input_path)

if __name__ == '__main__':
    input_path = input('Specifie your input folder: ')
    main_runner(input_path)


from chroniclepy.chroniclepy import summarising, preprocessing, subsetting
from argparse import ArgumentParser
import pandas as pd
import unittest
import shutil
import yaml
import os

class PreprocessingOutputTest(unittest.TestCase):

    def test_preprocessing(self):
        print("Test preprocessing simple")
        preprocessing.preprocess_folder(
            infolder='resources/rawdata',
            outfolder='resources/preprocessed'
        )
        self.assertTrue(True)

    def test_output(self):
        print("Test preprocessing output")

        directory = '.'

        # preprocessed
        files = {
            "preprocessing": {
                "expected": os.path.join(
                    directory,
                    'resources/constants/constants_preprocessed.yaml'
                ),
                "encountered": os.path.join(
                    directory,
                    'resources/preprocessed/ChronicleData_preprocessed-TestParticipant.csv'
                ),
                "folder": os.path.join(directory, "resources/preprocessed")
            },
            "summarising": {
                "expected": os.path.join(
                    directory,
                    'resources/constants/constants_summary.yaml'
                ),
                "encountered": os.path.join(
                    directory,
                    'resources/output/summary_daily.csv'
                ),
                "folder": os.path.join(directory, "resources/output")
            }
        }

        for keyword in files.keys():

            print("Testing pipeline for %s"%keyword)

            with open(files[keyword]['expected'], 'r') as outfile:
                expected_output = yaml.safe_load(outfile)

            encountered_output = pd.read_csv(files[keyword]['encountered']).to_dict()
            if not encountered_output == expected_output:
                print("    There are files with different values !!")
                for key, value in expected_output.items():
                    if value != encountered_output[key]:
                        print("        Difference for %s: %s vs. %s"%(key, str(value[0]), str(encountered_output[key][0])))

                raise ValueError("    This isn't right !")
            else:
                print("    Test successful...")
                shutil.rmtree(files[keyword]['folder'])

if __name__ == '__main__':
    unittest.main()