软工实践寒假作业(2/2)
软工实践寒假作业(2/2)
这个作业属于哪个课程|<2020春S班>
:---??:---:
这个作业要求在哪里|作业要求
这个作业的目标|<掌握github的使用、PSP表格、疫情统计程序>
作业正文|....
其他参考文献|知乎、菜鸟教程
一、Github仓库地址
https://github.com/zjwoyingle/InfectStatistic-main
二、PSP表格
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 30 | 40 |
Estimate | 估计这个任务需要多少时间 | 5 | 10 |
Development | 开发 | 1200 | 800 |
Analysis | 需求分析 (包括学习新技术) | 120 | 180 |
Design Spec | 生成设计文档 | 30 | 40 |
Design Review | 设计复审 | 20 | 15 |
Coding Standard | 代码规范 (为目前的开发制定合适的规范) | 30 | 50 |
Design | 具体设计 | 60 | 100 |
Coding | 具体编码 | 240 | 360 |
Code Review | 代码复审 | 30 | 60 |
Test | 测试(自我测试,修改代码,提交修改) | 120 | 60 |
Reporting | 报告 | 30 | 20 |
Test Repor | 测试报告 | 30 | 20 |
Size Measurement | 计算工作量 | 10 | 10 |
Postmortem & Process Improvement Plan | 事后总结, 并提出过程改进计划 | 20 | 20 |
合计 | 1975 | 1785 |
解体思路描述
- 首先是命令行参数的识别。在CSDN上学习了相关知识:、java学习之命令行参数通过命令行传递参数
- 其次是日志的读取。学会了读取指定文件夹内所有文件的知识:JAVA基础知识之File类。
- 之后是分析日志内容的编码。因为有些偷懒,所以没有去学习JAVA的正则表达式,写了一大堆代码。
- 最后是txt文档的生成。就是先得到结果,在输出到文件。
四、设计实现过程
因为做作业的时候,时间也比较紧张了,所以并没有花心思设计几个类、几个函数。结果呢,就把代码塞到了main函数里,幸好代码量不是太多。下面就是一些示意图:
五、代码说明
- 处理命令行参数
//得到存放各类型命令行参数的ArrayList具体值
for (int i=0;i
?? if (args[i].equals("-log")) {
???? logList=args[++i];
???? logList=logList.replace('/', '');
?? }
?? else if (args[i].equals("-out")) {
???? outList=args[++i];
???? outList=outList.replace('/', '');
?? }
?? else if (args[i].equals("-date")) {
???? dateList=args[++i];
?? }
?? else if (args[i].equals("-type")) {
???? for (int j=i+1;j
?????? if (!args[j].equals("-out")&&!args[j].equals("-date")&&...)
?????? {
???????? typeList.add(args[j]);
?????? }
?????? else
?????? {
???????? i=j-1;
???????? break;
?????? }
???? }
?? }
?? else if (args[i].equals("-province")) {
?? ...
}
}//获取ArrayList循环结束
- 处理日志文件
//处理日志中的数据
for(String s:arr)
{
?? if (s.compareTo(dateList+".log")>0) continue;
?? try
?? {
???? File afile = new File(logList+s);
???? Scanner sc = new Scanner(afile);
???? while (sc.hasNext())
???? {
?????? String first=sc.next();
?????? if (first.equals("//"))
?????? sc.nextLine();
?????? else
?????? {
???????? int index=0;
???????? for (int i=0;i<32;i++)
???????? {
?????????? if (first.equals(province[i]))
?????????? {
???????????? index=i;
???????????? break;
?????????? }
???????? }
???????? number0=1;
???????? numberindex=1;
???????? String second=sc.next();
???????? if (second.equals("新增"))
???????? {
?????????? String third=sc.next();
?????????? String four=sc.next();
?????????? four=four.replace("人", "");
?????????? int member=Integer.parseInt(four);
?????????? if (third.equals("感染患者")) {
???????????? number[0][0]+=member;
???????????? number[index][0]+=member;
?????????? }
?????????? else {
???????????? number0+=member;
???????????? numberindex+=member;
?????????? }
???????? }
???????? else if (second.equals("感染患者"))
???????? ...
?????? }
???? }
???? sc.close();
?? }
}
- 将从日志文件得到的数据转化为所需数据
//得到输出结果
ArrayList result=new ArrayList();
if (provinceInt.size()0)
?? ...
else
{
?? for (int i=0;i<32;i++)
?? numberi=0;
?? for (int i=0;i
?? if(typeInt.size()
?? {
???? for (int i=0;i<32;i++)
???? {
?????? if (numberi==0)
?????? {
???????? continue;
?????? }
?????? String mid=province[i]+" 感染患者"+""+number[i][0]+""+"人"+" 疑似患者"+""+numberi+""+"人"
?????? +" 治愈"+""+numberi+""+"人"+" 死亡"+""+numberi+""+"人\n";
?????? result.add(mid);
?????? }
???? }
?? else
?? ...
?? }
}
六、单元测试截图和描述
由于我写代码之前没有仔细看单元测试的内容,所以把所有的代码都写到了main函数里,这就很难测试每一个代码片段了。所以写完以后,我只能修改了一下自己的代码,这样起码main函数可以得到测试结果,。
测试代码
import static org.junit.Assert.*;
import org.junit.Test;
public class InfectStatisticTest
{
?? @Test
?? public void testMain()
?? {
???? String[] test1=("list -log D:/log/ -out D:/ListOut1.txt -date 2020-01-22").split(" ");
???? //for(int i=0;i
???? InfectStatistic.main(test1);
???? assertEquals("全国 感染患者15人 疑似患者22人 治愈2人 死亡1人\n", InfectStatistic.result.get(0));
???? assertEquals("福建 感染患者5人 疑似患者7人 治愈0人 死亡0人\n", InfectStatistic.result.get(1));
???? assertEquals("湖北 感染患者10人 疑似患者15人 治愈2人 死亡1人\n", InfectStatistic.result.get(2));
// String[] test2=("list -log D:/log/ -out D:/ListOut2.txt -date 2020-01-22 -province 福建 河北").split(" ");
????// InfectStatistic.main(test2);
????// assertEquals("福建 感染患者5人 疑似患者7人 治愈0人 死亡0人\n", InfectStatistic.result.get(0));
????// assertEquals("河北 感染患者0人 疑似患者0人 治愈0人 死亡0人\n", InfectStatistic.result.get(1));
// String[] test3=("list -log D:/log/ -out D:/ListOut7.txt -date 2020-01-23 -type cure dead ip -province 全国 浙江 福建").split(" ");
????// InfectStatistic.main(test3);
????// assertEquals("全国 治愈4人 死亡3人 感染患者42人\n", InfectStatistic.result.get(0));
????// assertEquals("福建 治愈1人 死亡0人 感染患者9人\n", InfectStatistic.result.get(1));
????// assertEquals("浙江 治愈0人 死亡0人 感染患者0人\n", InfectStatistic.result.get(2));
?? }
}
三个测试结果截图
七、单元测试覆盖率优化和性能测试,性能优化截图和描述
单元测试覆盖率
我是直接测试main函数,所以命令行要么带province要么不带province,要么带type要么不带type,就不能一次测试把所有情况都覆盖。
八、代码规范的链接
https://github.com/zjwoyingle/InfectStatistic-main/blob/master/221701137/codestyle.md
九、心路历程与收获
第一次做这么复杂的项目,真正的感觉特别难,也发现了自己很多很多不懂的地方。以后一定需要多加学习。一开始看题目,感觉一点头绪都没有,完全不知道如何下手。所幸经过许多人和资料文献的帮忙,让自己一步步的做了出来。现在感觉很喜悦,对自己的成果很满意。
十、第一次作业中技术路线图相关的5个仓库
1.SpringAll:https://github.com/zjwoyingle/SpringAll
简介:循序渐进,学习Spring Boot、Spring Boot & Shiro、Spring Cloud、Spring Security & Spring Security OAuth2,博客Spring系列源码,帮助初学者学习Spring。
2.hibernate-orm:https://github.com/zjwoyingle/hibernate-orm
简介:Hibernate的核心对象/关系映射功能,适合进一步学习Hibernate框架。
3.Java:https://github.com/zjwoyingle/Java
简介:Java的学习之路,学习JavaEE以及框架时候的一些项目,结合博客和源码,让你受益匪浅,适合Java初学者和刚入门开始学框架者。
4.Heart-First-JavaWeb:https://github.com/zjwoyingle/Heart-First-JavaWeb
简介:一个走心的 Java Web 入门开发教程,面向新手友好,容易上手,同时没有废话,有很多实用的例子适合入门者学习。
5.JavaGuide:https://github.com/zjwoyingle/JavaGuide
简介:Java学习+面试指南,一份涵盖大部分Java程序员所需要掌握的核心知识。适合各个阶段的同学阅读学习。