软工实践第一次个人编程作业
正文
| 这个作业属于哪个课程 | https://edu.cnblogs.com/campus/fzu/SE2020 |
|---|---|
| 这个作业要求在哪里 | https://edu.cnblogs.com/campus/fzu/SE2020/homework/11167 |
| 这个作业的目标 | <熟练使用github,学会用python处理json文件数据。规范代码> |
| 学号 | 031802320 |
| 语言 | python |
psp表格
| PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
|---|---|---|---|
| Planning | 计划 | 30 | 40 |
| Estimate | 估计这个任务需要多少时间 | 10 | 10 |
| Development | 开发 | ||
| Analysis | 需求分析 (包括学习新技术) | 60 | 60 |
| Design Spec | 生成设计文档 | 15 | |
| Design Review | 设计复审 | 10 | |
| Coding Standard | 代码规范 (为目前的开发制定合适的规范) | 10 | 10 |
| Design | 具体设计 | 40 | 40 |
| Coding | 具体编码 | 500 | |
| Code Review | 代码复审 | 100 | |
| Test | 测试(自我测试,修改代码,提交修改) | 100 | |
| Reporting | 报告 | 60 | |
| Test Report | 测试报告 | 60 | |
| Size Measurement | 计算工作量 | 60 | |
| Postmortem & Process Improvement Plan | 事后总结, 并提出过程改进计划 | 30 | |
| 合计 |
解题思路
用python解析处理json文件,获取数据,解析出单个用户的行为信息,再去用函数查询每个事件的数量
设计过程
命令行参数的解析、Json文件的读取,数据分析处理依次完成代码
查阅博客了解python各种参数设置,函数
设计真正符合题意的函数
在学了
有用的部分代码说明
读取json按行分解并解析
def read1(self):
self.dicts = []
for root, dirs, files in os.walk(self.dir_addr):
for file in files:
if file[-5:] == '.json' and file[-6:] != '1.json' and file[-6:] != '2.json' and file[-6:] != '3.json':
with open(file, 'r', encoding='utf-8') as f:
self.jsons = [x for x in f.read().split('\n') if len(x)>0]#按行分割
for self.json in self.__jsons:
self.dicts.append(json.loads(self.json))
命令行参数设置
def run():#命令行参数的设置(-i为初始化,-u为用户,-r为项目,-e为事件)
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--init', help='json file path')
parser.add_argument('-u', '--user', help='username')
parser.add_argument('-r', '--repo', help='repository name')
parser.add_argument('-e', '--event', help='type of event')
处理数据得到结果getnum()
def getnum(jsdata_list, user, event, repo):
'计算数量'
num = 0
i = 0
for jsdata in jsdata_list:
if len(user) != 0 and len(repo) == 0:
if user == jsdata['actor']['login'] and jsdata['type'] == event:
num += 1
else:
pass
elif len(user) == 0 and len(repo) != 0:
if repo == jsdata['repo']['name'] and jsdata['type'] == event:
num += 1
else:
pass
elif len(user) != 0 and len(repo) != 0:
if repo == jsdata['repo']['name'] and jsdata['type'] == event and user == jsdata['actor']['login']:
num += 1
else:
pass
print(num)
单元测试截图描述
借用别人代码进行的单元测试

代码规范链接
https://github.com/supernooob/2020-personal-python/blob/master/codestyle.md
总结
不会,不是我能独立完成的作业
向别人了解学习了基本的文本数据处理框架
认识到自己的学习能力,应该花更多时间实践,要真正深刻地掌握一门语言才行
浙公网安备 33010602011771号