EE308FZ_Lab1_2: Development Blog
Development Blog
To see the whole version, go to the End and see HTML version on Github.com.
Contents
目录
- Development Blog
- Contents
- PSP Form
- Ideas of Problem-solving
- Design and Implement Processes
- Code Description
- main.py
- common.py
- specific_c.py
- Unit Test
- Screenshots and Description
- Test Data
- Result
- Coverage Optimization
- Performance Testing
- Summary
- End
PSP Form
| Process Stages | Estimated Time(min) | Actual Time(min) |
|---|---|---|
| Analyze Problem | 10 | 5 |
| Planning Development | 10 | 5 |
| Modelling Project | 30 | 15 |
| Design Basic Framework | 20 | 20 |
| Design & Develop Assistant Tools | 30 | 120 |
| Review Assistant Tools | 10 | 30 |
| Develop Prototype working on 1st Level | 30 | 40 |
| Review & Fortify Program | 10 | 30 |
| Design 2nd Level Program | 30 | 40 |
| Develop & Review 2nd Level Program | 30 | 200 |
| Design 3rd Level Program | 30 | 20 |
| Design 4th Level Program | 40 | 80 |
| Develop & Review 3rd & 4th Level Program | 80 | 200 |
| Refine Details | 20 | 5 |
| Final Test | 20 | 10 |
| Reporting | 40 | 70 |
| Summarizing | 30 | 10 |
| Total Time | 470 | 900 |
Ideas of Problem-solving
Problem is given in four level and that's good for Incremental model.
Idea of develop solution:
- Break problem into parts of tasks and queue them.
- Think sub solutions for tasks.
- Code and implement the solutions.
- Test
Design and Implement Processes
Solution steps:
- Determine file type and check
- Read corresponding keywords of the language
- Read the file content
- Solve for 1st level
- Solve for 2nd level
- Solve for 3rd&4th level
graph TD
File_Validation --> Read_Keywords --> Read_File_Content
Read_File_Content --beginning_of_running_any_solution--> sol.1
Read_File_Content -.-> 1st_Level
Read_File_Content -.-> 2nd_Level
Read_File_Content -.-> 3rd_Level
Read_File_Content -.-> 4th_Level
1st_Level --> sol.1
2nd_Level --> sol.2
3rd_Level --> sol.3
4th_Level --> sol.3
sol.1 --> Count_Keywords
Count_Keywords -- generate info--> sol.1
Count_Keywords --> Give_Answer_of_1st_Level
sol.1 --give info--> sol.2
sol.1 --give info--> sol.3
sol.2 --> Iterate_and_Calculate_for_sol.2
sol.3 --> Iterate_and_Calculate_for_sol.3
Iterate_and_Calculate_for_sol.2 -.-> Give_Answers_of_2nd_Level
Iterate_and_Calculate_for_sol.3 -.-> Give_Answers_of_3rd&4th_Level
Iterate_and_Calculate_for_sol.2 --> Function2
Function2 --find 'switch', iterate--> Function2
Function2 --> Count_'case'
Count_'case' --> Give_Answers_of_2nd_Level
Iterate_and_Calculate_for_sol.3 --> Function3
Function3 --find 'if/else', iterate--> Function3
Function3 --> Count_'else_if/else'
Count_'else_if/else' --> Give_Answers_of_3rd&4th_Level
Give_Answer_of_1st_Level --collect--> Completed_Answer
Give_Answers_of_2nd_Level --collect--> Completed_Answer
Give_Answers_of_3rd&4th_Level --collect--> Completed_Answer
Code Description
My project used many to assist the development process. But those do nothing with problem-solving, so I will not explain them here.
Here is key codes and their explanation:
main.py
This is the entrance of whole program. This file contains $sol.1$ and leads to the rest.
# Open File Preparation
f = None
try:
# get the file name
fileName = sys.argv[1]
except IndexError as ie:
estr = OINFOHEADER + f'No file input, no first parameter given. {ie}'
raise IndexError(estr)
# get the program directory
programDir = osp.dirname(sys.argv[0])
# Check ext
fileExt: common.ExtClass = common.ExtClass()
# determine ext
fileExt.extSelect(fileName)
# open file
try:
f = open(fileName)
except FileNotFoundError as fe:
estr = OINFOHEADER + f'{fe}'
raise FileNotFoundError(estr)
# read keywords
keys = []
try:
with open(osp.join(programDir, f'keywords_{fileExt.ext}.txt')) as fkey:
# with open(programDir + dirsep + f'keywords_{fileExt.ext}.txt') as fkey:
t = fkey.read()
keys = t.split()
except FileNotFoundError as fe:
estr = OINFOHEADER + f'{fe}'
raise FileNotFoundError(estr)
# read file data
strs = f.readlines()
# work of 1st level
keycnt, moreinfo = common.countKw(keys, strs)
print('total num: ', keycnt)
# language-specific part of solution's entrance (of .c file)
speMDic = {
'c': specific_c,
'cpp': specific_cpp
}
speMDic[fileExt.ext].entrance(keys, strs, moreinfo)
common.py
This file contains the common parts of codes, i.e. the public codes for all modules.
# Class and method for storing and determining ext
class ExtClass():
ext = None
exti = 0
mode: DevMode = sampleModeCommon
def __init__(self, mode: DevMode=None):
...
def extSelect(self, fileName:str=''):
# debug code
...
# set ext
t1 = fileName.rsplit(sep='.', maxsplit=3)
self.ext = t1[-1]
...
# This function count keywords in strings from the file.
def countKw(keys, strs:list):
...
for i in strs:
cnt1 = 0
for j in keys:
i: str
a = k = 0
while True:
a = i.find(j,a)
if a == -1:
break
a += keylength[j]
if i[a].isalpha() is False:
# found a keyword here
k += 1
# pairs of location prepared for more operation
p = [idi, a - keylength[j], j]
locations.append(p)
cnt1 += k
cnt2 += cnt1
idi += 1
return cnt2, locations
specific_c.py
Contains part of solutions for c language.
# addon entrance
def entrance(pkeys, pstrs, pmoreinfo=None):
...
locations = extractWordsBraces(strs, wordLocation)
# process switch-case
locations_SwCsBraces = extractSwCsBraces(locations)
SwCnt_Group = countSwCs(locations_SwCsBraces)
# output SwCs
print(f'switch num: ', SwCnt_Group.__len__())
print('case num: ', end='')
for i in SwCnt_Group:
print(i, end=' ')
print('')
# process if-else, if-elseif-else
# these codes are only designed for cases with entire braces attached to keywords.
locations_IfEsBraces = extractIfEsBraces(locations)
cnt_IfEs, cnt_IfEsifEs = countIfEs(locations_IfEsBraces)
cntIFES = [cnt_IfEs, cnt_IfEsifEs]
# output IFES
print(f'if-else num: ', cnt_IfEs)
print(f'if-elseif-else num: ', cnt_IfEsifEs)
# This function count 'switch's and each group's 'case's. Support nested structure.
def countSwCs(plocations_SwCsBraces):
...
i = 0
while i < length:
# find a 'switch', do iteration
if plocations_SwCsBraces[i][2]=='switch':
...
interval = [i, endBrace+1]
intervals.append(interval)
# iterate
CsCntItr = countSwCs(plocations_SwCsBraces[i+1:endBrace+1])
SwCnt_Group.extend(CsCntItr)
# print(SwCnt_Group)
i = endBrace
i += 1
...
# count 'case's of given strings
i = 0
while i < length:
...
if plocations_SwCsBraces[i][2]=='case':
CsCnt += 1
i += 1
if CsCnt!=0:
SwCnt_Group.append(CsCnt)
return SwCnt_Group
# This function figures the answers of sol.3. Support nested structure.
def countIfEs(plocations_IfEsBraces):
...
while i < length:
# find a/an 'if'/'else', do iteration
if plocations_IfEsBraces[i][2] == 'if' or \
(plocations_IfEsBraces[i][2] == 'else' and plocations_IfEsBraces[i+1 if i+1 <length else i][2] != 'if'):
...
interval = [i + 2, endBrace]
intervals.append(interval)
# iterate
retv = countIfEs(plocations_IfEsBraces[i + 1:endBrace + 1])
...
cnt_IfEs += retv[0]
cnt_IfEsifEs += retv[1]
i = endBrace
i += 1
...
# count cases of 'if-else' and 'if-elseif-else' of given strings
i = 0
tlength = tpifesloclist.__len__()
while i < tlength:
if tpifesloclist[i][2] == 'else':
if tpifesloclist[i+1 if i+1<tlength else i][2] == 'if':
cnt_IfEsifEs += 1
while i < tlength:
if tpifesloclist[i][2] == 'else' and tpifesloclist[i+1 if i+1<tlength else i][2] != 'if':
break
i += 1
elif tpifesloclist[i+1 if i+1<tlength else i][2] == '{':
cnt_IfEs += 1
i += 1
cntIFES = [cnt_IfEs, cnt_IfEsifEs]
return cntIFES
Unit Test
my_unit_test.py
Screenshots and Description
Test Data
Test file, $testfile.c$, is copied from website. See the website at the End.
Result
Picture shown below tells that of 4th level, i.e. the ultimate requirement. It goes to expectation.


Coverage Optimization
Comment useless codes.

$81$% ->$82$%
Performance Testing

Summary
In this program, I used lots of new knowledge. Software Engineering is truly a systematic engineering. Methodology is really important.
End
| The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZU202201 |
|---|---|
| The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/608734907 |
| The Aim of This Assignment | Note the development processes. |
| MU STU ID and FZU STU ID | 20123850_832001217 |
Project on Github.com: https://github.com/LiuJiewenTT/ee308fz_lab1
URL on github.com of this passage(download): https://liujiewentt.github.io/ee308fz_lab1/development%20blog.md
URL on github.com of this passage(view with Github md): https://github.com/LiuJiewenTT/ee308fz_lab1/tree/main/development%20blog.md
URL on github.com of this passage(view as html): https://liujiewentt.github.io/ee308fz_lab1/development%20blog.html
URL on csdn.net of this passage(view as html): https://bbs.csdn.net/topics/608838406
相关推荐
技术转移联合体在跨境技术转移中面临哪些合规要求和标准限制?.docx
技术转移联合体在跨境技术转移中面临哪些合规要求和标准限制?
省级科技管理部门在制定技术交易补贴政策时,通常优先支持哪类平台?.docx
科易网(厦门科易网科技有限公司)创立于2007年,是技术转移与科技创新数智化服务平台,拥有国家科技成果转化服务示范基地、国家技术转移示范机构等资质。平台以“AI+科技成果转化”为核心,整合成果、专利、专家、政策等多维数据,构建知识图谱与科创智能体,面向企业、政府、高校院所提供成果转化、技术需求对接、产业服务等数智化解决方案。截至目前,已服务全国企业超43万家,推动落地项目11800余项,总金额逾80亿元
水泥稳定碎石基层施工安全交底要点(含现场管控项).docx
水泥稳定碎石基层施工安全交底要点(含现场管控项)
普通职员月度工作总结知识笔记(结构+话术+案例).docx
普通职员月度工作总结知识笔记(结构+话术+案例)
水稳层冬期基层施工技术方案(含防冻与保温措施).docx
水稳层冬期基层施工技术方案(含防冻与保温措施)


