寒假作业(2/2)

寒假作业 (2/2)

这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzu/2020SpringW
这个作业要求在哪里 https://edu.cnblogs.com/campus/fzu/2020SpringW/homework/10281
这个作业的目标 Git、GitHub使用,代码规范意识,一定的程序设计能力(基于命令行),PSP,单元测试和性能分析改进
作业正文 ....
其他参考文献 ...

1、Github 连接

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


2、PSP 表格

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

3、解题思路描述

  • 分析日志,需求是统计每个省的数据,创建省类用于记录感染患者、疑似患者、治愈,死亡等属性信息

  • 分析需求,最终处理结果将每个省的信息按行输出,故可将参加统计的每个省类加入一个集合,输出时从该集合中依次取出,并打印结果,因此选择哈希表(HashTable),将省名作为键,Province作为值

  • 详细分析日志文本,log日志中出现的几种情况:分类后数组长度有三种情况:3、4、5,分类后可以得到需要修改的省份两种情况:1.仅修改一个省份;2.需修改两个省份,后判断需要执行的操作类型,分析日志中出现的几种情况思考要如何修改相应省份的数据

  • 详细分析需求文档,需完成需求里要求的功能:读取log文件夹里的文件,数据的统计

  • 命令行参数分析:命令list以及五个参数名-log、 -out、 -date、 -type、 -province,自定义方法从中提取参数名,再取得相应的参数值,并需要注意的几点组合情况


4、设计实现过程

  • 大致流程
    命令行输入=>命令行解析处理=>获取-log参数对应日志=>遍历日志并统计相应数据=>按照其余参数要求将对应结果输出在相应文档

5、代码说明

  • ① 命令行解析并处理
public static void separateCMDInit(String[] args) {
            HashMap<Integer, String> paramenterHashMap = new HashMap<Integer, String>(5);
            paramenterHashMap.put(1, "-log");
            paramenterHashMap.put(2, "-out");
            paramenterHashMap.put(3, "-date");
            paramenterHashMap.put(4, "-type");
            paramenterHashMap.put(5, "-province");

            paramenterStrings = new String[args.length - 1];
            for(int i=1,len=args.length; i<len; i++) {
                paramenterStrings[i-1] = args[i];
            }
            int key;
            for(int i=0,len=paramenterStrings.length; i<len; i++) {
                key = OperateHashTable.getKey(paramenterHashMap, paramenterStrings[i]);
                if( key != -1) {
                    indexOfParamenterStrings[key] = i;
                }
            }
            paramentersOfType[0] = "null";
            paramentersOfProvince[0] = "null";

            for(int i=1; i<=5; i++) {
                if(indexOfParamenterStrings[i] != -1) {
                    if(i == 1) {    // -log
                        inputDir = paramenterStrings[indexOfParamenterStrings[i] + 1];
                        toDateString = GetFile.getMaxDateInputDir(inputDir);
                    }else if(i == 2) {  //-out
                        outputFileNameString = paramenterStrings[indexOfParamenterStrings[i] + 1];
                    }else if(i == 3) {  //-date
                        toDateString = paramenterStrings[indexOfParamenterStrings[i] + 1];
                    }else if(i == 4) {  //-type
                        String[] paramenterValues = new String[20];
                        int cnt = 0;
                        for(int j = indexOfParamenterStrings[i]+1;
                            j<paramenterStrings.length && OperateHashTable.getKey(paramenterHashMap, paramenterStrings[j])==-1; j++) {
                            paramenterValues[cnt++] = paramenterStrings[j];
                            paramentersOfType = paramenterValues;
                        }
                    }else if(i == 5) {  //-province
                        String[] paramenterValues = new String[20];
                        int cnt = 0;
                        for(int j = indexOfParamenterStrings[i]+1;
                            j<paramenterStrings.length && OperateHashTable.getKey(paramenterHashMap, paramenterStrings[j])==-1; j++) {
                            paramenterValues[cnt++] = paramenterStrings[j];
                            paramentersOfProvince = paramenterValues;
                        }
                    }
                }
            }
        }

//说明
/*
将输入的命令行进行分类并初始化各成员变量,再处理参数所需要对应的哈希表
*/

  • ② 判断操作类型
        public static void execOperate(Province province1, Province province2, int operateType, int number) {
            switch (operateType) {
                case 1:
                    province1.increaseDead(number);
                    province1.decreaseIp(number);
                    break;
                case 2:
                    province1.increaseCure(number);
                    province1.decreaseIp(number);
                    break;
                case 3:
                    province1.increaseIp(number);
                    break;
                case 4:
                    province1.increaseSp(number);
                    break;
                case 5:
                    province1.decreaseSp(number);
                    break;
                case 6:
                    province1.decreaseSp(number);
                    province1.increaseIp(number);
                    break;
                case 7:
                    province1.decreaseIp(number);
                    province2.increaseIp(number);
                    break;
                case 8:
                    province1.decreaseSp(number);
                    province2.increaseSp(number);
                    break;
                default:
                    break;
            }
        }

//说明
/*根据输入参数的信息可得到三种类型:3,4,5个值 */

  • ③ 各省份数据统计
/** description:统计省份数据 */
        public static void StatisticProvince(String lineString, Hashtable<String, Province> hashtable) {
            InfectStatistic infectStatistic = new InfectStatistic();
            String[] afterSplitStrings = lineString.split(" ");
            int numAfterSplit = afterSplitStrings.length; 
            int number = OperateLineString.getNumber(afterSplitStrings[numAfterSplit - 1]);
            String[] provinceNameStrings = OperateLineString.getProvince(afterSplitStrings);   
            int operateType = OperateLineString.getOperateType(afterSplitStrings);    

            if (provinceNameStrings[1].equals("")) { // 只有一个省
                if (!hashtable.containsKey(provinceNameStrings[0])) { // 哈希表中没有该省
                    Province province = infectStatistic.new Province(provinceNameStrings[0], 0, 0, 0, 0);
                    ProviceStatistic.execOperate(province, province, operateType, number);
                    hashtable.put(province.getProvinceName(), province);
                } else {
                    Province province = hashtable.get(provinceNameStrings[0]);
                    ProviceStatistic.execOperate(province, province, operateType, number);
                }
            } else if (!provinceNameStrings[1].equals("")) { // 有两个省
                Province province1 = null;
                Province province2 = null;
                if (hashtable.containsKey(provinceNameStrings[0])) {
                    province1 = hashtable.get(provinceNameStrings[0]);
                    if(hashtable.containsKey(provinceNameStrings[1])){
                        province2 = hashtable.get(provinceNameStrings[1]);
                    }else{
                        province2 = infectStatistic.new Province(provinceNameStrings[1], 0, 0, 0, 0);
                        hashtable.put(provinceNameStrings[1], province2);
                    }
                }else if (!hashtable.containsKey(provinceNameStrings[0])) {
                    province1 = infectStatistic.new Province(provinceNameStrings[0], 0, 0, 0, 0);
                    if(hashtable.containsKey(provinceNameStrings[1])){
                        province2 = hashtable.get(provinceNameStrings[1]);
                    }else{
                        province2 = infectStatistic.new Province(provinceNameStrings[1], 0, 0, 0, 0);
                        hashtable.put(provinceNameStrings[1], province2);
                    }
                    hashtable.put(provinceNameStrings[0], province1);
                }
                ProviceStatistic.execOperate(province1, province2, operateType, number);
            }

        }
        /**  description:统计全国的数据 */
        public static void StatisticNation(Hashtable<String, Province> hashtable) {
            InfectStatistic infectStatistic = new InfectStatistic();
            Province Nation = infectStatistic.new Province("全国", 0, 0, 0, 0);
            Set set = hashtable.keySet();
            Iterator iterator = set.iterator();
            while(iterator.hasNext()) {
                Object keyObject = iterator.next();
                Nation.ip += hashtable.get(keyObject).getIp();
                Nation.sp += hashtable.get(keyObject).getSp();
                Nation.cure += hashtable.get(keyObject).getCure();
                Nation.dead += hashtable.get(keyObject).getDead();
            }
            hashtable.put("全国", Nation);
        }

//说明
/*将全国和各省数据统计分开处理,具体步骤可看详细代码*/


6、单元测试截图和描述

目前暂无


7、单元测试覆盖率优化和性能测试

单元测试覆盖率


性能测试


8、代码规范的链接

https://github.com/xuguangqing/InfectStatistic-main/blob/master/221701428/codestyle.md


9、心路历程与收获

刚开始看到作业是看的一脸懵,不论是git/github还是代码编程以及单元测试和性能都让我看的心头一紧。不过还好有时间慢慢来,
现在可以初步使用Git、GitHub,也巩固了java编程知识,也稍微掌握了单元测试和性能测试。


10、学习仓库

①简介:最全的资源教程——前端涉及的所有知识体系
链接:https://github.com/nicejade/Front-end-tutorial

②简介:前端技能汇总
链接:https://github.com/JacksonTian/fks

③简介:前端开发所使用语言的主流学习资源汇集指南
链接:https://github.com/icepy/Front-End-Develop-Guide

④简介:前端开发相关的优秀网站、博客、以及活跃开发者
链接:https://github.com/foru17/front-end-collect

⑤简介:前端开发者手册,它概述并讨论了前端工程的实践,该如何学习以及实践时该使用什么工具
链接:https://github.com/helloqingfeng/Awsome-Front-End-learning-resource/tree/master/02-fedHandlebook-master

posted @ 2020-02-18 16:52  木头人超自信  阅读(169)  评论(1编辑  收藏  举报