福州大学软件工程实践第一次个人编程作业

这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzu/SE2020
这个作业要求在哪里 https://edu.cnblogs.com/campus/fzu/SE2020/homework/11167
这个作业的目标 <json文件的输入,解析与数据处理,学会Git,GitHub使用以及单元测试>
学号 <181800404>

一、PSP表格

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

二、解题思路

  一开始就是懵逼,十分的懵逼。一度到了怀疑人生的地步。(转专业来的没见过世面)
后来听从同学的建议选择了python来学习如何实现json文件的解析与处理,学习了python等库。
  ·JSON
  ·[https://www.runoob.com/python/python-json.html](Python JSON)
  OS
  ·[https://www.runoob.com/python/os-file-methods.html](Python OS 文件/目录方法)
  ARGPARSE
  ·[https://www.cnblogs.com/iMX8mm/p/10821468.html] (python3中argparse模块)
了解了这些模块之后就明白了我们的任务大概是从json文件中读取数据文件并且对用户的4种事件、每一用户在每一个项目的4种事件分别进行分类并存储

三、设计实现过程

四、代码说明

  ·命令行设置

        self.parser.add_argument('-i', '--init')
        self.parser.add_argument('-u', '--user', type=str)
        self.parser.add_argument('-r', '--repo', type=str)
        self.parser.add_argument('-e', '--event', type=str)

  ·loaddate函数

    def loadData(self, dict_address: str):
        user_event = {}
        repo_event = {}
        user_repo_event = {}
        need_event = ["PushEvent", "IssueCommentEvent", "IssuesEvent", "PullRequestEvent"]
        for root, dirs, files in os.walk(dict_address):
            for file in files:
                if file[-5:] == ".json":
                    json_path = file
                    json_file = open(dict_address + '/' + json_path, 'r', encoding='UTF-8').readlines()
                    for line in json_file:
                        line = json.loads(line)
                        if line["type"] in need_event:
                            self.addUserEvent(line, user_event)
                            self.addRepoEvent(line, repo_event)
                            self.addUserRepoEvent(line, user_repo_event)

  ·部分add函数和get函数

    def addUserEvent(self, dict, user_event):
        user_id = dict['actor']['login']
        event = dict['type']
        if user_id not in user_event:
            user_event[user_id] = {'PushEvent': 0, 'IssueCommentEvent': 0, 'IssuesEvent': 0, 'PullRequestEvent': 0}
        user_event[user_id][event] += 1

    def getUserEvent(self, user, event):
        x = open("user_event.json", 'r', encoding='utf-8').read()
        data = json.loads(x)
        # if user or event not in data:
        #     return 0
        return data[user][event]

五、GitHub运行结果

六、单元测试截图和描述

目前单元测试运行失败还在寻找原因

七、代码迭代

本人水平有限暂时无法实现

八、总结

 &emsp本次练习最大的收获就是明白了自己到底有多菜学习了python的基本使用方法了解了pycharm的使用第一次使用了除C以外的语言了解了json文件的处理方法,这次作业让我对自己目前的水平有了一次全新的认识,接下来的日子里我会积极学习新的知识增强自己的代码能力┭┮﹏┭┮。

posted @ 2020-09-17 18:32  painy333  阅读(181)  评论(1编辑  收藏  举报