"Building of the law," the fourth operation

Operational requirements Links Work address
Partner blog Li Han
Github Address github

One,

(1) PSP form

PSP2.1 Personal Software Process Stages Estimated time consuming (minutes) The actual time-consuming (minutes)
Planning plan 30 30
· Estimate • Estimate how much time this task requires 30 30
Development Develop 770 720
· Analysis · Needs analysis (including learning new technologies) 300 240
· Design Spec Generate design documents 30 20
· Design Review · Design Review (and his colleagues reviewed the design documents) 30 20
· Coding Standard · Code specifications (development of appropriate norms for the current development) 20 15
· Design · Specific design 30 30
· Coding · Specific coding 300 315
· Code Review · Code Review 30 40
· Test · Test (self-test, modify the code, submit modifications) 30 40
Reporting report 150 120
· Test Report · testing report 60 45
· Size Measurement · Computing workload 30 30
· Postmortem & Process Improvement Plan · Hindsight, and propose process improvement plan 60 45
total 950 900

(2) Code specifications:

Naming conventions: 1. class name first letter capitalized, use nouns or noun phrases that reflect the named class class function.

2. The first word lowercase class member variable, the variable name can be added _ prefix.

3. The method name first characters to uppercase, and should use a verb or verb phrase.

4. The first character lowercase parameter, the parameter descriptive names.

5. The name of the interface to be meaningful, the interface modifier only with public and internal.

6. Each statement accounting for at least one row, breaking a long sentence for the two-line display.

7. nested statement is not more than three layers.

See detailed specifications Code: Code Specifications

(3) twinning process: non-staged discussions, pair programming Photo:

Division of the line, discussion, pair programming; solve small problems when working line.

two,

(4) problem-solving ideas and key code Description:

FIG general functional configuration:

Count the number of characters, words, lines modules:

public long charactersnumber = 0;  //字符数

​        public long wordsnumber = 0;  //单词数

​        public long linesnumber = 0;  //行数

​        //数据统计

​        public void Calculate(string dataline, WordTrie wtrie)

​        {

​            if (string.IsNullOrEmpty(dataline)) return;

​            string word = null;

​            for (int i = 0, len = dataline.Length; i < len; i++)

​            {

​                char unit = dataline[i];

​                if (unit >= 65 && unit <= 90){

​                    unit = (char)(unit + 32);

​                }  //大写转小写

​                if ((unit >= 48 && unit <= 57) || (unit >= 97 && unit <= 122)){

​                    word = String.Concat(word, unit);

​                }

​                else{

​                    if (!string.IsNullOrEmpty(word)){  //判断是否为词尾后的字符

​                        if (word[0] >= 97 && word[0] <= 122){  //首字符是否为字母

​                            wtrie.Insert(word);

​                        }

​                        word = null;

​                    }

​                }

​            }

​            if (!string.IsNullOrEmpty(word))  //判断行尾是否有单词

​            {

​                if (word[0] >= 97 && word[0] <= 122){  //首字符是否为字母

​                 wtrie.Insert(word);

​                }

​                word = null;

​            }

​            this.linesnumber++;  //统计行数

​            this.wordsnumber = wtrie.CountSum;  //统计单词数

​            this.charactersnumber += dataline.Length;  //统计字符数

​        }

Sort Word Frequency:

   public List<ListUnit> Sort()

​        {

​            TrieNode node = _Root;

​            List<ListUnit> WordList = new List<ListUnit>();

​            WordList = WordPreOrder(node, WordList);

​            //按词频降序排列,若词频相等按字典序排列

​            WordList.Sort((a, b) =>

​            {

​                if (a.WordNum.CompareTo(b.WordNum) != 0)

​                    return -a.WordNum.CompareTo(b.WordNum);

​                else

​                    return a.Word.CompareTo(b.Word);

​            });

​            return WordList;

​        }

Generate word lists:

private List<ListUnit> WordPreOrder(TrieNode node, List<ListUnit> WordList)`

​        `{`

​            `if (node.PrefixNum == 0) { return WordList; }`

​            `if (node.WordNum != 0)`

​            `{`

​                `ListUnit unit = new ListUnit();`

​                `unit.Word = node.Word;`

​                `unit.WordNum = node.WordNum;`

​                `WordList.Add(unit);`

​            `}`

​            `foreach (char key in node.Sons.Keys)`

​            `{`

​                `WordList = WordPreOrder(node.Sons[key], WordList);`

​            `}`

​            `return WordList;`

​        `}

Read and accounting files:

​ ```csharp
public string pathIn;

​ public string pathOut;

// read the input file rows and statistics

​ public WordCalculate Input(WordCalculate datanumber, WordTrie wtrie)

​ {

​ FileStream fs = null;

​ StreamReader sr = null;

​ String dataline = String.Empty;

​ try

​ {

​ fs = new FileStream(this.pathIn, FileMode.Open);

​ sr = new StreamReader(fs);

​ while ((dataline = sr.ReadLine()) != null)

​ {

datanumber.Calculate (dataline, wtrie); // row statistics

​ }

​ }

​ catch

​ {

Console.WriteLine ( "reads the document failed!");

​ }

​ finally

​ {

​ if (sr != null) { sr.Close(); }

​ if (fs != null) { fs.Close(); }

​ }

return datanumber;

​ }
```

The resulting output file:

​        //将统计数据写到输出文件

​        public void Output(WordCalculate datanumber, WordTrie wtrie)

​        {

​            FileStream fs = null;

​            StreamWriter sw = null;

​            List<WordTrie.ListUnit> WordList = new List<WordTrie.ListUnit>();

​            try

​            {

​                fs = new FileStream(this.pathOut, FileMode.Create);

​                sw = new StreamWriter(fs);

​                WordList = wtrie.Sort();

​                sw.WriteLine(String.Concat("characters:", datanumber.charactersnumber, "\n"));

​                sw.WriteLine(String.Concat("words:", datanumber.wordsnumber, "\n"));

​                sw.WriteLine(String.Concat("lines:", datanumber.linesnumber, "\n"));

​                sw.WriteLine("\n词频\t单词\n");

​                Console.WriteLine(String.Concat("字符总数", datanumber.charactersnumber, "\n"));

​                Console.WriteLine(String.Concat("单词总数", datanumber.wordsnumber, "\n"));

​                Console.WriteLine(String.Concat("有效行数", datanumber.linesnumber, "\n"));

​                Console.WriteLine("\n词频\t单词\n");

​                for (int i = 0; (i < 10 && i < datanumber.wordsnumber); i++)

​                {

​                    sw.WriteLine(String.Concat(WordList[i].WordNum, '\t', WordList[i].Word, "\n"));

​                    Console.WriteLine(String.Concat(WordList[i].WordNum, '\t', WordList[i].Word, "\n"));

​                }

​            }

​            catch

​            {

​                Console.WriteLine("文档写入失败!");

​            }

​            finally

​            {

​                if (sw != null) { sw.Close(); }

​                if (fs != null) { fs.Close(); }

​            }

​        }

Code is more, only show part of the code, complete code has been submitted.

The result: the input file

Output:

(5) Performance Analysis and Improvement:

The first edition features all of our initial code written in a Main function, intended to function independently, after comparing the performance of loosely coupled, accounting for huge resources Main function.

The second version implements basic functions generate performance analysis reports after independence:

three,

(6) unit test: as detailed teammate

(7) Exception Handling:

Exception handling code: for document reading, writing an exception handling mechanism

(8) Additional functions:
. M-phrase length parameter setting statistical
parameter sets the number of words output-n.
Parameter setting file path to the read-i.
Parameter storage path generated file-o.
Multiparameter implement mixed-use new features such as using the commandline program

(9) The code review:

They pair programming, the programming process two mutual supervision, and common access to relevant information, reference articles also probably the same. Thus did not find such structure, functional problems such as a big problem in the code review process. But the review also found a number of small problems, such as the implementation of the relevant code specifications are not fully in place, there are many code redundancy situation. When interworking code path problem did not communicate well, but have been modified in a timely manner.

four,

(10) Personal sentiment:

It did junction high efficiency of programming than a man, how to explore each other when it comes to problems with access to information; a person at the time of writing the code will also have two pairs of eyes supervision, error correction, thinking; my heart is not even in the face difficulties would be too panic, general through discussion, Baidu can be solved. Experience the most authentic, pair programming really is 1 + 1> 2

At the same time the process of pair programming, C # language a deeper understanding of their own programming quality has been greatly improved. The experimental work by a lot of harvest.

Guess you like

Origin www.cnblogs.com/liuhanhan/p/11672149.html