2020软件工程第一次个人编程作业
-
PSP表格
| PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
|---|---|---|---|
| Planning | 计划 | 30 | 60 |
| Estimate | 估计这个任务需要多少时间 | 30 | 30 |
| Development | 开发 | 240 | 180 |
| Analysis | 需求分析 (包括学习新技术) | 360 | 480 |
| Design Spec | 生成设计文档 | 30 | 90 |
| Design Review | 设计复审 | 20 | 20 |
| Coding Standard | 代码规范 (为目前的开发制定合适的规范) | 10 | 10 |
| Design | 具体设计 | 120 | 60 |
| Coding | 具体编码 | 360 | 60 |
| Code Review | 代码复审 | 120 | 60 |
| Test | 测试(自我测试,修改代码,提交修改) | 30 | 60 |
| Reporting | 报告 | 30 | 60 |
| Test Report | 测试报告 | 30 | 30 |
| Size Measurement | 计算工作量 | 60 | 60 |
| Postmortem & Process Improvement Plan | 事后总结, 并提出过程改进计划 | 60 | 60 |
| 合计 | 1370 | 1320 |
-
流程图

-
代码说明
json解析,参数传递文件路径,将json数据整合到data.json里
def findjson(filedir):
filenames=os.listdir(filedir)
with open('data.json','w',encoding = 'utf-8') as f:
for filename in filenames:
filepath = filedir+'\'+filename
for line in open(filepath,encoding = 'utf-8'):
f.writelines(line)
return命令行参数的设置以及参数的传递
opts,arv= getopt.getopt(sys.argv[1:],'i:u:r:e:',['user=','repo=','event=','init='])
filedir = ""
reponame = ""
username = ""
eventname = ""
for opt in opts:
if opt[0] == '-i' or opt[0] == '--init':
filedir = opt[1]
findjson(filedir)
break
elif opt[0] == '-u' or opt[0] == '--user':
username = opt[1]
elif opt[0] == '-r' or opt[0] == '--repo':
reponame = opt[1]
elif opt[0] == '-e' or opt[0] == '--event':
eventname = opt[1]逐行读出data.json的数据并存放至列表
data_s=[]
f = open('data.json','r',encoding = 'utf-8')
for line in f.readlines():
data_s.append(json.loads(line))对不同需求进行查找计数并输出结果
def count_1(data_s,username,eventname):
cnt = 0
for data in data_s:
if data['actor']['login'] == username and data['type'] == eventname:
cnt = cnt + 1
print(cnt)
returndef count_2(data_s,reponame,eventname):
cnt = 0
for data in data_s:
if data['repo']['name'] == reponame and data['type'] == eventname:
cnt = cnt + 1
print(cnt)
returndef count_3(data_s,username,reponame,eventname):
cnt = 0
for data in data_s:
if data['repo']['name'] == reponame and data['repo']['name'] == reponame and data['type'] == eventname:
cnt = cnt + 1
print(cnt)
return
-
单元测试截图

-
单元测试覆盖率




程序的平均覆盖率是
0.59,差1分及格那咋办嘛(学废了就优化)
-
单元测试性能测试




听说多线程可以优化,然后查询的算法也可以优化,希望以后学会了实践一下。
-
代码规范链接
https://github.com/AshCrimpeng/2020-personal-python/blob/master/CodeStyle.md
-
总结
第一次接触与之前输入输出完全不同的编程作业,极大的打击了我的自信心。

遇到的困难
对于json文件的打开操作,文件路径的正确写法,编码方式
对于文件夹中多个 json 文件的整合解析,以及在写入时目录没有相应文件时自动生成相应文件
命令行参数的设置以及参数的传递学到的东西
python 打开文件的操作,文件夹内多个json文件的解析
sys.argv 和 getopt.getopt() 的用法
git的基础用法 —— fork 以及 commit
不是一般的菜不足的地方
通过覆盖率以及性能测试可以了解到代码还有很多不足的地方(但是那又有什么办法呢)
多进程学废了一定优化代码
查找计算的程序有些冗余
虽然有些打击,但是还是从中学到了不少东西,算是迈出了我的一大步,该学习了朋友!

浙公网安备 33010602011771号