From 794838e4baf0ef1d4d99941e33f9ce1a74f72ca9 Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Wed, 8 Jun 2011 11:13:35 +0200 Subject: [PATCH] visuaization scripts --- cookbook/gp_pageview_withingroup.php | 123 +++++++++++++++++++++++++ cookbook/graphformatexporter.php | 130 ++++++++++++++++++++++++++ cookbook/graphprocessing.php | 132 +++++++++++++++++++++++++++ 3 files changed, 385 insertions(+) create mode 100644 cookbook/gp_pageview_withingroup.php create mode 100644 cookbook/graphformatexporter.php create mode 100644 cookbook/graphprocessing.php diff --git a/cookbook/gp_pageview_withingroup.php b/cookbook/gp_pageview_withingroup.php new file mode 100644 index 0000000..7f138b8 --- /dev/null +++ b/cookbook/gp_pageview_withingroup.php @@ -0,0 +1,123 @@ +"; + + # eventually modify to use a dedicated folder + # generate a file per page + if (!file_exists($FarmD.$processingfile)) + if (!touch($FarmD.$processingfile)) + print "Creation of the processing file fails, check write permissions for pmWiki and $processingfile."; + + # cached version (to comment during tests) + #if ( (time() - filemtime($FarmD.$processingfile)) < 3600 ) return $processinglib.''; + + $canvaswidth=500; + $canvasheight=150; + + $groupname = $sourcegroup; + $pages = ListPages("/$groupname\./e"); + $pages = MatchPageNames($pages,array('-*.*RecentChanges,-*.GroupFooter,-*.GroupHeader')); + $pagesnum = count($pages); + $processingsetupcode = " +float[][] e = new float[$pagesnum][3]; +void setup(){ + frameRate(15); + size($canvaswidth,$canvasheight); + strokeWeight(1); +"; + $processingdrawcode .= " +void draw(){ + background(255); + for (int j=0;j<$pagesnum;j++){ + noStroke(); + fill(64,128,187,100); + ellipse(e[j][0],e[j][1],e[j][2],e[j][2]); + } +"; + # associate a color per group name + + $processinghandlinglinkscode = ''; + + $processinghandlinglinkscode .= 'Object l={'; + $processinglinkcode = " stroke(64,128,187,100);\n"; + $pageindex=0; + # scan over the array of pages to get mazimum and generate axis... + # use min() and max() to get limits + foreach ($pages as $page) { + # generate nice JS code + $content = ReadPage($page,$since=0); + $diameter = strlen($content["text"]) / 100 ; + if ($diameter < 30) $diameter=30; + if ($diameter > 120) $diameter=120; + $author = $content["author"]; + $links = $content["targets"]; + $links_array = explode(",",$links); + foreach ($links_array as $link) { + # draw a line between the circle with + # k must become $link + if (($linkindex = array_search($link,$pages)) !== false ) + $processinglinkcode .= " line(e[$pageindex][0],e[$pageindex][1],e[$linkindex][0],e[$linkindex][1]);\n"; + } + $x = round( 20 + $content["rev"] * 2 ); + $y = round( 50 + ((time() - $content["time"]) / (60*60*24 * 4)) ); + $pagename = preg_replace("/$groupname.(.*)/","$1",$page); + $processingsetupcode .= " e[$pageindex][0]=$x;e[$pageindex][1]=$y;e[$pageindex][2]=$diameter;\n"; + //$pagename.link('$page'); + $tx = $x - 20; + $ty = $y; + # modify to add to $processingsetupcode instead then itterate over it + if ($pagename == $sourcename) + # this is the name of the current page, do sth special + $processingdrawcode .= " fill(100);\n text('$pagename',$tx,$ty);\n fill(64,128,187,100);\n"; + elseif (preg_match("/$pagename/",getenv('HTTP_REFERRER'))) + # buggy... + # elseif (preg_match("/$ScriptUrl.*$groupname.*$pagename/",$HTTP_REFERER)) + $processingdrawcode .= " fill(120);\n text('$pagename',$tx,$ty);\n fill(64,128,187,100);\n"; + + else + $processingdrawcode .= " text('$pagename',$tx,$ty);\n"; + //$processinghandlinglinkscode .= " new alink($x-20,$y,30,'/$groupname/$pagename','$pagename', #aa0088,#ff00aa),\n"; + # modify $processingsetupcode again to include presence of PTV like startrecall + $pageindex++; + } + //$processinghandlinglinkscode = preg_replace("/(.*),$/","$1",$processinghandlinglinkscode); + //$processinghandlinglinkscode .= "}\n"; + $processingsetupcode .= " }"; + //$processingdrawcode .= $processinglinkcode.' forLinks("render"); }'.$processinghandlinglinkscode; + $processingdrawcode .= $processinglinkcode." }"; + + $result = $processinglib.''; + + $write_result = file_put_contents($FarmD.$processingfile,$processingsetupcode.$processingdrawcode); + if (!$write_result) + if (strlen($processingcode)>0) + print "Creation of the feed file fails, check write permissions for pmWiki and $processingfile."; + else + print "No code to generate, did you correctly generate your Processing code?"; + + // ----------------------- return the processed result ----------------------- + return $result; +} + +?> diff --git a/cookbook/graphformatexporter.php b/cookbook/graphformatexporter.php new file mode 100644 index 0000000..1893baf --- /dev/null +++ b/cookbook/graphformatexporter.php @@ -0,0 +1,130 @@ +$edges"; + + $nodesfile = $FarmD."/pub/nodes.csv"; + if (!file_exists($nodesfile)) + if (!touch($nodesfile)) + print "Creation of the processing file fails, check write permissions for pmWiki and $nodesfile."; + $write_result = file_put_contents($nodesfile,$nodes); + if (!$write_result) + if (strlen($nodes)>0) + print "Creation of the feed file fails, check write permissions for pmWiki and $nodesfile."; + else + print "No code to generate, did you correctly generate your Processing code?"; + + $edgesfile = $FarmD."/pub/edges.csv"; + if (!file_exists($edgesfile)) + if (!touch($edgesfile)) + print "Creation of the processing file fails, check write permissions for pmWiki and $edgesfile."; + $write_result = file_put_contents($edgesfile,$edges); + if (!$write_result) + if (strlen($edges)>0) + print "Creation of the feed file fails, check write permissions for pmWiki and $edgesfile."; + else + print "No code to generate, did you correctly generate your Processing code?"; + + + return ; +} + +SDV($HandleActions['graphvan'],'GraphVAN'); +SDV($HandleAuth['graphvan'],'view'); + +function GraphVAN($pagename, $auth){ + $sourcename = preg_replace("/.*\.(.*)/","$1",$pagename); + $groupname = preg_replace("/(.*)\..*/","$1",$pagename); + global $FarmD, $WikiTitle, $ScriptUrl; + + //entire wiki + if ($pagename == "Main.HomePage") + $pages = ListPages("//e"); + else + $pages = ListPages("/$groupname\./e"); + + //$pages = MatchPageNames($pages,array('-*.RecentChanges,-*.GroupFooter,-*.GroupHeader')); + $pagesnum = count($pages); + + $vangraph = "*Node data\nId Group Label Size Time Rev\n"; + $vangraphties = "*Tie data\nFROM TO\n"; + # scan over the array of pages to get mazimum and generate axis... + foreach ($pages as $page) { + $cleanpage = preg_replace("/.*\.(.*)/","$1",$page); + $content = ReadPage($page,$since=0); + $size = strlen($content["text"]); + $pagetime = $content["time"]; + $pagerev = $content["rev"]; + $group = preg_replace("/(.*)\..*/","$1",$page); + $vangraph .= "$page $group $cleanpage $size $pagetime $pagerev\n"; + $page_category = preg_replace("/.*\[\[\!(.*)\]\].*/s","$1",$content["text"]); + $author = $content["author"]; + $links = $content["targets"]; + $links_array = explode(",",$links); + foreach ($links_array as $link) { + if (($linkindex = array_search($link,$pages)) !== false ) + { + $cleanlink = preg_replace("/.*\.(.*)/","$1",$link); + $vangraphties .= "$page $link\n"; + } + } + } + // ----------------------- return the processed result ----------------------- + print "$vangraph
$vangraphties"; + + $vanfile = $FarmD."/pub/graph.van"; + if (!file_exists($vanfile)) + if (!touch($vanfile)) + print "Creation of the processing file fails, check write permissions for pmWiki and $vanfile."; + $write_result = file_put_contents($vanfile,$vangraph.$vangraphties); + if (!$write_result) + if (strlen($vangraph)>0) + print "Creation of the feed file fails, check write permissions for pmWiki and $vanfile."; + else + print "No code to generate, did you correctly generate your Processing code?"; + + return ; +} diff --git a/cookbook/graphprocessing.php b/cookbook/graphprocessing.php new file mode 100644 index 0000000..4399a4f --- /dev/null +++ b/cookbook/graphprocessing.php @@ -0,0 +1,132 @@ +"; + + # eventually modify to use a dedicated folder + # generate a file per page + if (!file_exists($FarmD.$processingfile)) + if (!touch($FarmD.$processingfile)) + print "Creation of the processing file fails, check write permissions for pmWiki and $processingfile."; + + # cached version (to comment during tests) + //if ( (time() - filemtime($FarmD.$processingfile)) < 3600 ) return $processinglib.''; + + $canvaswidth=600; + $canvasheight=600; + + $groupname = $sourcegroup; + $pages = ListPages('/./e'); + $pages = MatchPageNames($pages,array('-*.*RecentChanges,-*.GroupFooter,-*.GroupHeader,-PmWiki.*,-Site.*')); + $pagesnum = count($pages); + $processingsetupcode = " +float[][] e = new float[$pagesnum][3]; +void setup(){ + frameRate(15); + size($canvaswidth,$canvasheight); + strokeWeight(1); +"; + $processingdrawcode .= " +void draw(){ + background(255); + for (int j=0;j<$pagesnum;j++){ + noStroke(); + fill(64,128,187,100); + ellipse(e[j][0],e[j][1],e[j][2],e[j][2]); + } +"; + # associate a color per group name + + $processinghandlinglinkscode = ''; + + $processinghandlinglinkscode .= 'Object l={'; + $processinglinkcode = " stroke(64,128,187,100);\n"; + $pageindex=0; + # scan over the array of pages to get mazimum and generate axis... + # use min() and max() to get limits + foreach ($pages as $page) { + # generate nice JS code + $content = ReadPage($page,$since=0); + $diameter = strlen($content["text"]) / 100 ; + if ($diameter < 30) $diameter=30; + if ($diameter > 120) $diameter=120; + #change color per group + # get group hash, convert hash to color string, apply color + $author = $content["author"]; + $links = $content["targets"]; + $links_array = explode(",",$links); + foreach ($links_array as $link) { + # draw a line between the circle with + # k must become $link + if (($linkindex = array_search($link,$pages)) !== false ) + $processinglinkcode .= " line(e[$pageindex][0],e[$pageindex][1],e[$linkindex][0],e[$linkindex][1]);\n"; + } + $x = round( 20 + $content["rev"] * 3 ); + $y = round( 50 + ((time() - $content["time"]) / (60*60*24 )) ); + $pagename = preg_replace("/$groupname.(.*)/","$1",$page); + $processingsetupcode .= " e[$pageindex][0]=$x;e[$pageindex][1]=$y;e[$pageindex][2]=$diameter;\n"; + //$pagename.link('$page'); + $tx = $x - 20; + $ty = $y; + # modify to add to $processingsetupcode instead then itterate over it + + + /* current page irrelevant here + if ($pagename == $sourcename) + # this is the name of the current page, do sth special + $processingdrawcode .= " fill(100);\n text('$pagename',$tx,$ty);\n fill(64,128,187,100);\n"; + elseif (preg_match("/$pagename/",getenv('HTTP_REFERRER'))) + # buggy... + # elseif (preg_match("/$ScriptUrl.*$groupname.*$pagename/",$HTTP_REFERER)) + $processingdrawcode .= " fill(120);\n text('$pagename',$tx,$ty);\n fill(64,128,187,100);\n"; + + else + $processingdrawcode .= " text('$pagename',$tx,$ty);\n"; + //$processinghandlinglinkscode .= " new alink($x-20,$y,30,'/$groupname/$pagename','$pagename', #aa0088,#ff00aa),\n"; + */ + $processingdrawcode .= " text('$pagename',$tx,$ty);\n"; + # modify $processingsetupcode again to include presence of PTV like startrecall + $pageindex++; + } + //$processinghandlinglinkscode = preg_replace("/(.*),$/","$1",$processinghandlinglinkscode); + //$processinghandlinglinkscode .= "}\n"; + $processingsetupcode .= " }"; + //$processingdrawcode .= $processinglinkcode.' forLinks("render"); }'.$processinghandlinglinkscode; + $processingdrawcode .= $processinglinkcode." }"; + + $result = $processinglib.''; + + $write_result = file_put_contents($FarmD.$processingfile,$processingsetupcode.$processingdrawcode); + if (!$write_result) + if (strlen($processingcode)>0) + print "Creation of the feed file fails, check write permissions for pmWiki and $processingfile."; + else + print "No code to generate, did you correctly generate your Processing code?"; + + // ----------------------- return the processed result ----------------------- + return $result; +} + +?>