which course this assignment belongs to | 2022 Fuda University - Software Engineering; Software Engineering Practice - Class W |
---|---|
where is the job requirement | The second assignment of soft engineering practice |
goal of this assignment | Winter Olympics data query: learn JSON data crawling and reading; be familiar with file reading; understand the basic steps of software development, learn unit testing and performance analysis; |
other references | JProfiler , how to generate jar files in idea , java read and write file operations |
Table of contents
3. Description of problem-solving ideas
Q1: Crawl the missing game data
Q3: How to read the commands in the instruction file and write the data into the target file
4. Design and implementation process
4.3 Flow chart of key functions
5. Show the key code of the project, and explain the ideas and notes.
5.1 Judging the legitimacy of the instruction
7. Record the time spent on improving program performance, and describe your improvement ideas
The data crawling mentioned in this blog is only used for teaching research and has no other purpose
1. Gitcode project address.
2. PSP form:
PSP | Personal Software Process Stages | Estimated time spent (minutes) | Actual time spent (minutes) |
---|---|---|---|
Planning | plan | ||
• Estimate | • Estimate how much time this task will take | 25 | 30 |
Development | • development | ||
• Analysis | • Needs analysis (including learning new technologies) | 90 | 240 |
• Design Spec | • Generate design documentation | 15 | 25 |
• Design Review | • Design review | 20 | 25 |
• Coding Standard | • Code specification (make appropriate specification for current development) | 15 | 30 |
• Design | • specific design | 20 | 25 |
• Coding | • Specific coding | 270 | 360 |
• Code Review | • Code review | 25 | 30 |
• Test | • Testing (self-testing, modifying code, submitting changes) | 120 | 480 |
Reporting | Report | ||
• Test Repor | • testing report | 60 | 120 |
• Size Measurement | • Calculate workload | 10 | 25 |
• Postmortem & Process Improvement Plan | • Summarize afterwards and propose process improvement plan | 35 | 35 |
total | 705 | 1545 |
3. Description of problem-solving ideas
3.1 Clear topic requirements:
- Read Json data and output the total list of medals
- Read Json data and output daily schedule
- Read the instructions in input.txt and write the final data to output.txt
Q1: Crawl the missing game data
On the official website of the CCTV Winter Olympics column, open the developer tools page, check and find the game data of the desired date, and convert the required data into the Json format data we need through the tool website.
Q2: Parsing JSON data
Parsing JSON data by importing Google's Gson third-party library
Q3: How to read the commands in the instruction file and write the data into the target file
Use the InputStreamReader and OutputStreamWriter functions to read and write files, and then choose "additional writing" or "rewriting" according to specific requirements.
4. Design and implementation process
4.1 Class distribution
4.2 Function distribution
4.3 Flow chart of key functions
5. Show the key code of the project, and explain the ideas and notes.
5.1 Judging the legitimacy of the instruction
//利用数组【i】逐个输出第i行的文件指令
ArrayList<String> arrayList=fileTest.readFileByLine(input);
for (int i = 0; i < arrayList.size(); i++) {
//逐行实现命令
//空行跳过
if (arrayList.get(i).trim().equals("")||arrayList.get(i).length()==0) {
System.out.println("空行命令");
}
//total指令
else if (arrayList.get(i).trim().equals("total")) {
System.out.println(arrayList.get(i).trim());
new ReadJson().ReadMedals(output);
}
else if (arrayList.get(i).length()>=12) {
String str1=arrayList.get(i).replaceAll(" ","").substring(0,8);
String str2=arrayList.get(i).replaceAll(" ","").substring(8,12);
if (str1.equals("schedule")){
//判断日期是否合法
if (str2.substring(0,2).equals("02")) {
int date=Integer.parseInt(str2.substring(2,4));
System.out.println(date);
if (date<=20&&date>=2) {
new ReadJson().ReadMatch(output,str2);
}
else {
new FileHandle().appendTFile(output,"N/A");
}
}
else{
new FileHandle().appendTFile(output,"N/A");
}
}
}
else{
new FileHandle().appendTFile(output,"Error");
}
}
5.2Json data analysis
JsonParser parse = new JsonParser();
try {
JsonObject json = (JsonObject)parse.parse(new FileReader("data\\"+date+".json"));
JsonObject result = json.get("data").getAsJsonObject();
JsonArray futureArray = result.get("matchList").getAsJsonArray();
for (int i = 0; i < futureArray.size(); ++i) {
JsonObject subObj = futureArray.get(i).getAsJsonObject();
String homename=subObj.get("homename").getAsString();
String awayname=subObj.get("awayname").getAsString();
//将从JSON文件读出来的数据分别存4个字符串中
//比赛时间:
String str1="time:" + subObj.get("startdatecn").getAsString().substring(11,16);
//...........
}
catch(){
//.....
}
6. Unit testing
6.1 Test results:
6.2 Coverage
7. Performance analysis and ideas for improvement
Before improvement: it takes 678000ms to run the command file with 10w instructions (80% of the correct instructions)
8. Exception handling
try {
File file = new File(name);
InputStreamReader inputReader = new InputStreamReader(new FileInputStream(file));
BufferedReader bf = new BufferedReader(inputReader);
// 按行读取字符串
String str;
while ((str = bf.readLine()) != null) {
arrayList.add(str);
}
bf.close();
inputReader.close();
} catch (IOException e) {
e.printStackTrace();
}
9. Experience
- Learn to analyze needs and decompose problems step by step, and find solutions step by step;
- Learned new knowledge and became more aware of the lack of knowledge;
- The writing of the program is very important, but the unit testing and performance analysis of the programmer before the program is released should also be paid attention to;