Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automatic Programming Assignment Grading Scripts
#!/bin/bash
# Copyright 2016 Ahmet Arslan
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Clones the homework repository (e.g. https://github.com/AnadoluUniversityCeng/bim313-hw1-YgzNsl) for a given GitHub user name (e.g. YgzNsl)
# and executes maven goals.
#
# Requires git, maven, java and grep installed on your computer.
#
if [ -z "$1" ];
then
echo "Need a GitHub username, e.g. 'YgzNsl'"
echo "Usage grade.sh <GitHubUserName>"
echo "example: grade.sh YgzNsl"
exit 1
fi
declare -i grade=0
FOLDER="bim313-hw1-$1";
rm -rf $FOLDER
URL="https://github.com/AnadoluUniversityCeng/$FOLDER.git"
echo "<hw>" >> "/var/www/bim313.com/public_html/hw1.xml"
#########################################################
##### This check only works for public repositories #####
#########################################################
response=$(curl https://github.com/AnadoluUniversityCeng/$FOLDER);
if [ "{\"error\":\"Not Found\"}" == "${response}" ];
then
echo $response
echo "$(date) Homework grade for $1 = $grade"
echo "<username>$1</username><date>$(date)</date><grade>$grade</grade>" >> "/var/www/bim313.com/public_html/hw1.xml"
echo "</hw>" >> "/var/www/bim313.com/public_html/hw1.xml"
exit 1
fi;
echo "cloning $URL ..."
git clone $URL
cd $FOLDER
mvn clean package
java -jar target/HW1-1.0.jar > cities.txt
if grep 'ESK..EH.R' cities.txt | grep 'G.RESUN' | grep 'ARDAHAN'
then
echo "OK";
grade=$(( grade + 20 ))
else
echo "NOT OK";
fi
if grep 'A.RI' cities.txt | grep 'ERZ.NCAN' | grep 'MU.LA'
then
echo "OK";
grade=$(( grade + 20 ))
else
echo "NOT OK";
fi
if grep ADANA cities.txt | grep ADIYAMAN | grep AFYON
then
echo "OK";
grade=$(( grade + 20 ))
else
echo "NOT OK";
fi
if grep 'D.YARBAKIR' cities.txt | grep 'KIR.EH.R' | grep ZONGULDAK
then
echo "OK";
grade=$(( grade + 20 ))
else
echo "NOT OK";
fi
if grep 'U.AK' cities.txt | grep ZONGULDAK | grep BARTIN
then
echo "OK";
grade=$(( grade + 20 ))
else
echo "NOT OK";
fi
if grep 'KIRKLAREL.' cities.txt | grep 'KIR.EH.R' | grep 'R.ZE'
then
echo "NOT OK";
grade=$(( grade - 20 ))
else
echo "OK";
fi
if grep 'ESK..EH.R' cities.txt | grep 'N..DE' | grep KARAMAN
then
echo "NOT OK";
grade=$(( grade - 20 ))
else
echo "OK";
fi
if grep ORDU cities.txt | grep TOKAT | grep YALOVA
then
echo "NOT OK";
grade=$(( grade - 20 ))
else
echo "OK";
fi
if grep YALOVA cities.txt | grep 'KARAB.K' | grep 'OSMAN.YE'
then
echo "NOT OK";
grade=$(( grade - 20 ))
else
echo "OK";
fi
if grep 'B.TL.S' cities.txt | grep 'DEN.ZL.' | grep 'K.L.S'
then
echo "NOT OK";
grade=$(( grade - 20 ))
else
echo "OK";
fi
echo "$(date) Homework grade for $1 = $grade"
echo "<username>$1</username><date>$(date)</date><grade>$grade</grade>" >> "/var/www/bim313.com/public_html/hw1.xml"
echo "</hw>" >> "/var/www/bim313.com/public_html/hw1.xml"
#!/bin/bash
# Copyright 2016 Ahmet Arslan
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Clones the homework repository (e.g. https://github.com/AnadoluUniversityCeng/bim313-hw2-hnbirsen) for a given GitHub user name (e.g. hnbirsen)
# and executes maven goals.
#
# Requires git, maven, java and grep installed on your computer.
#
if [ -z "$1" ];
then
echo "Need a GitHub username, e.g. 'hnbirsen'"
echo "Usage grade2.sh <GitHubUserName>"
echo "example: grade2.sh hnbirsen"
exit 1
fi
export LC_ALL=en_US.UTF-8
declare -i grade=0
FOLDER="bim313-hw2-$1";
rm -rf $FOLDER
URL="https://github.com/AnadoluUniversityCeng/$FOLDER.git"
echo "<hw>" >> "/var/www/bim313.com/public_html/hw2.xml"
#########################################################
##### This check only works for public repositories #####
#########################################################
#response=$(curl https://github.com/AnadoluUniversityCeng/$FOLDER);
#if [ "{\"error\":\"Not Found\"}" == "${response}" ];
#then
# echo $response
# echo "<username>$1</username><date>$(date)</date><grade>$grade</grade>" >> "/var/www/bim313.com/public_html/hw2.xml"
# echo "</hw>" >> "/var/www/bim313.com/public_html/hw2.xml"
# exit 1
#fi;
echo "cloning $URL ..."
git clone $URL
cd $FOLDER
mvn clean package
java -jar target/HW2-1.0.jar -n 5 -p longest > longest5.txt
if grep -i '^\s*8473km:ED.RNE->HAKKAR.->KIRKLAREL.->MU.LA->VAN->ED.RNE\s*$' longest5.txt
then
echo "OK";
grade=$(( grade + 25 ))
else
echo "NOT OK";
fi
java -jar target/HW2-1.0.jar -n 5 -p shortest > shortest5.txt
if grep -i '^\s*492km:B.LEC.K->BURSA->KOCAEL.->SAKARYA->YALOVA->B.LEC.K\s*$' shortest5.txt
then
echo "OK";
grade=$(( grade + 25 ))
else
echo "NOT OK";
fi
java -jar target/HW2-1.0.jar -n 7 -p longest > longest7.txt
if grep -i '^\s*11731km:ED.RNE->HAKKAR.->KIRKLAREL.->MU.LA->S..RT->TEK.RDA.->VAN->ED.RNE\s*$' longest7.txt
then
echo "OK";
grade=$(( grade + 25 ))
else
echo "NOT OK";
fi
java -jar target/HW2-1.0.jar -n 7 -p shortest > shortest7.txt
if grep -i '^\s*772km:BOLU->KOCAEL.->SAKARYA->ZONGULDAK->BARTIN->KARAB.K->D.ZCE->BOLU\s*$' shortest7.txt
then
echo "OK";
grade=$(( grade + 25 ))
else
echo "NOT OK";
fi
echo "<username>$1</username><date>$(date)</date><grade>$grade</grade>" >> "/var/www/bim313.com/public_html/hw2.xml"
echo "</hw>" >> "/var/www/bim313.com/public_html/hw2.xml"
#!/bin/bash
# Copyright 2016 Ahmet Arslan
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Clones the homework repository (e.g. https://github.com/AnadoluUniversityCeng/bim313-hw3-hnbirsen) for a given GitHub user name (e.g. hnbirsen)
# and executes maven goals.
#
# Requires git, maven, java and grep installed on your computer.
#
if [ -z "$1" ];
then
echo "Need a GitHub username, e.g. 'hnbirsen'"
echo "Usage grade3.sh <GitHubUserName>"
echo "example: grade3.sh hnbirsen"
exit 1
fi
export LC_ALL=en_US.UTF-8
declare -i grade=0
FOLDER="bim313-hw3-$1";
rm -rf $FOLDER
URL="https://github.com/AnadoluUniversityCeng/$FOLDER.git"
echo "<hw>" >> "/var/www/bim313.com/public_html/hw3.xml"
#########################################################
##### This check only works for public repositories #####
#########################################################
#response=$(curl https://github.com/AnadoluUniversityCeng/$FOLDER);
#if [ "{\"error\":\"Not Found\"}" == "${response}" ];
#then
# echo $response
# echo "<username>$1</username><date>$(date)</date><grade>$grade</grade>" >> "/var/www/bim313.com/public_html/hw3.xml"
# echo "</hw>" >> "/var/www/bim313.com/public_html/hw3.xml"
# exit 1
#fi;
echo "cloning $URL ..."
git clone $URL
cd $FOLDER
mvn clean package
for type in News Blog;
do
for month in SEPTEMBER AUGUST JULY;
do
for field in title content;
do
java -jar target/HW3-1.0.jar -file /home/aarslan/signalmedia-1m.jsonl -field $field -month $month -type $type > "$month$type$field.txt"
done
done
done
if grep -i '^\s*numArticles:732504\s*$' SEPTEMBERNewstitle.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*wordCount:7119816\s*$' SEPTEMBERNewstitle.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*averageLength:9\.71983\s*$' SEPTEMBERNewstitle.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*numArticles:732504\s*$' SEPTEMBERNewscontent.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*wordCount:290660073\s*$' SEPTEMBERNewscontent.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*averageLength:396\.80339\s*$' SEPTEMBERNewscontent.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*numArticles:1859\s*$' AUGUSTNewscontent.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*wordCount:18577\s*$' AUGUSTNewstitle.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*numArticles:254744\s*$' SEPTEMBERBlogtitle.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*wordCount:2150908\s*$' SEPTEMBERBlogtitle.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*averageLength:8\.44341\s*$' SEPTEMBERBlogtitle.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*numArticles:254744\s*$' SEPTEMBERBlogcontent.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*wordCount:95819346\s*$' SEPTEMBERBlogcontent.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*averageLength:376\.13976\s*$' SEPTEMBERBlogcontent.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*numArticles:1040\s*$' JULYBlogcontent.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*wordCount:590621\s*$' JULYBlogcontent.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*averageLength:567\.90481\s*$' JULYBlogcontent.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*numArticles:9728\s*$' AUGUSTBlogtitle.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*wordCount:76596\s*$' AUGUSTBlogtitle.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
if grep -i '^\s*averageLength:7\.87377\s*$' AUGUSTBlogtitle.txt
then
echo "OK";
grade=$(( grade + 5 ))
else
echo "NOT OK";
fi
echo "<username>$1</username><date>$(date)</date><grade>$grade</grade>" >> "/var/www/bim313.com/public_html/hw3.xml"
echo "</hw>" >> "/var/www/bim313.com/public_html/hw3.xml"
#!/bin/bash
# Copyright 2016 Ahmet Arslan
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > "/var/www/bim313.com/public_html/hw1.xml"
echo "<?xml-stylesheet type=\"text/xsl\" href=\"simple.xsl\" ?>" >> "/var/www/bim313.com/public_html/hw1.xml"
echo "<homework>" >> "/var/www/bim313.com/public_html/hw1.xml"
while read -r username || [[ -n "$username" ]]; do
echo "Grading username: $username"
./grade.sh $username &> "/var/www/bim313.com/public_html/$username.txt"
done <usernames.txt
echo "</homework>" >> "/var/www/bim313.com/public_html/hw1.xml"
#!/bin/bash
# Copyright 2016 Ahmet Arslan
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > "/var/www/bim313.com/public_html/hw2.xml"
echo "<?xml-stylesheet type=\"text/xsl\" href=\"simple.xsl\" ?>" >> "/var/www/bim313.com/public_html/hw2.xml"
echo "<homework>" >> "/var/www/bim313.com/public_html/hw2.xml"
while read -r username || [[ -n "$username" ]]; do
echo "Grading username: $username"
./grade2.sh $username &> "/var/www/bim313.com/public_html/$username.txt"
done <usernames.txt
echo "</homework>" >> "/var/www/bim313.com/public_html/hw2.xml"
#!/bin/bash
# Copyright 2016 Ahmet Arslan
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > "/var/www/bim313.com/public_html/hw3.xml"
echo "<?xml-stylesheet type=\"text/xsl\" href=\"simple.xsl\" ?>" >> "/var/www/bim313.com/public_html/hw3.xml"
echo "<homework>" >> "/var/www/bim313.com/public_html/hw3.xml"
while read -r username || [[ -n "$username" ]]; do
echo "Grading username: $username"
./grade3.sh $username &> "/var/www/bim313.com/public_html/$username.txt"
done <usernames.txt
echo "</homework>" >> "/var/www/bim313.com/public_html/hw3.xml"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment