From 21b7af0876b40b4442dc701225b7322db92e453e Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Sat, 13 Aug 2011 15:35:35 +0200 Subject: [PATCH] added the visualization exercise --- pmwiki_recipes/exercises.php | 113 +++++++++++++++++++++++++++++++---- 1 file changed, 102 insertions(+), 11 deletions(-) diff --git a/pmwiki_recipes/exercises.php b/pmwiki_recipes/exercises.php index 63f4144..3cc39e7 100644 --- a/pmwiki_recipes/exercises.php +++ b/pmwiki_recipes/exercises.php @@ -1,15 +1,22 @@ B>C? A>C>B? B>C>A? B>A>C? C>B>A? C>A>B? # e.g. size, frequency update, last edition, ... -# which of those page corresponds the updates visualization V, A, B or C? +# what is the color hashing used in RevertedPIM for this group, color A, B or C? +# might require JS # keyword or URL in pages # implemented +# which of those page corresponds the updates visualization V, A, B or C? (type=historyvisualization) # is page A linked to page B? (type=pagelink) # consider a difficulty parameter # should be linked to the counter @@ -22,15 +29,20 @@ SDV($HandleActions['Exercises'], 'Exercises'); SDV($HandleAuth['Exercises'],'read'); function Exercises($pagename, $auth){ + global $ScriptUrl; $type = $_GET["type"]; $counter = (int) $_GET["counter"]; $difficulty = (int) $_GET["difficulty"]; list($group,$page) = explode(".",$pagename); - $availableexercisetypes = array("pagelink", "expressioninpage", "pagehasexpression"); + $availableexercisetypes = array("pagelink", "expressioninpage", "pagehasexpression", "historyvisualization"); + //should also test if the pim_functions.php generated the PJS has been loaded, else not make historyvisualization available + if ($type=="random") $type= $availableexercisetypes[rand(0,count($availableexercisetypes)-1)]; + $result = ""; + $verbatimresult = ""; switch ($type){ case "pagelink": // the pattern should be improve, e.g. remove PmWiki. , RecentChanges, GroupFooter, GroupHeader, Template, ... @@ -97,6 +109,69 @@ function Exercises($pagename, $auth){ } $result .="? "; $result .="\n\nClick on the answer."; + case "historyvisualization": + $processingpath = '/mirrors/fabien/pub/libraries/processing.js'; + $processingpath = "$ScriptUrl/pub/libraries/processing.js"; + $processinglib = ""; + // the pattern should be improve, e.g. remove PmWiki. , RecentChanges, GroupFooter, GroupHeader, Template, ... + if ($group == "AllPages"){ + // equivalent to getting ALL pages + $pages = ListPages(); + } else { + $pages = ListPages("/$group\./e"); + + } + + //randomly pick a page in the possible pages + $sourcepage = $pages[rand(0,count($pages)-1)]; + $processingfile = "/mirrors/fabien/pub/visualization/edits_per_page/$sourcepage.pjs"; + $processingfile = "$ScriptUrl/pub/visualization/edits_per_page/$sourcepage.pjs"; + + //randomly pick a page amongst the linked pages + $answers[] = $sourcepage; + + unset($pages[array_search($answers[0],$pages)]); + + //randomly pick n-1 others pages which may not be amongst the list of linked page + // n should be based on $difficulty, e.g. n=2+$difficulty or n=2^$difficulty + $n=3; + for ($i=1;$i<$n;$i++) { + $answers[] = $pages[rand(0,count($pages)-1)]; + unset($pages[array_search($answers[$i],$pages)]); + } + + //display + $historyvisualization = $processinglib.''; + $verbatimresult = $historyvisualization; + $result .="Which of those page corresponds the updates visualization:"; + + $counterparam = ""; + if ( $counter > 0) { + $counterparam = "counter=$counter&"; + } + + // there should now be at least 1 needle in the haystack, the first one + // note that there might be more but this is not a problem as long as the question is stated clearly. + shuffle($answers); + + for ($i=0;$i 0) { $result .= " Try other types of exercises:"; @@ -122,8 +196,9 @@ function Exercises($pagename, $auth){ $result .= " (note that it resets the counter)"; } } + $result .= "\n\n%center%[-Generated by [[http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#PIMBasedExercises|PIM Based Exercises]].-]%%"; $renderedresult = MarkupToHTML($pagename, $result); - print $renderedresult; + print "".$verbatimresult.$renderedresult.""; //$text = RetrieveAuthSection($pagename,$auth); //$content = MarkupToHTML($pagename, $text); @@ -159,20 +234,36 @@ function ExercisesCheck($pagename, $auth){ $result .="Note that $formattedlinks also are. "; if ( $counter > 0) { $counter++; - $result .="\n\nSee if you can [[$pagename?action=Exercises&counter=$counter|solve yet another one]]. "; + $result .="\n\nSee if you can [[$pagename?action=Exercises&type=$type&counter=$counter|solve yet another one]]. "; } else { - $result .="\n\nSee if you can [[$pagename?action=Exercises&counter=1|solve yet another one]]. "; + $result .="\n\nSee if you can [[$pagename?action=Exercises&type=$type&counter=1|solve yet another one]]. "; } } else { $result .="No, [[$sourcepage]] is not linked to [[$answer]] "; $result .="but $formattedlinks are. "; - $result .="\n\nTry to redeem yourself by [[$pagename?action=Exercises|trying another time]]. "; + if ($counter > 0) $result .="\nIt means you are losing your $counter points."; + $result .="\n\nTry to redeem yourself by [[$pagename?action=Exercises&type=$type|trying another time]]. "; + } + break; + case "historyvisualization": + if ( $sourcepage == $answer ) { + $result .="Excellent! [[$sourcepage]] indeed has that history of editions."; + if ( $counter > 0) { + $counter++; + $result .="\n\nSee if you can [[$pagename?action=Exercises&type=$type&counter=$counter|solve yet another one]]. "; + } else { + $result .="\n\nSee if you can [[$pagename?action=Exercises&type=$type&counter=1|solve yet another one]]. "; + } + } else { + $result .="No, it was the visualization of [[$sourcepage]] history of editions."; + if ($counter > 0) $result .="\nIt means you are losing your $counter points."; + $result .="\n\nTry to redeem yourself by [[$pagename?action=Exercises&type=$type|trying another time]]. "; } break; default: - $result .= "Exercise type unknown."; + $result .= "Exercise type unknown, this most likely indicate that the checking for the solution has not yet been implemented, please consider notifying the author. For now try [[$pagename?action=Exercises&type=random|a random type of exercise]]."; } - $result .= "\n\nGenerated by [[http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#PIMBasedExercises|PIM Based Exercises]]"; + $result .= "\n\n%center%[-Generated by [[http://fabien.benetou.fr/MemoryRecalls/ImprovingPIM#PIMBasedExercises|PIM Based Exercises]].-]%%"; $renderedresult = MarkupToHTML($pagename, $result); print $renderedresult; }