首页 > 其他 > 详细

基于码云开展程序设计教学的自动判分方法和代码框架?

时间:2018-10-01 10:01:28      阅读:153      评论:0      收藏:0      [点我收藏+]

1. 目的

  • 学生基于码云提交程序设计作业;
  • 教师编写检查器,自动对所有人的作业进行判分;

2. 方法

2.1 作业提交要求

  1. 教师建立一个空项目,学生在该项目建立自己的分支(分支名 SEXXX,XXX 为学号后三位),fork该项目到本地;
  2. 学生将完成的程序设计作业 push 到远端自己对应的分支;
  3. 学生完成的程序作业要求满足一定的接口规范:如指定的文件名、函数名、输出输入接口等。

2.2 班级作业检查框架: CheckFramework.sh

  • 只需要学生的分支命名规则不变,每次作业的 CheckFramework不需要修改
  1. 思路

  2. 代码

#!/bin/sh
# Filename: CheckFramework.sh
#
# Usage checkRepo.sh git_repo_url
#
# Algorithm:
#   1.  clone git_repo to local directory
#   2.  checkout to each branch (of every student)
#   3.  testing and evaluating each program written by students.
#   4.  return result  (csv 格式)
#
# Input: git_repo_url
# output: result.csv   
#
######################################################################       

# 0. Global variants
ResultFile="result.csv"           # 返回每个学生的成绩

# 1. check repo_url
if [ $# -lt 1 ]; then
  echo "Usage:";
  echo "\033[1;31m $0 \033[m\033[1;32m gitRepo_url\033[m.";
  echo "Such as:";
  echo "\033[1;31m $0\033[m\033[1;32m  https://gitee.com/se16/HelloWorld.git \033[m";
  exit;
fi

# 2. git clone repository $1
if [ ! -d $1 ]; then
    echo -e "Cloning the Repository: \033[1;31m$1\033[m.";
    #git clone $1;
fi

# 2.1 check if the repository($2) was correctly cloned.
RepoName=`echo ${1##*/} | cut -d "." -f 1`;

echo "the Repository name is \033[1;31m$RepoName\033[m.";

if [ ! -d $RepoName ]; then
    # incorrect repository!
    echo "Cloning repository ${1##*/} \033[1;31mfailed\033[m. Check it's url, please!";
    exit;
fi
    
# 2.2 successfully cloned the repository. Now change working directory to sub-directory named $RepoName
#     step1 : checkout to $bra, 
#     step2 : and check the homeworks one by one, give evaluation score of each homework.
#             (use an function outsides) 
#     step3 : output result.

# 2.2.0 delete previous result.csv
if [[ -f $ResultFile ]]; then
    #statements 
    rm result.csv;
fi

# echo -e "Processing homeworks in each branch named SEXXX";
cd $RepoName;

# 列举本地分支,筛选学生建立的『SEXXX』分支,删除当前分支前的星号 "*"" ,及空格
git branch --list | grep -ai 'se' | sed 's/[\* ]//g' > "../branches.txt";

count=0;

while read bra; do
    let count=count+1;
    # 2.2.1 checkout ; OK
    git checkout -q $bra;  #  -q --quiet          # suppress progress reporting

    # 2.2.2 run test script, and return a score of current branch(student). Dev
    echo "\n-e NO.\033[1;31m$count\033[m. Reviewing homeworks of student NO. \033[1;32m$bra ...\033[m ";

    ## add some scripts ...

    

    ls;
    ## return score of current branch (student's work)
    score=60;

    # 2.2.3 write score to a structure which records all students scores. OK
    echo "$bra,$score" >> ../$ResultFile
done < ../branches.txt

echo "\nFinished";

2.3 作业的检查器: CheckersCaller.sh

  • 每次作业的 Checkers 不一样,需要独立设计
  • 对应地 CheckersCaller.sh 需要对 score 的汇总做微调 (包括:权重、汇总项目)
  1. 思路
  • 依次采用 命令 source Checker_i.sh ,调用不同的检查器;
  • 这些检查器 Checker_i.sh 输出 对应的检查项目得分 score_i
  • 对每一项检查赋予权重 wi, 对所有检查项目得分加权(wi),得到汇总得分 TotalScore
  • 输出TotalScore。(export TotalScore
  1. 代码
#!/bin/sh
# Filename: CheckersCaller.sh
#
# Usage: CheckersCaller.sh
#
# Algorithm:
# 1.    call checkers which export a set of scores
# 2.   summation:sum the scores to TotalScore
# 3.   export TotalScore
#
# Input:Null
# Output:TotalScore   -- summation of each score_i.
#
#####################################################       

TotalScore=0

# 1. 调用一组Checker_i.sh 脚本, 得到一组输出 score_i (单项得分)
source Checker_1.sh
source Checker_2.sh
...
source Checker_n.sh

# 2. 汇总得分 (wi 为每一项的权重)
TotalScore=score_1*w1+score_2*w2+...+score_n*wn

# 3. 输出汇总分 TotalScore
export TotalScore

2.4 作业的单项检查器: Checker_i.sh

  1. 思路

  2. 代码示例

  • 这里给出一个静态代码审查的示例。(Checker_1.sh)
#!/bin/sh
# Checker_1.sh
# usage Checker_1.sh filename
# 思路:
# 1.  检查待测文件是否存在
# 2.  静态检查源代码,给一个评测分 S
#
# Input: filename  -- Program under test(review)
# Output:score_i  -- export score_i
#
#################################################       
# 0. Global variable for export
score_1=0                   # here i=1

# 1. check Usage
if [ $# -lt 1 ]; then
  echo "Usage:";
  echo "\033[1;31m $0 \033[m\033[1;32m filename\033[m.";
  echo "Such as:";
  echo "\033[1;31m $0\033[m\033[1;32m  HelloWord.c \033[m";
  exit;
fi

# 2. Does file $1 exist?  s_temp is the evaluation
if [[ ! -f $1 ]]; then  # not exist
    echo "File \033[1;32m$1\033[m does\033[1;31m not exist\033[m!";
    s_temp=0;
else
    # in this block, you can call other tools or write scripts for evaluating
        call foreign tools or scripts             # return a score 
        ......
        s_temp=score
fi

# 3. export global variable
export score_1
  • 还可以有其他审查项目,需要老师(助教)自己编写检查器,比如可以:

      1. 编译待测代码. 可编译,给一个评测分 s2
      1. 运行N 个测试用例,若通过测试数量 n,则 给出评测得分 s3= totalOfTesting * n/N

3. 其他的思考

3.1 本文的方法:

  • 本文方法的需要老师自己编写检查器(Checker_i.sh),工作量有些大,本文对检查器的接口做了定义,具体检查内容需要老师自己定义。
  • 另外,对学生提交程序的接口有较严格的要求。

3.2 其他方案:

  • 是不是还可以借助 git push 机制,触发自动检查、评分的。 目前,不清楚
  • 本想利用 Jenkins 持续集成的方案,设计触发器的,感觉有点复杂,设置了几次,跑不起来,若有谁搞通了,最好也写篇博客;

基于码云开展程序设计教学的自动判分方法和代码框架?

原文:https://www.cnblogs.com/juking/p/9733978.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!