--- a/TAs Tue Jan 22 12:53:05 2019 +0000
+++ b/TAs Mon Jan 28 12:49:19 2019 +0000
@@ -52,6 +52,16 @@
--------
232 submissions
+CW8, Advanced Part 2
+
+89 => 4
+63 => 3
+17 => 2
+17 => 1
+46 => 0
+--------
+232 submissions
+
CW9, Part 1
late (231)
@@ -66,7 +76,7 @@
231 submissions
-CW9, Part2
+CW9, Advanced Part 2
156 => 4
1 => 3
@@ -89,6 +99,17 @@
--------
230 submissions
+CW10, Advanced Part 2
+
+77 => 4
+1 => 3
+48 => 2
+14 => 1
+90 => 0
+--------
+230 submissions
+
+
=======================
Ninos Lahdo used var instead of val, but in useless places
Binary file cws/cw02.pdf has changed
--- a/cws/cw02.tex Tue Jan 22 12:53:05 2019 +0000
+++ b/cws/cw02.tex Mon Jan 28 12:49:19 2019 +0000
@@ -234,8 +234,8 @@
\begin{itemize}
\item[(3)] Implement a kind of grouping function that calculates a Map
containing the userIDs and all the corresponding recommendations for
- this user (list of movieIDs). This should be implemented in a tail
- recursive fashion using a Map as accumulator. This Map is set to
+ this user (list of movieIDs). This should be implemented in a
+ tail-recursive fashion using a Map as accumulator. This Map is set to
\pcode{Map()} at the beginning of the calculation. For example
\begin{lstlisting}[numbers=none]
--- a/marking2/danube.scala Tue Jan 22 12:53:05 2019 +0000
+++ b/marking2/danube.scala Mon Jan 28 12:49:19 2019 +0000
@@ -176,3 +176,5 @@
//List(1,2,3).take(2)
//}
+
+
--- a/marking2/danube_test.sh Tue Jan 22 12:53:05 2019 +0000
+++ b/marking2/danube_test.sh Mon Jan 28 12:49:19 2019 +0000
@@ -6,12 +6,7 @@
out=${1:-output}
-# read marks for CW7 part 1
-marks=$(( `tail -1 $out` ))
-
-echo $marks
-
-echo "" >> $out
+echo "" > $out
echo "Below is the feedback for your submission danube.scala" >> $out
echo "" >> $out
@@ -20,32 +15,32 @@
# compilation tests
function scala_compile {
- (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2>> $out 1>> $out)
+ (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)
}
# functional tests
function scala_assert {
- (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
+ (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
}
# purity test
function scala_vars {
- (egrep '\bvar\b|\breturn\b|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
+ (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
}
# var, .par return, ListBuffer test
#
-echo "danube.scala does not contain vars, returns etc?" | tee -a $out
+echo "danube.scala does not contain vars, returns etc?" >> $out
if (scala_vars danube.scala)
then
- echo " --> test failed" | tee -a $out
- tsts0=$(( 1 ))
+ echo " --> fail (make triple-sure your program conforms to the required format)" >> $out
+ tsts0=$(( 0 ))
else
- echo " --> success" | tee -a $out
+ echo " --> success" >> $out
tsts0=$(( 0 ))
fi
@@ -54,14 +49,14 @@
if [ $tsts0 -eq 0 ]
then
- echo "danube.scala runs?" | tee -a $out
+ echo "danube.scala runs?" >> $out
if (scala_compile danube.scala)
then
- echo " --> success" | tee -a $out
+ echo " --> success" >> $out
tsts=$(( 0 ))
else
- echo " --> scala did not run danube.scala" | tee -a $out
+ echo " --> scala did not run danube.scala" >> $out
tsts=$(( 1 ))
fi
else
@@ -72,16 +67,15 @@
if [ $tsts -eq 0 ]
then
- echo "danube.scala tests:" | tee -a $out
- echo " val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" | tee -a $out
- echo " get_csv_url(movies_url).length == 9742" | tee -a $out
+ echo "danube.scala tests:" >> $out
+ echo " val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" >> $out
+ echo " get_csv_url(movies_url).length == 9742" >> $out
if (scala_assert "danube.scala" "danube_test1.scala")
then
- echo " --> success" | tee -a $out
- marks=$(( marks + 1 ))
+ echo " --> success" >> $out
else
- echo " --> one of the tests failed" | tee -a $out
+ echo " --> one of the tests failed" >> $out
fi
fi
@@ -89,25 +83,17 @@
if [ $tsts -eq 0 ]
then
- echo " val good_ratings = process_ratings(ratings)" | tee -a $out
- echo " val movie_names = process_movies(movies)" | tee -a $out
- echo " " | tee -a $out
- echo " good_ratings.length == 48580 " | tee -a $out
- echo " movie_names.length == 9742 " | tee -a $out
+ echo " val good_ratings = process_ratings(ratings)" >> $out
+ echo " val movie_names = process_movies(movies)" >> $out
+ echo " " >> $out
+ echo " good_ratings.length == 48580 " >> $out
+ echo " movie_names.length == 9742 " >> $out
if (scala_assert "danube.scala" "danube_test2.scala")
then
- echo " --> success" | tee -a $out
- marks=$(( marks + 1 ))
+ echo " --> success" >> $out
else
- echo " --> one of the tests failed" | tee -a $out
+ echo " --> one of the tests failed" >> $out
fi
fi
-
-
-## final marks
-echo "Overall mark for CW 7, Part 1 + 2" | tee -a $out
-echo "$marks" | tee -a $out
-
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/marking2/danube_test2.sh Mon Jan 28 12:49:19 2019 +0000
@@ -0,0 +1,156 @@
+#!/bin/bash
+
+# to make the script fail safely
+set -euo pipefail
+
+
+out=${1:-output}
+
+echo "" > $out
+
+echo "Below is the feedback and provisional marks for your submission" >> $out
+echo "for assignment 7 Part 3. Please note all marks are provisional until" >> $out
+echo "ratified by the assessment board -- this is not an official" >> $out
+echo "results transcript." >> $out
+echo "" >> $out
+
+# marks for CW7 part 3
+marks=$(( 0 ))
+
+
+# compilation tests
+
+function scala_compile {
+ (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2>> $out 1>> $out)
+}
+
+# functional tests
+
+function scala_assert {
+ (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "") #2> /dev/null 1> /dev/null)
+}
+
+# purity test
+
+function scala_vars {
+ (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
+}
+
+
+# var, .par return, ListBuffer test
+#
+echo "danube.scala does not contain vars, returns etc?" | tee -a $out
+
+if (scala_vars danube.scala)
+then
+ echo " --> test failed" | tee -a $out
+ tsts0=$(( 1 ))
+else
+ echo -e " --> success" | tee -a $out
+ tsts0=$(( 0 ))
+fi
+
+### compilation test
+
+
+if [ $tsts0 -eq 0 ]
+then
+ echo "danube.scala runs?" | tee -a $out
+
+ if (scala_compile danube.scala)
+ then
+ echo -e " --> success" | tee -a $out
+ tsts=$(( 0 ))
+ else
+ echo " --> scala danube.scala did not run successfully" | tee -a $out
+ tsts=$(( 1 ))
+ fi
+else
+ tsts=$(( 1 ))
+fi
+
+### danube groupById test
+
+if [ $tsts -eq 0 ]
+then
+ echo " val ls1 = List((\"1\", \"a\"), (\"2\", \"a\"), (\"1\", \"c\"), (\"2\", \"a\"), (\"1\", \"c\"))" | tee -a $out
+ echo " val ls2 = List((\"1\", \"a\"), (\"1\", \"b\"), (\"2\", \"x\"), (\"3\", \"a\"), (\"2\", \"y\"), (\"3\", \"c\"))" | tee -a $out
+ echo " groupById(ls1, Map()) == Map(1 -> List(c, c, a), 2 -> List(a, a))" | tee -a $out
+ echo " groupById(ls2, Map()) == Map(1 -> List(b, a), 2 -> List(x, y), 3 -> List(c, a))" | tee -a $out
+ echo " where the order in the lists is unimportant" | tee -a $out
+ echo " val ls3 = (1 to 1000).map(_.toString).toList" | tee -a $out
+ echo " val ls4 = ls3 zip ls3.tail" | tee -a $out
+ echo " val ls5 = ls4 ::: ls4.reverse" | tee -a $out
+ echo " groupById(ls5, Map()) == Map(1 -> List(2,2), 2 -> List(3,3), ....)" | tee -a $out
+
+ if (scala_assert "danube.scala" "danube_test3.scala")
+ then
+ echo -e " --> success" | tee -a $out
+ marks=$(( marks + 1 ))
+ else
+ echo -e " --> test failed" | tee -a $out
+ fi
+fi
+
+### danube favourites tests
+
+if [ $tsts -eq 0 ]
+then
+ echo " val good_ratings = process_ratings(ratings)" | tee -a $out
+ echo " val ratings_map = groupById(good_ratings, Map())" | tee -a $out
+ echo " favourites(ratings_map, \"912\").length == 80 " | tee -a $out
+ echo " favourites(ratings_map, \"858\").length == 158 " | tee -a $out
+ echo " favourites(ratings_map, \"260\").length == 201 " | tee -a $out
+
+ if (scala_assert "danube.scala" "danube_test4.scala")
+ then
+ echo " --> success" | tee -a $out
+ marks=$(( marks + 1 ))
+ else
+ echo " --> one of the tests failed" | tee -a $out
+ fi
+fi
+
+### danube suggestions tests
+
+if [ $tsts -eq 0 ]
+then
+ echo " val good_ratings = process_ratings(ratings)" | tee -a $out
+ echo " val ratings_map = groupById(good_ratings, Map())" | tee -a $out
+ echo " suggestions(ratings_map, \"912\").length == 4110 " | tee -a $out
+ echo " suggestions(ratings_map, \"858\").length == 4883 " | tee -a $out
+ echo " suggestions(ratings_map, \"260\").length == 4970 " | tee -a $out
+
+ if (scala_assert "danube.scala" "danube_test5.scala")
+ then
+ echo " --> success" | tee -a $out
+ marks=$(( marks + 1 ))
+ else
+ echo " --> one of the tests failed" | tee -a $out
+ fi
+fi
+
+### danube recommendation tests
+
+if [ $tsts -eq 0 ]
+then
+ echo " recommendations(ratings_map, movies_map, \"1\").length == 2 " | tee -a $out
+ echo " recommendations(ratings_map, movies_map, \"2\").length == 2 " | tee -a $out
+ echo " recommendations(ratings_map, movies_map, \"3\").length == 2 " | tee -a $out
+ echo " recommendations(ratings_map, movies_map, \"4\").length == 0 " | tee -a $out
+ echo " recommendations(ratings_map, movies_map, \"5\").length == 2 " | tee -a $out
+
+ if (scala_assert "danube.scala" "danube_test6.scala")
+ then
+ echo " --> success" | tee -a $out
+ marks=$(( marks + 1 ))
+ else
+ echo " --> one of the tests failed" | tee -a $out
+ fi
+fi
+
+
+## final marks
+echo "Overall mark for CW 7, Part 3" | tee -a $out
+echo "$marks" | tee -a $out
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/marking2/danube_test3.scala Mon Jan 28 12:49:19 2019 +0000
@@ -0,0 +1,54 @@
+
+// first test
+
+val ls1_urban = List(("1", "a"), ("2", "a"), ("1", "c"), ("2", "a"), ("1", "c"))
+
+val m_urban = groupById(ls1_urban, Map())
+
+assert(m_urban.getOrElse("1", Nil).count(_ == "c") == 2)
+assert(m_urban.getOrElse("1", Nil).count(_ == "a") == 1)
+assert(m_urban.getOrElse("2", Nil) == List("a", "a"))
+
+// second test
+
+def urban_gb(ratings: List[(String, String)]) =
+ ratings.groupBy(_._1).mapValues(_.map(_._2).toSet)
+
+def urban_gb2(ratings: List[(String, String)]) =
+ ratings.groupBy(_._1).mapValues(_.map(_._2))
+
+def urban_ck(ratings: List[(String, String)]) =
+ urban_gb(ratings) == groupById(ratings, Map()).mapValues(_.toSet)
+
+
+val ls2_urban = List(("1", "a"), ("1", "b"), ("2", "x"), ("3", "a"), ("2", "y"), ("3", "c"))
+
+assert(urban_ck(ls2_urban))
+
+// thrird test
+
+val ls3_urban = (1 to 1000).map(_.toString).toList
+val ls4_urban = ls3_urban zip ls3_urban.tail
+val ls5_urban = ls4_urban ::: ls4_urban.reverse
+
+assert(urban_ck(ls5_urban))
+
+
+/*
+import io.Source
+import scala.util._
+
+def urban_get_csv_file(name: String) : List[String] = {
+ val csv = Source.fromFile(name)
+ csv.mkString.split("\n").toList.drop(1)
+}
+
+def urban_process_ratings(lines: List[String]) : List[(String, String)] = {
+ for (cols <- lines.map(_.split(",").toList);
+ if (cols(2).toFloat >= 4)) yield (cols(0), cols(1))
+}
+
+val urban_ratings = urban_process_ratings(urban_get_csv_file("ratings.csv").take(1000))
+
+assert(urban_ck(urban_ratings))
+*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/marking2/danube_test4.scala Mon Jan 28 12:49:19 2019 +0000
@@ -0,0 +1,28 @@
+
+// first test
+
+
+def urban_groupById(ratings: List[(String, String)]) =
+ ratings.groupBy(_._1).mapValues(_.map(_._2))
+
+def urban_get_csv_file(name: String) : List[String] = {
+ import io.Source
+ import scala.util._
+ val csv = Source.fromFile(name)
+ csv.mkString.split("\n").toList.drop(1)
+}
+
+def urban_process_ratings(lines: List[String]) : List[(String, String)] = {
+ for (cols <- lines.map(_.split(",").toList);
+ if (cols(2).toFloat >= 4)) yield (cols(0), cols(1))
+}
+
+
+val urban_good_ratings = process_ratings(urban_get_csv_file("ratings.csv"))
+
+val urban_ratings_map = urban_groupById(urban_good_ratings)
+
+assert(favourites(urban_ratings_map, "912").length == 80)
+assert(favourites(urban_ratings_map, "858").length == 158)
+assert(favourites(urban_ratings_map, "260").length == 201)
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/marking2/danube_test5.scala Mon Jan 28 12:49:19 2019 +0000
@@ -0,0 +1,28 @@
+
+// first test
+
+
+def urban_groupById(ratings: List[(String, String)]) =
+ ratings.groupBy(_._1).mapValues(_.map(_._2))
+
+def urban_get_csv_file(name: String) : List[String] = {
+ import io.Source
+ import scala.util._
+ val csv = Source.fromFile(name)
+ csv.mkString.split("\n").toList.drop(1)
+}
+
+def urban_process_ratings(lines: List[String]) : List[(String, String)] = {
+ for (cols <- lines.map(_.split(",").toList);
+ if (cols(2).toFloat >= 4)) yield (cols(0), cols(1))
+}
+
+
+val urban_good_ratings = process_ratings(urban_get_csv_file("ratings.csv"))
+
+val urban_ratings_map = urban_groupById(urban_good_ratings)
+
+assert(suggestions(urban_ratings_map, "912").length == 4110)
+assert(suggestions(urban_ratings_map, "858").length == 4883)
+assert(suggestions(urban_ratings_map, "260").length == 4970)
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/marking2/danube_test6.scala Mon Jan 28 12:49:19 2019 +0000
@@ -0,0 +1,33 @@
+
+// first test
+
+
+def urban_groupById(ratings: List[(String, String)]) =
+ ratings.groupBy(_._1).mapValues(_.map(_._2))
+
+def urban_get_csv_file(name: String) : List[String] = {
+ import io.Source
+ import scala.util._
+ val csv = Source.fromFile(name)
+ csv.mkString.split("\n").toList.drop(1)
+}
+
+def urban_process_ratings(lines: List[String]) : List[(String, String)] = {
+ for (cols <- lines.map(_.split(",").toList);
+ if (cols(2).toFloat >= 4)) yield (cols(0), cols(1))
+}
+
+def urban_process_movies(lines: List[String]) : List[(String, String)] = {
+ for (cols <- lines.map(_.split(",").toList)) yield (cols(0), cols(1))
+}
+
+
+val urban_good_ratings = process_ratings(urban_get_csv_file("ratings.csv"))
+val urban_movie_names = process_movies(urban_get_csv_file("movies.csv")).toMap
+
+val urban_ratings_map = urban_groupById(urban_good_ratings)
+
+assert((for (n <- List("1", "2", "3", "4", "5")) yield {
+ recommendations(urban_ratings_map, urban_movie_names, n).length
+}) == List(2, 2, 2, 0, 2))
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/marking2/mk-advanced Mon Jan 28 12:49:19 2019 +0000
@@ -0,0 +1,35 @@
+#!/bin/sh
+###set -e
+
+trap "exit" INT
+
+files=${1:-assignment20187-*}
+
+for sd in $files; do
+ cd $sd
+ echo $sd
+ touch .
+ cp ../../../marking2/*.sh .
+ cp ../../../marking2/danube_test1.scala .
+ cp ../../../marking2/danube_test2.scala .
+ cp ../../../marking2/docdiff_test1.scala .
+ cp ../../../marking2/docdiff_test2.scala .
+ cp ../../../marking2/docdiff_test3.scala .
+ cp ../../../marking2/docdiff_test4.scala .
+ cp ../../../marking2/movies.csv .
+ cp ../../../marking2/ratings.csv .
+ ./docdiff_test.sh output
+ ./danube_test.sh output
+ rm *.sh
+ rm danube_test1.scala
+ rm danube_test2.scala
+ rm docdiff_test1.scala
+ rm docdiff_test2.scala
+ rm docdiff_test3.scala
+ rm docdiff_test4.scala
+ rm ratings.csv
+ rm movies.csv
+ cd ..
+done
+
+
--- a/marking3/knight3_test.sh Tue Jan 22 12:53:05 2019 +0000
+++ b/marking3/knight3_test.sh Mon Jan 28 12:49:19 2019 +0000
@@ -26,7 +26,7 @@
# functional tests
function scala_assert {
- (ulimit -t 30; JAVA_OPTS="-Xmx4g -Xss200m" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
+ (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
}
function scala_assert_long {
@@ -135,7 +135,7 @@
if (scala_vars knight3.scala)
then
echo " --> test failed" | tee -a $out
- tsts0=$(( 0 ))
+ tsts0=$(( 1 ))
else
echo " --> success" | tee -a $out
tsts0=$(( 0 ))