效能分析和PSPhtml
PSP2.1 | Personal Software Process Stages | 預估耗時(分鐘) | 實際耗時(分鐘) |
---|---|---|---|
Planning | 計劃 | 0 | 0 |
Estimate | 估計這個任務須要多少時間 | 900 | 1600 |
Development | 開發 | 350 | 500 |
Analysis | 需求分析 (包括學習新技術) | 60 | 230 |
Design Spec | 生成設計文檔 | 10 | 60 |
Design Review | 設計複審 | 10 | 10 |
Coding Standard | 代碼規範 (爲目前的開發制定合適的規範) | 20 | 30 |
Design | 具體設計 | 20 | 20 |
Coding | 具體編碼 | 270 | 450 |
Code Review | 代碼複審 | 10 | 20 |
Test | 測試(自我測試,修改代碼,提交修改) | 40 | 60 |
Reporting | 報告 | 60 | 120 |
Test Report | 測試報告 | 20 | 40 |
Size Measurement | 計算工做量 | 10 | 20 |
Postmortem & Process Improvement Plan | 過後總結, 並提出過程改進計劃 | 20 | 40 |
合計 | 900 | 1600 |
性能分析圖:
java
public static void main(String args[]) throws IOException { String content = readFile(args[0]); Lib lib = new Lib(); String str1 = lib.countChar(content); String str2 = lib.countWord(content); String str3 = lib.countLine(content); String str4 = lib.countMostWord(); writeFile("result.txt", str1 + "\r\n" + str2 + "\r\n" + str3 + "\r\n" + str4); }
public String countChar(String content) { return "characters: " + content.replaceAll("\r\n", " ").toCharArray().length; }
public String countWord(String content) { int wordNum = 0; char[] ch = content.toCharArray(); int begin = 0, end = 0, len = content.toCharArray().length; String str = null; for (int i = 0; i < len; i++) { boolean flag = !((ch[i] >= 65 && ch[i] <= 90) || (ch[i] >= 97 && ch[i] <= 122) || (ch[i] >= 48 && ch[i] <= 57)); if (flag || i == 0) { // If it is a delimiter or the beginning of the calculation if (flag) { begin = end = i + 1; } else { begin = end = i; } // Find two delimiters while (end < len && ((ch[end] >= 65 && ch[end] <= 90) || (ch[end] >= 97 && ch[end] <= 122) || (ch[end] >= 48 && ch[end] <= 57))) { end++; } if (begin != end) { i = end - 1; if (end - begin >= 4) { str = content.substring(begin, end).toLowerCase(); boolean isWord = true; for (int j = 0; j < 4; j++) { // If the first four are letters if (str.charAt(j) >= 48 && str.charAt(j) <= 57) { isWord = false; break; } } if (isWord) { wordNum++; if (map.containsKey(str)) { map.put(str, map.get(str) + 1); } else { map.put(str, 1); } } } } } else { continue; } } return "words: " + wordNum; }
public String countLine(String content) { int len = content.toCharArray().length; char[] ch = content.toCharArray(); int line = 0; boolean flag = false; for (int i = 0; i < len; i++) { while (i + 1 < len) { // /r/n Text wrap skips calculations if ((ch[i] == 13 && ch[i + 1] == 10)) { break; } if ((ch[i] >= 0 && ch[i] <= 32) || ch[i] == 127) { // Is a blank character i++; continue; } else { i++; flag = true; } } if( i + 1 == len && ! ((ch[i] >= 0 && ch[i] <= 32) || ch[i] == 127)){ flag = true; } i = i + 1; if (flag) { line++; flag = false; } } return "lines: " + line; }
// Computing word frequency public String countMostWord() { // Sort the keys in the HashMap and display the sorted results List<Map.Entry<String, Integer>> infoIds = new ArrayList<Map.Entry<String, Integer>>(map.entrySet()); // Sort the keys in the HashMap Collections.sort(infoIds, new Comparator<Map.Entry<String, Integer>>() { public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) { if (o1.getValue() == o2.getValue()) { return o1.getKey().compareTo(o2.getKey()); } return -(o1.getValue() - o2.getValue()); } }); StringBuilder sb = new StringBuilder(); // The output frequency for (int i = 0; i < infoIds.size() && i < 10; i++) { sb.append("<" + infoIds.get(i).getKey() + ">: " + infoIds.get(i).getValue() + "\r\n"); } return sb.toString(); }
public String inputFileName = null; // The file name to read public String outputFileName = null; // The file name to output public int titleWeight = 10; // title weight public int abstractWeight = 1; // abstract weight public int m = 1; // The length of the phrase public int n = 10; // Output the number of words public static void main(String args[]) throws IOException { Main instance = new Main(); for (int i = 0; i < args.length; i++) { switch (args[i]) { case "-i": instance.I(args[i + 1]); break; case "-o": instance.O(args[i + 1]); break; case "-w": instance.W(args[i + 1]); break; case "-m": instance.M(args[i + 1]); break; case "-n": instance.N(args[i + 1]); break; default: break; } } String content = instance.readFile(instance.inputFileName); Lib lib = new Lib(); lib.countWordOrWordGroupAndFrequency(content, instance.titleWeight, instance.abstractWeight, instance.m, instance.n); // 計算單詞總數 String str1 = lib.printChar(); // calculate Number of characters String str2 = lib.printWord(); // Count words String str3 = lib.printLines(); // Calculate number of lines String str4 = lib.printCountMostWord(instance.n);// Computing word frequency instance.writeFile(instance.outputFileName,str1 + "\r\n" + str2 + "\r\n" + str3 + "\r\n" + str4); } public void I(String str) { inputFileName = str; } public void O(String str) { outputFileName = str; } public void W(String str) { if (Integer.valueOf(str) == 0) { titleWeight = abstractWeight = 1; } else if (Integer.valueOf(str) == 1) { titleWeight = 10; abstractWeight = 1; } } public void M(String str) { m = Integer.valueOf(str); } public void N(String str) { n = Integer.valueOf(str); }
public void countWordOrWordGroupAndFrequency(String content, int w1, int w2, int m1, int n1) { titleWeight = w1; abstractWeight = w2; m = m1; n = n1; boolean isWordGroup = false; if (m >= 2) { isWordGroup = true; } String[] attr = content.split("\r\n\r\n"); String[] str = null; String t1 = null; String t2 = null; for (int i = 0; i < attr.length; i++) { if (attr[i] != null && !attr[i].equals("")) { if (i == 0) { str = attr[i].split("\r\n"); } else { str = attr[i].replaceFirst("\r\n", "").split("\r\n"); } if (str.length == 3) { t1 = str[1].substring(7); t2 = str[2].substring(10); lines += 2; // add line charNum += 2; // add line countChar(t1 + t2); if (isWordGroup) { countWordGroup(t1, true); // Calculate the title countWordGroup(t2, false); // Calculated in this paper, } else { countWord(t1, true); // Calculate the title countWord(t2, false); // Calculated in this paper } } } } }
public void countWordOrWordGroupAndFrequency(String content, int w1, int w2, int m1, int n1) { titleWeight = w1; abstractWeight = w2; m = m1; n = n1; boolean isWordGroup = false; if (m >= 2) { isWordGroup = true; } String[] attr = content.split("\r\n\r\n"); String[] str = null; String t1 = null; String t2 = null; for (int i = 0; i < attr.length; i++) { if (attr[i] != null && !attr[i].equals("")) { if (i == 0) { str = attr[i].split("\r\n"); } else { str = attr[i].replaceFirst("\r\n", "").split("\r\n"); } if (str.length == 3) { t1 = str[1].substring(7); t2 = str[2].substring(10); lines += 2; // add line charNum += 2; // add line countChar(t1 + t2); if (isWordGroup) { countWordGroup(t1, true); // Calculate the title countWordGroup(t2, false); // Calculated in this paper, } else { countWord(t1, true); // Calculate the title countWord(t2, false); // Calculated in this paper } } } } } // Count words public void countWord(String content, boolean isTitle) { char[] ch = content.toCharArray(); int begin = 0, end = 0, len = content.toCharArray().length; String str = null; for (int i = 0; i < len; i++) { boolean flag = !((ch[i] >= 65 && ch[i] <= 90) || (ch[i] >= 97 && ch[i] <= 122) || (ch[i] >= 48 && ch[i] <= 57)); // 判斷是不是分隔符 if (flag || i == 0) { // If it is a delimiter or the beginning of the calculation if (flag) { begin = end = i + 1; } else { begin = end = i; } // Find two delimiters while (end < len && ((ch[end] >= 65 && ch[end] <= 90) || (ch[end] >= 97 && ch[end] <= 122) || (ch[end] >= 48 && ch[end] <= 57))) { end++; } if (begin != end) { i = end - 1; if (end - begin >= 4) { str = content.substring(begin, end).toLowerCase(); boolean isWord = true; for (int j = 0; j < 4; j++) { // If the first four are letters if (str.charAt(j) >= 48 && str.charAt(j) <= 57) { isWord = false; break; } } if (isWord) { wordNum++; if (map.containsKey(str)) { if (isTitle) { map.put(str, map.get(str) + titleWeight); } else { map.put(str, map.get(str) + abstractWeight); } } else { if (isTitle) { map.put(str,titleWeight); } else { map.put(str,abstractWeight); } } } } } } else { continue; } } } // Computing phrase public void countWordGroup(String content, boolean isTitle) { char[] ch = content.toCharArray(); int wordGroupBegin = 0, wordGroupEnd = 0; int firstWordEnd = 0; int begin = 0, end = 0, len = content.toCharArray().length; String str = null; int wordGroupNum = 0; for (int i = 0; i < len; i++) { boolean flag = !((ch[i] >= 65 && ch[i] <= 90) || (ch[i] >= 97 && ch[i] <= 122) || (ch[i] >= 48 && ch[i] <= 57)); // Determines if it is a delimiter if (flag || i == 0) { // If it is a delimiter or the beginning of the calculation if (flag) { begin = end = i + 1; } else { begin = end = i; } // Find two delimiters while (end < len && ((ch[end] >= 65 && ch[end] <= 90) || (ch[end] >= 97 && ch[end] <= 122) || (ch[end] >= 48 && ch[end] <= 57))) { end++; } if (begin != end) { i = end - 1; if (end - begin < 4) { wordGroupNum = 0; } if (end - begin >= 4) { str = content.substring(begin, end).toLowerCase(); boolean isWord = true; for (int j = 0; j < 4; j++) { // If the first four are letters if (str.charAt(j) >= 48 && str.charAt(j) <= 57) { isWord = false; wordGroupNum = 0; break; } } if (isWord) { wordNum++; wordGroupNum++; if (wordGroupNum == 1) { wordGroupBegin = begin; firstWordEnd = end; } if (wordGroupNum == m) { wordGroupEnd = end; str = content.substring(wordGroupBegin, wordGroupEnd).toLowerCase(); if (map.containsKey(str)) { if (isTitle) { map.put(str, map.get(str) + titleWeight); } else { map.put(str, map.get(str) + abstractWeight); } } else { if (isTitle) { map.put(str,titleWeight); } else { map.put(str,abstractWeight); } } wordGroupNum = 0; i = firstWordEnd - 1; wordNum = wordNum - m +1 ; } } else { wordGroupNum = 0; } } } } else { continue; } } }
@org.junit.Test public void Test10() throws IOException { String arg = "H:\\javaweb代碼\\qqqqq\\src\\main\\java\\軟工實踐_test\\input.txt"; String content = readFile(arg); Lib lib = new Lib(); String str1 = lib.countChar(content); // 計算 字符數 String str2 = lib.countWord(content); // 計算單詞總數 String str3 = lib.countLine(content); // 計算行數 String str4 = lib.countMostWord();// 計算詞頻 String test1="characters: 99"; String test2="words: 20"; String test3="lines: 20"; String test4="<aaaa>: 4\n" + "<bbbb>: 1\n" + "<cccc>: 1\n" + "<dddd>: 1\n" + "<eeee>: 1\n" + "<ffff>: 1\n" + "<gggg>: 1\n" + "<hhhh>: 1\n" + "<iiii>: 1\n" + "<jjjj>: 1\n"; Assert.assertEquals(str1,test1); Assert.assertEquals(str2,test2); Assert.assertEquals(str3,test3); Assert.assertEquals(str4,test4); }
qq q qqq qqq.qqq q www w www 結果 characters: 35 words: 0 lines: 2
a b c d 結果 characters: 11 words: 0 lines: 4
abcdefghijklmnopqrstuvwxyz 1234567890 ,./;'[]\<>?:"{}|`-=~!@#$%^&*()_+ 結果 characters: 76 words: 1 lines: 3 <abcdefghijklmnopqrstuvwxyz>: 1
下圖爲對做者發表論文的svg圖顯示前30位 連接 點擊連接能夠在網站上查看svg圖下圖只有靜態效果
python
實現成果的展現
git
詞頻分析 代碼下載github
心得體會web
心得與總結算法
經過此次做業學會了許多除了編寫代碼外的知識,好比GitHub的上傳,單元測試的含義,以及測試數據的設計,等各類非代碼類的技能。固然在代碼這方面也提高很多,主要在於測試階段,設計各種流程圖以及類圖還有微信小程序的界面開發以及博客文檔的撰寫,輔助隊友進行代碼開發。經過此次團隊做業,我進一步對團隊協做有了深的理解,一我的完成代碼開發以及測試真的工做量大,並且在對於測試,客觀性不夠強,團隊配合測試,所使用的測試用例可能更加的全面以及更可以保證測試結果的正確性。總之在此次軟工實踐做業中,雖然花費的時間較多,可是也學到了許多新的技能。累但值得哈哈哈!數據庫
心得與總結小程序
此次做業的做業量雖然很大,可是經過此次做業我學到了不少東西,好比一個明確的需求有多重要,這個做業的需求研究了好幾天,最後仍是經過微信羣裏的同窗進行了討論,還有助教的回答。以後就是編碼和測試,在編碼的過程當中,一開始對需求的不明確致使一直修改代碼,後面等肯定了需求後在寫以後進度快了好多,編寫完代碼以後就和隊友一塊兒測試代碼,調試代碼,知道程序的運行的結果和周圍隊友的結果一致,雖然此次做業花了不少的時間,也學到了不少的東西,也學到了不少和團隊配合的東西。後端