CSE 390A, Spring 2014 Assignment 6: Advanced Shell Scripting

本文介绍了一个用于自动评估Bash脚本作业的工具,该工具能够运行学生提交的脚本并比较其输出是否符合预期,同时检查脚本中的注释数量,最终给出评分。

This assignment focuses on Bash shell scripting at a more advanced level.  Electronically turn in file gradeit.sh as described in this document.  You will also want the support files from the Homework section of the course web site.   

For this assignment, you will write a script gradeit.sh that "grades" solutions to a hypothetical homework assignment.  You're given a set of students' solution files, each of which is supposed to be named gettysburg.sh (though some  students used the wrong file name...), and your script will run each of them one at a time, examining the output to see if it matches the expected output.  Your script will also examine the code to see whether it has enough comments.  The output from a run of your program will look like this: 

$ ./gradeit.sh 50 

Retro Grade-It, 1970s version 

Grading with a max score of 50 

 

Processing bensonl ... 

bensonl has correct output 

bensonl has 3 lines with comments 

bensonl has earned a score of 50 / 50 

 

Processing dravir ... 

dravir has incorrect output (1 lines do not match) 

dravir has 0 lines with comments 

dravir has earned a score of 38 / 50 

 

Processing joeblow ... 

joeblow has incorrect output (4 lines do not match) 

joeblow has 5 lines with comments 

joeblow has earned a score of 30 / 50 

 

Processing oterod ... 

oterod did not turn in the assignment 

oterod has earned a score of 0 / 50

To get started, download the following support files from the course web site:  students.tar.gz : This file contains a set of fake student solutions to examine.  Extract this file with the tar command (see slide 17 from lecture 6 for information about how to decompress a tar file).  It will create a set of student folders and files such as:

students/bensonl/gettysburg.sh 

students/oterod/GETTYSburg.sh 

students/stepp/gettysburg.sh 

 Each student's directory is supposed to contain a file representing that student's homework solution (though some students have not turned in the file properly, so it may not exist or may have the wrong name).

 Note that you are not targeting the specific students shown above; your code should not specifically mention names like stepp or bensonl.  Your code should process all students in the students directory.  expected.txt : This file contains the expected homework output.  Download this file into your assignment folder.  This is the text you'll compare to each student's output to see whether it is correct. You must write a script gradeit.sh that gives each student a score on the assignment.  Your program should accept the maximum score as a command-line argument.  For example, to run it with a max score of 50 points, you would type: 

$ ./gradeit.sh 50 

If the user does not pass a value for the maximum points, your script should print the following error message and exit:

$ ./gradeit.sh 

Usage: ./gradeit.sh MAXPOINTS

 You do not need to check this argument for validity.  If an argument is passed, you may assume it is a positive integer.

Processing Each Student:

 If your script is passed an argument, it should assume that the current directory contains 1) a students/ directory whose contents resemble those in the sample files you have been given (containing one directory per student, each named with the student’s id) and 2) expected.txt.  Your script will examine each student in the students/ folder as follows:  

 Run the student's gettysburg.sh file, using the student's folder as the working directory.  (You may want to capture the student's output into a file.)  Note that the student script files may not have execute permission, so you should manually invoke bash to run them, such as: bash ./gettysburg.sh 

 Compare the student's output against the expected output file using diff. Run diff so that it ignores all white space (explore the options: –w and –b). Count the number of lines that do not match. To simplify things, we will consider any line of diff output containing a < or a > to count as 1 line of unmatched content.  Produce output in this format: 

bensonl has correct output 

or:

smith has incorrect output (8 lines do not match) 

For each unmatched line, deduct 5 points from the student's score.  For example, if the diff output has 4 lines that have < or >, the student should lose 20 points.  If the student loses more points than there are points in the assignment, the student should receive 0 points. (Hint: You can look for each of < and > separately and total them, or search for "[<>]" to match either one.)

 Check whether the student has sufficient code comments.  Comments are worth 7 points on the assignment.  A comment is defined as any line that contains a  # .  A student must have 3 or more lines of comments (if the file has an initial #!/bin/bash line, we will count that as a comment line, too).  A student that has fewer than 3 lines of comments should lose 7 points from his/her assignment score, down to a minimum of 0.  Produce output such as: 

toddk4 has 5 lines with comments 

Output each student's score on the assignment.  If a student jones has no differing lines of output and 5 lines of comments in his script, the score output for that student would be:

jones has earned a score of 50 / 50 

 If student davis has 3 differing lines of output (-15) and 2 lines of comments (-7), the score output would be:

davis has earned a score of 28 / 50 

  If the student did not turn in the program or incorrectly named the file, the student gets 0 points on the assignment.  (See the various if tests from lecture such as -d, -e, etc. to see whether files exist or have various properties.)  If the user lewis did not turn in a proper gettysburg.sh file, you would output the following:

lewis did not turn in the assignment 

 See the course web site for several complete sample output runs of the program. You may assume that no student's program tries to do anything evil to your computer, such as erasing all your files.  You may also assume that students' code will not lock up and get stuck in any sort of infinite loop.  It is okay if your gradeit.sh script creates temporary files while doing its work, though it would be best to remove them as you go along.

 Development Strategy (suggested): 

 Make your script able to simply output the names of all of the students to be processed. 

 Make your script able to simply run each student's gettysburg.sh program and show its output on the terminal. 

 Some tasks in your script will involve running Unix commands and capturing their output with back-ticks, ` `.  Since such commands run silently as their output is being captured, consider simply running the command first without back-ticks to see that the command is running properly and producing results that you expect.

  Remember to use echo statements to output partial results, computations, commands, etc. to verify them. Your script should work if placed in any directory containing expected.txt and a students/ directory. Do not hard code in a specific directory on your machine or your home directory on attu. This is important for grading!! Each Linux/Unix box can be slightly different; for full credit, your commands must be able to work properly either on attu, or on the basement lab computers, or the cse virtual machine image.  For reference, our solution to this assignment is 60 lines long (40 "substantive" lines on the CSE 142 Indenter tool). 

Answer:

gradeit.sh如下所示:

#!/bin/bash

!([ -n "$1" ]) && echo "Usage: ./gradeit.sh MAXPOINTS" && exit -1

echo "Retro Grade-It, 1970s version"
echo "Grading with a max score of $1"

f(){
	echo "Processing $1 ..."
	let s=0
	if !([ -n "`ls students/$1/ | grep gettysburg.sh`" ])
	then
	    echo "$1 did not turn in the assignment"
	else
		let s=$2
		./students/$1/gettysburg.sh > tmp
		diff -w expected.txt tmp > dif
		let DiffLine=`cat dif | grep "[<>]" | wc -l`
		let s=$s-$DiffLine*5
		if [ $DiffLine -eq 0 ]
		then
		    echo "$1 has correct output"
		else
			echo "$1 has incorrect output ($DiffLine lines do not match)"
	    fi
	    let Comments=`cat students/$1/gettysburg.sh | grep "#" | wc -l`
	    echo "$1 has $Comments lines with comments"
	    if [ $Comments -lt 3 ]
	    then
	        let s=$s-7
	    fi
	    if [ $s -lt 0 ]
	    then
	        let s=0
	    fi
	    rm tmp dif
	fi
	echo "$1 has earned a score of $s / $2"
}

let p=$1
for dir in `ls students/`
do
	if test -d students/$dir
	then
	    echo
	    f $dir $p
	fi
done

代码下载地址: https://pan.quark.cn/s/a4b39357ea24 在计算机视觉技术中,数据集扮演着训练和评估模型的核心角色。Labelme作为一个广受欢迎的开源工具,能够支持用户以交互方式对图像进行标注,而COCO(Common Objects in Context)则是一种被广泛采纳的数据集标准格式,适用于包括物体检测、图像分割在内的多种任务。本文将详细阐述如何将Labelme生成的标注数据转换为COCO数据集的标准格式。 Labelme标注的图像在输出为JSON格式时,会包含以下核心内容: 1. `version`: 指明JSON文件的版本信息。 2. `flags`: 目前未定义或保持为空,预留用于未来的功能扩展。 3. `shapes`: 列表形式存储对象的形状信息,每个形状项包含`label`(对象类别名称),`points`(构成对象边缘的多边形顶点),以及`shape_type`(通常为“polygon”)。 4. `imagePath`和`imageData`: 提供原始图像的存储路径和二进制数据,便于后续图像的还原。 5. `imageHeight`和`imageWidth`: 明确标注图像的垂直和水平尺寸。 COCO数据集的标准格式中定义了三种主要的标注类型: 1. Object instances(目标实例):主要用于执行物体检测任务。 2. Object keypoints(目标上的关键点):适用于人体姿态估计相关应用。 3. Image captions(看图说话):用于生成图像的文本描述。 COCO的JSON结构中包含以下基本组成部分: 1. `images`:记录图像的基本属性,包括`height`(高度)、`...
内容概要:本文围绕基于Basisformer模型的时间序列锂离子电池SOC(State of Charge,荷电状态)预测展开研究,利用PyTorch深度学习框架构建并训练模型,旨在提升锂电池SOC估计的准确性与鲁棒性。该方法融合Transformer架构的核心机制,通过引入基函数(Basis)分解策略,有效捕捉电池充放电过程中长时序、非线性动态特征,增强模型对复杂工况的适应能力。研究不仅详细阐述了Basisformer的网络结构设计、注意力机制优化与训练流程,还提供了完整的Python代码实现方案,涵盖数据预处理、模型搭建、损失函数定义、训练验证及结果可视化等环节,便于科研人员快速复现、调优并拓展至其他电池状态预测任务。; 适合人群:具备一定深度学习与Python编程基础,熟悉PyTorch框架,从事电池管理系统(BMS)、新能源汽车、储能系统、智能传感等领域的高校研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于动力电池与储能系统的实时SOC估算模块,提升系统安全性与能量利用效率;②作为学术研究的基础模型,用于复现、改进基于Transformer的时间序列预测方法在电化学系统中的应用;③为数据驱动的电池健康状态(SOH)、剩余使用寿命(RUL)联合估计提供可扩展的技术框架。; 阅读建议:建议读者结合所提供的代码与公开电池数据集(如NASA、CALCE等)进行动手实践,深入理解模型的输入输出结构与时序建模逻辑,同时可尝试引入温度、老化周期等多维特征,或融合物理模型构建混合预测架构,以进一步提升预测精度与泛化能力。
内容概要:本文系统阐述了基于动态规划算法优化插电式混合动力电动汽车(PHEV)能源管理的技术方案,结合Matlab与Simulink工具实现完整的仿真建模与代码开发。通过动态规划这一全局优化方法,在已知驾驶循环条件下,精确求解发动机、电机及电池之间的最优能量分配策略,以实现燃油消耗与排放的最小化目标,解决PHEV多能源路径规划中的复杂决策问题。文中提供了详尽的仿真模型构建流程与算法实现步骤,涵盖车辆动力学建模、能量管理架构设计、状态空间定义、代价函数构造、最优控制律求解及结果可视化分析等关键环节,全面揭示PHEV能量管理系统的内在机制与优化逻辑。; 适合人群:具备一定Matlab/Simulink编程基础,从事新能源汽车、智能控制、电力电子、自动化或交通运输工程等相关领域的研究生、科研人员及工程技术人员,尤其适合专注于车辆能量管理策略、节能控制算法研究的专业人士。; 使用场景及目标:①深入掌握动态规划在混合动力汽车能量管理中的理论基础与工程实现方法;②学习如何在Matlab/Simulink环境中搭建PHEV整车仿真平台并实施多目标优化仿真;③为学术研究、学位论文撰写或实际工程项目提供可复用的算法框架、模型模板与技术支持,支撑后续对等效燃油消耗最小化策略(ECMS)、模型预测控制(MPC)、实时优化算法等的对比研究与性能评估。; 阅读建议:建议读者结合所提供的完整代码与Simulink模型文件,逐模块调试运行,重点理解状态变量离散化处理、前后向递推求解过程、惩罚项设置以及边界条件处理等核心技术细节,同时可进一步拓展应用于不同工况场景、不同车型结构或与其他优化算法(如庞特里亚金极小值原理PMP)的对比验证,从而深化对PHEV能量管理实时性与全局性平衡问题的理解。
内容概要:本文围绕基于多虚拟同步发电机(VSG)的独立微网系统,开展多目标二次控制策略的MATLAB/Simulink建模与仿真研究。通过构建包含多个VSG单元的独立微网系统,设计并实现了能够同时实现频率与电压的无静差恢复、有功/无功功率精确分配以及环流有效抑制的综合控制目标的二次控制方法。研究重点在于控制策略的整体架构设计、关键控制模块的数学建模及其在Simulink环境中的精细化实现,通过大量仿真实验验证了所提控制策略在不同工况下的有效性、动态响应性能及系统鲁棒性。; 适合人群:具备电力系统分析、自动控制理论及现代电力电子技术等专业知识背景,熟悉MATLAB/Simulink仿真工具,从事新能源发电、微电网运行与控制、分布式能源系统集成等相关领域的科研人员、工程技术人员及高校研究生。; 使用场景及目标:① 深入掌握多VSG独立微网系统的建模方法与稳定性分析要点;② 理解并复现兼顾静态精度与动态品质的多目标二次协同控制算法;③ 为新型微网控制保护装置的研发及先进控制策略的工程化应用提供可靠的仿真验证平台和技术储备。; 阅读建议:学习者应在巩固电力系统基础理论的前提下,重点关注控制算法的设计逻辑、各控制环节间的耦合关系以及Simulink模块的搭建技巧,建议通过调整系统参数、设置不同的负载投切与故障扰动工况进行反复仿真,以深刻理解控制策略的内在机理与适应能力。
【通用视觉框架】基于Qt+Halcon开发的仿Visionmaster的通用视觉框架软件,全套源码,开箱即用 1.1 背景 ​ 本项目软件开发意图为实现对Halcon、Opencv算子及其它视觉软件的便捷使用,由于Halcon和Opencv使用相比VisionPro较为麻烦,故此本软件仿照海康VisionMaster的流程图式操作,实现对Halcon、Opencv及其它视觉软件的二次开发。 2.1 软件概述 本软件使用Qt框架进行开发,实现对视觉流程的自由搭配,市场上对标海康威视的VisionMaster; 本软件使用插件化开发框架,可使用提供的二次开发库自行添加新功能算子和新模块(将生成的插件放置到对应目录下即可); 2.2 功能概述: 视觉流程图式编程:实现对视觉/数据处理算子的自由编程,从而实现各类复杂的视觉需求 项目读取保存:编程的视觉项目进行保存或者读取 图像显示:主界面中可以显示及监控视觉算子的图像处理情况 日志消息显示:显示软件运行过程中出现的日志消息 多语言:可进行多种语言切换 2.3 开发平台 主开发语言:Qt(C++) C++语言标椎:C++17 开发环境:Window/Linux 编程平台:Qt Creator 编译器: |版本 | MSVC | Qt 6.4.0 MSVC2019 64bit | | Mingw | Qt 6.4.0 MinGW 64-bit | 视觉工具:Halcon19.11 Progress X64 资源介绍请查阅:https://blog.csdn.net/m0_37302966/article/details/146980317 更多视觉框架资源:https://blog.csdn.net/m0_37302966/article/details/146583453
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值