EE308_Lab2

JoeyNB 2021-09-23 02:57:53
The Link Your Classhttps://bbs.csdn.net/forums/MUEE308FZ
The Link of Requirement of This Assignmenthttps://bbs.csdn.net/topics/600798588
The Aim of This AssignmentCode personally & learn git and github & learn the process of writing a project & learn unit test and performance test
MU STU ID and FZU STU ID19104740_831901308

Github code

https://github.com/JoeyLee0111/Lab2.git 


PSP Form

Personal Software Process StagesEstimated Time/minutesCompleted Time/minutes
Planning1010
Estimate1010
Analysis60100
Design Spec4040
Design Review3030
Coding Standard3030
Design6060
Coding500600
Code Review Planning6060
Test90120
Test Report60100
Postmortem&Process Improvement120 120
Total10701280

Logic Design 

Main thinking.

 First step

Second step

Third step

 Fourth step

Fifth step


Process (with Code)(It's been optimized)

First, we need to get plain text.

def get_text():
    file = open("text.c", "r", encoding="UTF-8")  #Ensure normal opening
    text = file.read()
    for i in '!#$%&()+,-.:;<=>?@[\\]^_{|}~':  # Remove the punctuation
        text = text.replace(i, " ")
    file.close()
    return text

Second, we need to filt some characters and add into the list to make the next four steps easier.

def filting():
    text = get_text().replace("else if", "elseif")
    separator_word = [r'//.*', r'\/\*(?:[^\*]|\*+[^\/\*])*\*+\/', r'".*"'] # Remove // , / and '
    for i in separator_word:
        wordlist1 = re.split(i, text)
        text = ""
        for word in wordlist1:
            text = text + word
    wordlist1 = text.split()
    return wordlist1

Third, I used the traversal way to search keywords. It's a very simple solution to the first problem. Also, this method also works well for the next problem.

Fourth, I used two lists to solve this question and that'll make it more clearer.

def first_second_question():  # Number of output keywords.
    words = filting()
    keyWords = {"auto", "break", "case", "char", "const",
                "continue", "default", "do", "double", "else",
                "enum", "extern", "float", "for", "goto",
                "if", "int", "long", "register", "return",
                "short", "signed", "sizeof", "static", "struct",
                "switch", "typedef", "union", "unsigned",
                "void", "volatile", "while", "elseif"}
    number = 0
    fWords = []
    counts1 = {}
    for word in words:
        if len(word) == 1 or (word not in keyWords):
            continue
        counts1[word] = counts1.get(word, 0) + 1
        fWords.append(word)
        number = number + 1
    number = number + counts1.get("elseif", 0)
    print("total num: {}".format(number))
    num = counts1.get("switch", 0)
    print("switch num: {}".format(num))
    if num == 0:
        print("case num: {}".format(num))
        return
    list2 = []
    flag = -1
    for word in words:
        if word == "switch":
            list2.append(0)
            flag += 1
        elif word == "case":
            list2[flag] += 1
        else:
            continue
    print("case num: ", end="")
    print(" ".join(str(x) for x in list2))
    return fWords

Fifth,  I also used the traversal way to search keywords. Thinking over, I find that Q3 and Q4 can be solved together.The differences between them is else and elseif. By the 'if' , I got the result.

def three_fourth_question():
    fWords=first_second_question()
    listf = []
    num_if_else = 0
    num_if_elseif_else = 0
    for word in fWords:
        if word == "if":
            listf.append(word)
        elif word == "elseif" and listf[-1] != "elseif":
            listf.append(word)
        elif word == "else":
            if listf[-1] == "elseif":
                listf.pop()
                listf.pop()
                num_if_elseif_else += 1
            elif listf[-1] == "if":
                listf.pop()
                num_if_else += 1
    print("if-else num: {}".format(num_if_else))
    print("if-elseif-else num: {}".format(num_if_elseif_else))
    return

Run Result 


Unit Test

import timeit
def fun():
    for i in range(100000):
        a = i * i
print(timeit.timeit('fun()', 'from __main__ import fun', number=1))
import profile
def fun():
    for i in range(100000):
        a = i * i
print(profile.run('fun()'))

 


Optimization

I put all the code that was outside the method inside the method, and the average speed increased by more than 0.003 seconds.


Summary

We studied Python in the first semester of freshman year. This lab is not difficult in the code part. I think the difficult parts are optimization and unit test. Though I tried to make code run quickly, I never do so carefully about every detail. 

I learned how to use Github when I was learning Java. So it can save my time and I can improve my code.

I major in Electronic Engineering. The learning is more about hardware. I hope learn more knowleage about software by this course.

...全文
649 1 打赏 收藏 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
JoeyNB 2021-09-23
  • 打赏
  • 举报
回复

还没写完

代码转载自:https://pan.quark.cn/s/a4b39357ea24 自动驾驶是当前科技界高度关注的研究方向,其研究范畴涵盖了人工智能、计算机视觉、机器学习以及传感器融合等多个重要学科。这份题为"自动驾驶论文"的资料,无疑为人们提供了一个深入了解这一复杂系统的机会。以下是基于其标题和描述所呈现的一些关键知识点的详细阐述: 1. **自动驾驶技术**:自动驾驶指的是车辆在无需人类驾驶员参与的情况下,借助各类传感器和智能算法来感知周围环境,制定行驶路线,并执行驾驶行为。这种技术的核心宗旨在于提升交通安全性、缓解交通压力,并改善出行体验。 2. **Python编程语言**:Python是一种在数据处理和科学计算领域得到广泛应用的高级编程语言,由于其语法简洁且拥有丰富的库支持,经常被应用于自动驾驶领域的数据处理、模型构建和系统集成。 3. **源代码分析**:论文中提供的源代码可能包含了自动驾驶算法的实现细节,可能涵盖环境感知模块(包括图像处理、激光雷达数据解读)、决策模块(涉及路径规划、行为分析)、控制模块(涵盖车辆动力学建模、控制策略设计)等,这些代码可作为学习和研究自动驾驶算法的实践范例。 4. **计算机视觉**:自动驾驶系统中的计算机视觉技术主要用于识别道路标识、行人、其他车辆等,这通常涉及图像分类、目标识别和语义分割等任务,常见的技术包括卷积神经网络(CNN)、区域提议网络(RPN)、YOLO、Faster R-CNN等。 5. **机器学习**:机器学习是自动驾驶技术的核心,用于训练模型以理解和预测复杂的驾驶情境。深度学习,特别是深度强化学习,在决策制定和控制策略方面已取得显著进展。 6. **传感器融合**:自动驾驶汽车通常装备多种传...

183

社区成员

发帖
与我相关
我的任务
社区描述
福州大学 梅努斯国际工程学院 软件工程 教学
软件工程 高校
社区管理员
  • 单步调试
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧