Пример #1
0
    $groups = array();
    foreach ($topicspacedata as $nodearray) {
        $nodeString = $nodearray[0];
        $nodeid = $nodearray[0];
        if (strpos($nodeString, '/') !== FALSE) {
            $bits = explode('/', $nodeString);
            $nodeid = $bits[count($bits) - 1];
            $node = getNode($nodeid);
            if (!$node instanceof Error) {
                $nodeString = $node->name;
                $role = $node->role->name;
                $homepage = "";
                if (isset($node->homepage) && $node->homepage != "") {
                    $homepage = $node->homepage;
                }
                $next = array("x" => jitterme($nodearray[1]), "y" => jitterme($nodearray[2]), "size" => 10, "shape" => "circle", "id" => $nodeid, "name" => $nodeString, "nodetype" => $role, "homepage" => $homepage, "color" => "#282DF8");
                if (!array_key_exists($role, $groups)) {
                    $groups[$role] = array();
                }
                array_push($groups[$role], (object) $next);
            }
        }
    }
    foreach ($groups as $key => $values) {
        $next = array("key" => $key, "values" => $values);
        array_push($data, (object) $next);
    }
}
function jitterme($num)
{
    global $jitterArray;
Пример #2
0
/**
 * Load the data for the Bias Space visulaisation
 * @param url the url for the CIF data to load
 * @param timeout how long (in seconds) to cache the visualisation data
 * before it is considered out of date and should be refetched and recalculated.
 * Defaults to 60 seconds.
 * @return an array of arrays of the data loaded from the CIF
 * converted to the structure required by the Bias Space visualisation.
 */
function getBiasSpaceData($url, $timeout = 60)
{
    global $CFG, $HUB_CACHE;
    $withhistory = false;
    $withvotes = false;
    $withposts = false;
    $data = $HUB_CACHE->getObjData($CFG->VIS_PAGE_BIASSPACE . $url . $withhistory . $withvotes . $withposts);
    if ($data === FALSE) {
        //error_log("DATA not FOUND: getBiasSpaceData");
        $reader = $HUB_CACHE->getObjData('reader' . $url . $withhistory . $withvotes . $withposts);
        if ($reader === FALSE) {
            error_log("READER not FOUND: getBiasSpaceData");
            $reader = new catalyst_jsonld_reader();
            $reader = $reader->load($url, $timeout, $withhistory, $withvotes, $withposts);
            $HUB_CACHE->setObjData('reader' . $url . $withhistory . $withvotes . $withposts, $reader, $timeout);
        } else {
            error_log("READER FOUND: getBiasSpaceData");
        }
        //$reader = new catalyst_jsonld_reader();
        //$reader = $reader->load($url,$timeout,$withhistory,$withvotes,$withposts);
        $data = array();
        if (!$reader instanceof Error) {
            $nodes = $reader->nodeSet->nodes;
            $count = count($nodes);
            $nodeArray = array();
            for ($i = 0; $i < $count; $i++) {
                $node = $nodes[$i];
                $nodeArray[$node->nodeid] = $node;
            }
            // GET METRICS
            $metric = 'support_space_post_coordinates';
            $reply = "";
            if ($url == $CFG->homeAddress . 'testing/designcommunity.json') {
                $reply = getCannedResults($CFG->homeAddress . 'testing/designcommunityBiasSpace.json');
            } else {
                $reply = getMetrics($url, $metric);
            }
            // {warnings: [string,* ], responses: [ result,* ] }
            $replyObj = json_decode($reply);
            $results = $replyObj->responses;
            if (!isset($results[0]->error) && isset($results[0]->data)) {
                $biasspacedata = $results[0]->data;
                $groups = array();
                foreach ($biasspacedata as $nodearray) {
                    $nodeString = $nodearray[0];
                    $nodeid = $nodearray[0];
                    if (array_key_exists($nodeid, $nodeArray)) {
                        $node = $nodeArray[$nodeid];
                        $nodeString = $node->name;
                        $role = $node->rolename;
                        $homepage = "";
                        if (isset($node->homepage) && $node->homepage != "") {
                            $homepage = $node->homepage;
                        }
                        $next = array("x" => jitterme($nodearray[1]), "y" => jitterme($nodearray[2]), "size" => 10, "shape" => "circle", "id" => $nodeid, "name" => $nodeString, "nodetype" => $role, "homepage" => $homepage);
                        if (!array_key_exists($role, $groups)) {
                            $groups[$role] = array();
                        }
                        array_push($groups[$role], (object) $next);
                    }
                }
                foreach ($groups as $key => $values) {
                    $next = array("key" => $key, "values" => $values);
                    array_push($data, (object) $next);
                }
            }
        }
        $HUB_CACHE->setObjData($CFG->VIS_PAGE_BIASSPACE . $url . $withhistory . $withvotes . $withposts, $data, $timeout);
    } else {
        //error_log("DATA FOUND: getBiasSpaceData");
    }
    return $data;
}