软工实践寒假作业(2/2)

这个作业属于哪个课程 2020春W班 (福州大学)
这个作业要求在哪里 寒假作业(2/2)——疫情统计
这个作业的目标 开发一个疫情统计程序
作业正文 ....
其他参考文献

一、Github地址

https://github.com/ideaflyit/InfectStatistic-main

二、PSP

PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟)
Planning 计划 30 40
Estimate 估计这个任务需要多少时间 20 30
Development 开发 1800 1680
Analysis 需求分析 (包括学习新技术) 480 300
Design Spec 生成设计文档 60 40
Design Review 设计复审 10 10
Coding Standard 代码规范 (为目前的开发制定合适的规范) 60 30
Design 具体设计 60 60
Coding 具体编码 1000 800
Code Review 代码复审 30 20
Test 测试(自我测试,修改代码,提交修改) 60 90
Reporting 报告 60 70
Test Report 测试报告 30 30
Size Measurement 计算工作量 20 10
Postmortem & Process Improvement Plan 事后总结, 并提出过程改进计划 30 20
合计 3750 3230

三、思路描述

拿到题目后,想法是先解析命令行参数,再根据参数处理文件。于是需要建立一个类专门存储感染的信息,文件处理也需要一个类,并用正则来处理文件日志文件的每一行。
本次还需要学习如何进行性能调优,以及单元测试。

四、实现过程

  • 总设计

在这里插入图片描述

  • 参数处理
    在这里插入图片描述用common cli 处理-data -out -log
    在这里插入图片描述用ArrayList存-province -type参数
    在这里插入图片描述解析命令行参数
    在这里插入图片描述

  • 文件处理过程
    在这里插入图片描述寻找文件列表中最大日期
    在这里插入图片描述
    比较文件日期与所给出参数的大小,将小于等于参数日期的文件加入集合中比较文件日期与所给出参数的大小,将小于等于参数日期的文件加入集合中

  • 日志处理过程
    在这里插入图片描述正则表达式处理
    在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述

五、单元测试

在这里插入图片描述
在这里插入图片描述在这里插入图片描述

public class LogHandleTest {
    @Test
    public void testCalculate() {
        LogHandle lh = new LogHandle();
        String rows = "福建 新增 感染患者 5人\\n" + "湖北 新增 感染患者 10人\\n" + "湖北 新增 疑似患者 10人\\n" + "广东 新增 疑似患者 3人\\n"
                + "福建 新增 感染患者 5人\\n" + "湖北 感染患者 流入 福建 10人\\n" + "湖北 疑似患者 流入 福建 1人\\n" + "福建 死亡 5人\\n" + "浙江 死亡 5人\\n"
                + "福建 治愈 1人\\n" + "福建 疑似患者 确诊感染 1人\\n" + "山东 疑似患者 确诊感染 1人\\n" + "福建 排除 疑似患者 5人" + "云南 排除 疑似患者 5人";
        lh.calculate(rows);
        FileHandle fh = new FileHandle();

        System.out.println(fh.ShowHm(lh.hm, null, null));

    }

    @Test
    public void testCount1() {
        LogHandle lh = new LogHandle();
        StringBuilder sb = new StringBuilder();
        String rows = "福建 新增 感染患者 5人\\n" + "湖北 新增 感染患者 10人\\n" + "湖北 新增 疑似患者 10人\\n" + "广东 新增 疑似患者 3人\\n"
                + "福建 新增 感染患者 5人\\n" + "湖北 感染患者 流入 福建 10人\\n" + "湖北 疑似患者 流入 福建 1人\\n" + "福建 死亡 5人\\n" + "浙江 死亡 5人\\n"
                + "福建 治愈 1人\\n" + "福建 疑似患者 确诊感染 1人\\n" + "山东 疑似患者 确诊感染 1人\\n" + "福建 排除 疑似患者 5人" + "云南 排除 疑似患者 5人";
        lh.count1("([\\u4e00-\\u9fa5]+) 新增 感染患者 (\\d+)人", rows);

        FileHandle fh = new FileHandle();

        System.out.println(fh.ShowHm(lh.hm, null, null));
    }

    @Test
    public void testCount2() {
        LogHandle lh = new LogHandle();
        StringBuilder sb = new StringBuilder();
        String rows = "福建 新增 感染患者 5人\\n" + "湖北 新增 感染患者 10人\\n" + "湖北 新增 疑似患者 10人\\n" + "广东 新增 疑似患者 3人\\n"
                + "福建 新增 感染患者 5人\\n" + "湖北 感染患者 流入 福建 10人\\n" + "湖北 疑似患者 流入 福建 1人\\n" + "福建 死亡 5人\\n" + "浙江 死亡 5人\\n"
                + "福建 治愈 1人\\n" + "福建 疑似患者 确诊感染 1人\\n" + "山东 疑似患者 确诊感染 1人\\n" + "福建 排除 疑似患者 5人" + "云南 排除 疑似患者 5人";
        lh.count2("([\\u4e00-\\u9fa5]+) 新增 疑似患者 (\\d+)人", rows);

        FileHandle fh = new FileHandle();

        System.out.println(fh.ShowHm(lh.hm, null, null));
    }

    @Test
    public void testCount3() {
        LogHandle lh = new LogHandle();
        StringBuilder sb = new StringBuilder();
        String rows = "福建 新增 感染患者 5人\\n" + "湖北 新增 感染患者 10人\\n" + "湖北 新增 疑似患者 10人\\n" + "广东 新增 疑似患者 3人\\n"
                + "福建 新增 感染患者 5人\\n" + "湖北 感染患者 流入 福建 10人\\n" + "湖北 疑似患者 流入 福建 1人\\n" + "福建 死亡 5人\\n" + "浙江 死亡 5人\\n"
                + "福建 治愈 1人\\n" + "福建 疑似患者 确诊感染 1人\\n" + "山东 疑似患者 确诊感染 1人\\n" + "福建 排除 疑似患者 5人" + "云南 排除 疑似患者 5人";
        lh.count3("([\\u4e00-\\u9fa5]+) 感染患者 流入 ([\\u4e00-\\u9fa5]+) (\\d+)人", rows);

        FileHandle fh = new FileHandle();

        System.out.println(fh.ShowHm(lh.hm, null, null));
    }

    @Test
    public void testCount4() {
        LogHandle lh = new LogHandle();
        StringBuilder sb = new StringBuilder();
        String rows = "福建 新增 感染患者 5人\\n" + "湖北 新增 感染患者 10人\\n" + "湖北 新增 疑似患者 10人\\n" + "广东 新增 疑似患者 3人\\n"
                + "福建 新增 感染患者 5人\\n" + "湖北 感染患者 流入 福建 10人\\n" + "湖北 疑似患者 流入 福建 1人\\n" + "福建 死亡 5人\\n" + "浙江 死亡 5人\\n"
                + "福建 治愈 1人\\n" + "福建 疑似患者 确诊感染 1人\\n" + "山东 疑似患者 确诊感染 1人\\n" + "福建 排除 疑似患者 5人" + "云南 排除 疑似患者 5人";
        lh.count4("([\\u4e00-\\u9fa5]+) 疑似患者 流入 ([\\u4e00-\\u9fa5]+) (\\d+)人", rows);

        FileHandle fh = new FileHandle();

        System.out.println(fh.ShowHm(lh.hm, null, null));
    }

    @Test
    public void testCount5() {
        LogHandle lh = new LogHandle();
        StringBuilder sb = new StringBuilder();
        String rows = "福建 新增 感染患者 5人\\n" + "湖北 新增 感染患者 10人\\n" + "湖北 新增 疑似患者 10人\\n" + "广东 新增 疑似患者 3人\\n"
                + "福建 新增 感染患者 5人\\n" + "湖北 感染患者 流入 福建 10人\\n" + "湖北 疑似患者 流入 福建 1人\\n" + "福建 死亡 5人\\n" + "浙江 死亡 5人\\n"
                + "福建 治愈 1人\\n" + "福建 疑似患者 确诊感染 1人\\n" + "山东 疑似患者 确诊感染 1人\\n" + "福建 排除 疑似患者 5人" + "云南 排除 疑似患者 5人";
        lh.count5("([\\u4e00-\\u9fa5]+) 死亡 (\\d+)人", rows);

        FileHandle fh = new FileHandle();

        System.out.println(fh.ShowHm(lh.hm, null, null));
    }

    @Test
    public void testCount6() {
        LogHandle lh = new LogHandle();
        StringBuilder sb = new StringBuilder();
        String rows = "福建 新增 感染患者 5人\\n" + "湖北 新增 感染患者 10人\\n" + "湖北 新增 疑似患者 10人\\n" + "广东 新增 疑似患者 3人\\n"
                + "福建 新增 感染患者 5人\\n" + "湖北 感染患者 流入 福建 10人\\n" + "湖北 疑似患者 流入 福建 1人\\n" + "福建 死亡 5人\\n" + "浙江 死亡 5人\\n"
                + "福建 治愈 1人\\n" + "福建 疑似患者 确诊感染 1人\\n" + "山东 疑似患者 确诊感染 1人\\n" + "福建 排除 疑似患者 5人" + "云南 排除 疑似患者 5人";
        lh.count6("([\\u4e00-\\u9fa5]+) 治愈 (\\d+)人", rows);

        FileHandle fh = new FileHandle();

        System.out.println(fh.ShowHm(lh.hm, null, null));
    }

    @Test
    public void testCount7() {
        LogHandle lh = new LogHandle();
        StringBuilder sb = new StringBuilder();
        String rows = "福建 新增 感染患者 5人\\n" + "湖北 新增 感染患者 10人\\n" + "湖北 新增 疑似患者 10人\\n" + "广东 新增 疑似患者 3人\\n"
                + "福建 新增 感染患者 5人\\n" + "湖北 感染患者 流入 福建 10人\\n" + "湖北 疑似患者 流入 福建 1人\\n" + "福建 死亡 5人\\n" + "浙江 死亡 5人\\n"
                + "福建 治愈 1人\\n" + "福建 疑似患者 确诊感染 1人\\n" + "山东 疑似患者 确诊感染 1人\\n" + "福建 排除 疑似患者 5人" + "云南 排除 疑似患者 5人";
        lh.count7("([\\u4e00-\\u9fa5]+) 疑似患者 确诊感染 (\\d+)人", rows);

        FileHandle fh = new FileHandle();

        System.out.println(fh.ShowHm(lh.hm, null, null));
    }

    @Test
    public void testCount8() {
        LogHandle lh = new LogHandle();
        StringBuilder sb = new StringBuilder();
        String rows = "福建 新增 感染患者 5人\\n" + "湖北 新增 感染患者 10人\\n" + "湖北 新增 疑似患者 10人\\n" + "广东 新增 疑似患者 3人\\n"
                + "福建 新增 感染患者 5人\\n" + "湖北 感染患者 流入 福建 10人\\n" + "湖北 疑似患者 流入 福建 1人\\n" + "福建 死亡 5人\\n" + "浙江 死亡 5人\\n"
                + "福建 治愈 1人\\n" + "福建 疑似患者 确诊感染 1人\\n" + "山东 疑似患者 确诊感染 1人\\n" + "福建 排除 疑似患者 5人" + "云南 排除 疑似患者 5人";
        lh.count8("([\\u4e00-\\u9fa5]+) 排除 疑似患者 (\\d+)人", rows);

        FileHandle fh = new FileHandle();

        System.out.println(fh.ShowHm(lh.hm, null, null));
    }

}

public class FileHandleTest {
    @Test
    public void testFileRead() {
        FileHandle fh = new FileHandle();
        StringBuilder sb = new StringBuilder();
        sb = fh.fileRead("D:\\temp\\log\\2020-01-22.log.txt");
        System.out.println(sb);
    }

    @Test
    public void testGetInfo() {
        FileHandle fh = new FileHandle();
        StringBuilder sb = new StringBuilder();
        InflectInfo value = new InflectInfo();
        value.setArea("广东");
        value.setSp(1);
        value.setIp(6);
        value.setCure(3);
        value.setDead(4);
        ArrayList<String> al = new ArrayList<>();
        al.add("dead");
        sb = fh.getInfo(value, al);
        System.out.println(sb);
    }

   
}

public class ArgsParseTest {
    @Test
    public void testParse() {
        String[] args = { "-log", "logname", "-out", "outname", "-type", "sp", "dead", "-province", "福建", "广东" };
        ArgsParse ap = new ArgsParse();
        ap.parse(args);
        // System.out.println(ap.sprovince);
        assertEquals("logname", ap.slog);

        assertEquals("outname", ap.sout);

        System.out.println(ap.sprovince);
        System.out.println(ap.stype);

    }

    @Test
    public void testTypeAndPronvinceParse() {
        String[] args = { "-log", "logname", "-out", "outname", "-type", "sp", "dead", "-province", "福建", "广东" };
        ArgsParse ap = new ArgsParse();
        ArrayList<String> al = new ArrayList<>();
        al = ap.typeAndPronvinceParse(args, "-type");
        al = ap.typeAndPronvinceParse(args, "-province");
        System.out.println(al);
    }

}

六、性能分析

在这里插入图片描述

七、代码规范链接

https://github.com/ideaflyit/InfectStatistic-main/blob/master/091700403/codestyle.md

八、收获

本次作业使我学习了GitHub的使用,强化了对单元测试的认识。并对写项目的流程更加清晰。特别是单元测试的使用,自己之前对单元测试仅有一个概念,并没有运用到实处,而此次自学加深了自己的技能。

九、技术仓库

  1. https://github.com/lenve/JavaEETest
    Spring、SpringMVC、MyBatis、Spring Boot案例
  2. https://github.com/wuyouzhuguli/SpringAll
    循序渐进,学习Spring Boot、Spring Boot & Shiro、Spring Cloud、Spring Security & Spring Security OAuth2,博客Spring系列源码
  3. https://github.com/xkcoding/spring-boot-demo
    一个用来深度学习并实战 spring boot 的项目,目前总共包含 65 个集成demo
  4. https://github.com/Heeexy/SpringBoot-Shiro-Vue
    提供一套基于Spring Boot-Shiro-Vue的权限管理思路.前后端都加以控制,做到按钮/接口级别的权限
  5. https://github.com/bz51/SpringBoot-Dubbo-Docker-Jenkins
    基于SpringBoot+Dubbo的微服务框架(借助Docker+Jenkins实现自动化、容器化部署)
posted @ 2020-02-18 13:01  DorisDream  阅读(147)  评论(2编辑  收藏  举报