Fourth Job: Pair Programming

Github project addresses (1) Fork warehouse.

GitHub address github address
I Student ID 201831061217
Partners Student ID 201831061216
Partner blog address

(2) psp table

PSP2.1 Personal Software Process Stages Estimated time consuming (minutes) The actual time-consuming (minutes)
Planning plan 60 40
Estimate Estimate how much time this task requires Half of the week 3 days
Development Develop 500 700
Analysis Needs analysis (including learning new technologies) 200 400
Design Spec Generate design documents 30 20
Design Review Design review (and colleagues reviewed the design documents) 120 150
Coding Standard Code specifications (development of appropriate norms for the current development) 30 40
Design Specific design 60 40
Coding Specific coding 600 900
Code Review Code Review 120 120
Test Test (self-test, modify the code, submit modifications) 120 120
Reporting report 180 250
Test Report testing report 60 40
Size Measurement Computing workload 20 5
Postmortem & Process Improvement Plan Later summarized, and process improvement plan 60 40
total 2160 3 days

(3) calculate the design and implementation of the interface module.

Here Insert Picture Description

Code Analysis

Codes using five overall function implemented, four of performance function, a utility function by -i -o -u -e command for calling function has been packaged four functions.
Here Insert Picture Description

-i __. txt achieve the amount of text in the character of statistics
using file method f.read ideas () will read the information stored in the string and then strike length of the string.

def My_chars_count(file_name):
    #用来统计文本文件里面的字符数量
    
    with open(file_name,'r') as f:
        chars=f.read()
    f.close()    
    return 'chars:'+str(len(chars))

Here Insert Picture Description

-o__.txt实现对文本文件符合条件的单词数量进行统计
思路:使用了正则表达式,之前就听说过但是一直没有去学习,这次是一个很好的机会去了解正则表达式。用readlines()的方法把文本文本以行的方式读取出来,然后在对每一行进行字符串匹配,符合以4个字母开头的单词就会以列表的形式输出再将其存入定义过的word单词列表,求出word的长度就是单词的数量

def My_words_count(file_name):
    #用来统计文本文件里面的单词数量规定4个字母以上的单词
    words=[]
    word=0
    with open(file_name,'r') as f:
        lines=f.readlines()
        for N in range(0,len(lines)):
        #正则表达式把符合条件的单词筛选出来
            words.extend(re.findall(r'[(a-z|A-Z)(a-z|A-Z)(a-z|A-Z)(a-z|A-Z)]{4,}',lines[N]))
    word+=len(words)   
    f.close()    
    return "words:"+str(word)

Here Insert Picture Description

-u__.txt实现对文本文件有效行数的统计
思路:有效行数即非空白行,空白行就是'\n'那么利用if语句就可以控制计数器的自增实现对于非空白行的计数。

def My_lines_count(file_name):
    #用来统计文本文件里面的行数
   
    line_num=0
    with open(file_name,'r') as f:
        lines=f.readlines()
        for each_line in lines:
            if each_line!='\n':
                line_num+=1
            
    
    f.close()    
    return "lines:"+str(line_num)    

Here Insert Picture Description

-e__.txt实现对文本文件单词出现频率的统计
思路:这个函数的前一部分和-u基本一致,利用正则表达式选出单词存入一个有重复的列表,接着利用python中的dict字典类型的特征,dict{key:value}key和value是映射关系不会出现重复的key,那么就把不重复的单词给key,单词的频率用value的值来记录。有重复单词的列表和字典和无重复单词的列表好像三个杯子,有重复单词->字典->无重复单词的列表就像一个杯子的水依次倒给下一个水杯倒三次水水变少了。
Here Insert Picture Description
在python的list列表中有一个方法list.count()(i)用来求得第i个列表元素在列表中的个数,用这个方法来解决这个问题在合适不过了。那么我们遍历无重复的单词列表让这个单词在有重复的单词列表中来求得重复的次数就可以了。

pythonpython
def word_count(file_name):
#记录文本中单词出现的频率,并且按照出现频率打印出来
#words列表存放有重复的单词
words=[]
with open(file_name,'r') as f:
lines=f.readlines()
for N in range(0,len(lines)):
words.extend(re.findall(r'[(a-z|A-Z)(a-z|A-Z)(a-z|A-Z)(a-z|A-Z)]{4,}',lines[N]))
#利用了python字典的特性dict{key:value},字典里面映射关系不会出现键key的重复
#创建一个字典存放单词和其频率
wokey={}
#用有重复单词的列表来给字典赋值,而在字典中就不会用重复了但是key对应的value的值没有变的
wokey=wokey.fromkeys(words)
#新定义一个单词列表来存放无重复的单词
wordlist=list(wokey.keys())
for i in wordlist:
#得到无重复的词频
wokey[i]=words.count(i)
wokey_1={}
wokey_1=sorted(wokey.items(),key=lambda p:p[1],reverse=1)
i=0
for x,y in wokey_1:
if i<10:
print('%s’s frequence: %d'%(x,y))
i+=1
continue
else:
break
f.close()
```
Here Insert Picture Description

-d 新增功能求指定长度的词组的次数

在第三步中,我们希望各位在第一步的基础上,添加一些新的功能:

a) 词组统计:能统计文件夹中指定长度的词组的词频
思路:因为可以使用正则表达式这个问题变的十分简单了,
r'[(a-z|A-Z)(a-z|A-Z)(a-z|A-Z)(a-z|A-Z)]{3},意思是在筛选前3个字符都是符合a-Z的单词,然后我们对于符合条件的单词进行计数。

def My_dgtwords_count(file_name):
    #用来统计文本文件里面的指定单词长度词组词的数量,这里是3个长度的词组
    words=[]
    word=0
    with open(file_name,'r') as f:
        lines=f.readlines()
        for N in range(0,len(lines)):
            words.extend(re.findall(r'[(a-z|A-Z)]{3}',lines[N]))
    word+=len(words)   
    f.close()    
    return "designatewords:"+str(word)

Here Insert Picture Description

调用以上功能函数的工具函数

注意实现多个功能时必须按照-i-o-u-e-d的顺序!

实现使用输入的 -i-u-d-o-e 和文件名 得到期望值的功能,这里写函数的时候非常蠢。。。我们没有特别好的方法就是手打各种输入方式然后调用对应函数。缺陷就是不能实现调换输入顺序和同时读取两个文档。

def My_cmd():
    command,file_name=input("Please input command").split()
    if command=='-i':
        #记录字符的数量
        print(My_chars_count(file_name))
    if command=='-d':
        #记录字符的数量
        print(My_dgtwords_count(file_name))
        
    if command=='-o':
        #记录符合条件单词的数量
         print(My_words_count(file_name))
    
    if command=='-u':
        #记录有效行数
        print(My_lines_count(file_name))
    if command=='-e':
        #记录词频
        print(word_count(file_name))
    if command=='-i-o':
        #记录字符的数量,记录符合条件单词的数量
        print(My_chars_count(file_name))
        print(My_words_count(file_name))
    if command=='-i-u':
        #记录字符的数量,记录有效行数
        print(My_chars_count(file_name))
        print(My_lines_count(file_name))
    if command=='-i-e':
        #记录字符的数量,#记录词频
        print(My_chars_count(file_name))
        print(word_count(file_name))
    if command=='-i-o-u':
        #记录字符的数量,记录符合条件单词的数量,记录有效行数
        print(My_chars_count(file_name))
        print(My_words_count(file_name))
        print(My_lines_count(file_name))
    if command=='-i-o-u-e':
        #记录字符的数量记录符合条件单词的数量,记录有效行数,记录词频
        print(My_chars_count(file_name))
        print(My_words_count(file_name))
        print(My_lines_count(file_name))
        print(word_count(file_name))
    if command=='-i-o-e':
        #记录字符的数量记录符合条件单词的数量,记录词频
        print(My_chars_count(file_name))
        print(My_words_count(file_name))
        print(word_count(file_name))
    if command=='-o-u':
        #记录符合条件单词的数量,有效行数
        print(My_words_count(file_name))
        print(My_lines_count(file_name))
    if command=='-o-e':
        #记录符合条件单词的数量和词频
        print(My_chars_count(file_name))
    if command=='-u-e':
        #记录有效行数和词频
        print(My_lines_count(file_name))
        print(word_count(file_name))

My_cmd()

多个功能一起实现:
Here Insert Picture Description

(4)代码复审过程。

代码复审检查表:

1、概要部分

(1)代码符合需求和规格说明么?
符合。
(2)代码设计是否考虑周全?

(3)代码可读性如何?
简单易懂。
(4)有冗余的或重复的代码吗?
开始有冗余但后面在两人协商后由一人改编后没有冗余了。
(5)代码的每一行都执行并检查过了吗?
执行并逐行检查过。

2、设计规范部分

(1)设计是否遵从已知的设计模式或项目中常用的模式?
遵守。
(2)有没有无用的代码可以清除?
没有。

3、代码规范部分

基本符合代码标准和风格,代码可读性高。

4、具体代码部分

数据结构中有没有用不到的元素?
没有

5、效能

代码的效能如何?
效能很高。

6、可读性

可读性比较高,注释很详细。

7、可测试性

进行了单元测试

8、代码复审感想

经过这次的代码复审,我认识到了代码复审可以找出代码的错误,以及发现逻辑和算法的出错,甚至还可能发现潜在的错误,这些能让我们互相在代码复审中互有补益,能够更加开拓我们对编程的理解和认识。

(5)计算模块接口部分的性能改进。

性能分析

Here Insert Picture Description
提高性能目前我所知道的就是循环里面减少时间复杂度。下面是我们写的一个循环,经过我们尝试在保证实现功能的前提下不能降低时间复杂度了。

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

通过性能分析主要的时间用在了input上面,挺尴尬的。
我们两个进行讨论希望能可以改变一些,但是通过了调整函数并未实现。这或许是由于我们现在所学知识还有限,同时也提醒我们后面还需要增加我们代码量和一些实践经验。

(6)计算模块部分单元测试展示。

Here Insert Picture Description

使用python测试模块uinttest进行测试,代码比较测试结果与预计一样。

(7)计算模块部分异常处理说明。

在测试过程中我发现当文本文件里面出现了汉字和一些中文符号后会报错

Here Insert Picture Description

Here Insert Picture Description

解决方法:

Here Insert Picture Description

读取方式改成二进制读取方式就可以了。

新的错误

Here Insert Picture Description

改回原来的读取方式后,又出现原来的方式,我们经过一番努力以后并没有解决这个问题,之后再网上复制粘贴来的文本都会有这样的问题所以这也是我们在代码测试复审中发现的缺陷。

代码模块上,由于第一次作业时就划分好了模块,以及对于多个函数的规划和安排都比较清晰,所以在添加新功能时,没有在大的代码模块上出现问题。结对时,我们遇到的困难主要还是在复杂字符串进行操作的算法上。在结对项目的开展初期,我们是在宿舍进行讨论的;我们在宿舍进行需求分析,然后搜索相对应的资料,各自也在进行进度的标记,控制项目的进程。在聊完了各自已经做完的工作之后,我俩一起探讨了当时未解决的问题,我们主要聊了下复杂字符串进行操作,开始这个问题对我们确实很棘手,搞得我们也烦躁,但在后期的讨论中我们烦躁的心情得到缓解,然后我们将我们所遇的问题进行了整理,紧接着我们通过上网查找这个问题的解决方法,功夫不负有心人我们找到了正则表达式来解决这个问题,正则表达式的大致匹配过程是:依次拿出表达式和文本中的字符比较,如果每一个字符都能匹配,则匹配成功;一旦有匹配不成功的字符则匹配失败。我们使用正则表达式中的findall(findall 的简单用法:返回string中所有与pattern相匹配的全部字串,返回形式为列表)。结对编程真的很棒,在相互的合作中能够给自己带来很多全新的认识。可以对代码结构进一步的优化,产生新的idea等等。

(9)新增功能

-d 新增功能求指定长度的词组的次数

在第三步中,我们希望各位在第一步的基础上,添加一些新的功能:

a) the phrase statistics: can statistical word frequency phrase folder specified length of
ideas: because you can use regular expressions to this problem becomes very simple,
r '[(az | AZ) (az | AZ) (az | AZ) (az | AZ)] {3 }, which means before the screening of three characters are in line with aZ words, and then we count the qualifying word.

def My_dgtwords_count(file_name):
    #用来统计文本文件里面的指定单词长度词组词的数量,这里是3个长度的词组
    words=[]
    word=0
    with open(file_name,'r') as f:
        lines=f.readlines()
        for N in range(0,len(lines)):
            words.extend(re.findall(r'[(a-z|A-Z)]{3}',lines[N]))
    word+=len(words)   
    f.close()    
    return "designatewords:"+str(word)

Here Insert Picture Description

Submit a question arising in the course

Here Insert Picture Description

Here Insert Picture Description

After submitting complete request could not pull, do not know what made me ask first link to the source code repository where the source code links

Twinning process

The pairing of two people is like the role of pilots and pilots, has just begun, after all, is not used to writing code has always been a person, two people together is a little difficult. But then with up later, for processing detection data, and abnormality detection code review particular pair to complete than a person with a high efficiency multi done separately. The first pair programming experience, I think the pair programming, the most important thing is to work hard to communicate not only constant communication and feedback information to the pilot better co-ordination to achieve 1 + 1> 2. Two people must have a Code otherwise, the two parties merged specification code obstacle when reading both sides will appear. The other is two people learning from each other based on mutual learning from each other to complete the progressive attitude of cooperation can harvest more, in short, this is a valuable pair programming.
Here Insert Picture Description

Guess you like

Origin www.cnblogs.com/Eldq/p/11671115.html