Location: PHPKode > projects > NetVis Module > netvis/gdwt_measures.php
<?php
// Geographically Dispersed Work Teams measures

	include("config.php");
	include($baseDir . "common/_func.php");

// for testing purposes, gdwt or workteams data is used

$sql="SELECT * FROM user WHERE username=\"$username\"";
$result = mysql_query($sql) or die(sqlError($sql));
$row = mysql_fetch_array($result);

session_register("uID");
$uID=$row['uID'];
session_register("pass");
$pass=2;

// process variable is for processing the form

	if(!isset($process)){
		include($baseDir . "common/_javascript.php");
		include($baseDir . "common/_header.php");

echo "<center>";
echo "<table width=\"700\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\">";
echo "<tr bgcolor=\"#CCCCCC\" align=\"center\">";
echo "<td nowrap bgcolor=\"#FFFFFF\" height=\"16\">";
echo "<div align=\"left\"><a href=\"index.php\">";
echo "<font color=#006699>Home</font></a> &gt; ";
echo "<a href=\"socialnetworks.php\">";
echo "<font color=#006699>Social Networks</font></a>";
echo " &gt; <a href=\"gdwt.php\"><font color=#006699>Geographic Dispersion</font></a> ";
echo "</div></td>";
echo "<td nowrap bgcolor=\"#FFFFFF\" height=\"16\" colspan=\"2\">";
echo "<div align=\"right\">";
		include($baseDir . "common/_options.php");
echo "</div>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</center>";

		echo "<br><center>Select Network to Analyze<br>";
		echo "<form method=post net=\"gdwt_measures.php\" name=\"form\">";
		echo "<select name=\"net\">";

		// grab the fields in networks table
		$sql="SELECT * FROM networks WHERE uID=$uID ORDER BY ID";
		$result=mysql_query($sql);

		// display the netname field in a pull-down menu
		while($row=mysql_fetch_array($result)){
			$net=$row['netname'];
			echo "<option value=\"$net\">$net</option><br>";
		}
			echo "</select>";
			echo "<br><br>Cutoff value:<br><br>";
			$cutoff=$row['cutoff'];
			echo "<input type=text name=\"cutoff\" size=2 value=$cutoff><br><br>";

		// first page of form complete
		echo "<input type=hidden name=process value=1>";
		echo "<input type=submit value=\"Submit\"></center><br>";
	include($baseDir . "common/_footer.php");

	}elseif($process==1){
	include($baseDir . "common/_gdwt.php");
	include($baseDir . "common/_javascript.php");
	include($baseDir . "common/_header.php");

echo "<center>";
echo "<table width=\"700\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\">";
echo "<tr bgcolor=\"#CCCCCC\" align=\"center\">";
echo "<td nowrap bgcolor=\"#FFFFFF\" height=\"16\">";
echo "<div align=\"left\"><a href=\"index.php\">";
echo "<font color=#006699>Home</font></a> &gt; ";
echo "<a href=\"socialnetworks.php\">";
echo "<font color=#006699>Social Networks</font></a> &gt; Dispersion</div>";
echo "</td>";
echo "<td nowrap bgcolor=\"#FFFFFF\" height=\"16\" colspan=\"2\">";
echo "<div align=\"right\">";
		include($baseDir . "common/_options.php");
echo "</div>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</center>";

	$net = $HTTP_POST_VARS['net'];
	$cutoff = $HTTP_POST_VARS['cutoff'];
 $sql = "UPDATE networks SET cutoff=\"". $cutoff ."\" WHERE uID=\"" . $uID .
	"\" AND netname=\"" . $net . "\"";
 mysql_query($sql) or die(sqlError($sql));			
	echo "<br><center>";

		// stat is the variable used for the class GDWT
		$stat= new GDWT($uID,$net);
		$stat->setData();

		// triangle function to display matrix values

		$stat->createTriangle();

	echo "raw data (upper-right triangle)=<br>";
	print_r($stat->data);
	echo "<br><br>";

	echo "<center>Team $net</center>";

		// create site function to determine how many different sites
		$sites = $stat->createSites();

		echo "Sites = " . $stat->numSites;
		echo "<br>";
		for($c=0; $c<$stat->numSites; $c++){
			$s = $c + 1;
			echo "Site $s contains people: {";
			$comma = false;
			for($p=0; $p<count($stat->people); $p++){
				if($stat->siteAssignments[$stat->people[$p]] == $c){
					if($comma){
						echo ", ";
					}
					else{
						$comma = true;
					}
					echo $stat->people[$p];
				}
			}
			echo "}<br>";
		}
		echo "<br>";
		echo "Isolation index: ".$stat->isolation."<br>";
		echo "<form method=post net=\"gdwt_measures.php\">";

		// compute miles function to determine miles between sites

		$miles = $stat->computeMiles();
		for($c=0; $c<count($stat->people); $c++){
			for($d=$c+1; $d<count($stat->people); $d++){
				$e=$c+$d-1;
				echo "Distance (in miles) from Person $c to Person $d: <input type=textbox name=mile".($c*count($stat->people)+$d)." value=$miles[$e]> (no commas)<br><br>";
			}
		}

		// compute minute function to determine minute between sites

		$minute = $stat->computeMinutes();
		for($c=0; $c<count($stat->people); $c++){
				for($d=$c+1; $d<count($stat->people); $d++){
				$e = $c + $d - 1;
					echo "Distance (in minute) from Person $c to Person $d: <input type=textbox name=minute ".($c*count($stat->people)+$d)." value=$minute[$e]> (no commas)<br><br>";
			}
		}

		// compute shared function to determine overlap in hours between sites
		$shared = $stat->computeShared();
		for($c=0; $c<count($stat->people); $c++){
				for($d=$c+1; $d<count($stat->people); $d++){
				$e = $c + $d - 1;
					echo "Shared timezones (in hours) from Person $c to Person $d: <input type=textbox name=share".($c*count($stat->people)+$d)." value=$shared[$e]> (no commas)<br><br>";
			}
		}

		echo "<br><br>";
		// second page of form complete
		echo "<input type=hidden name=process value=2>";
		echo "<input type=hidden name=\"net\" value=\"$net\">";
		echo "<input type=hidden name=\"miles\" value=\"$miles\">";
		echo "<input type=hidden name=\"minute\" value=\"$minute\">";
		echo "<input type=hidden name=\"shared\" value=\"$shared\">";
		echo "<input type=submit value=\"Submit\">";
		echo "<br><br><a href=\"gdwt_measures.php\"><font color=#006699>Back to Network Selection</font></a><br>";
		echo "</form></center>";
	include($baseDir . "common/_footer.php");

	}elseif($process==2){
	include($baseDir . "common/_gdwt.php");
	include($baseDir . "common/_javascript.php");
	include($baseDir . "common/_header.php");

echo "<center>";
echo "<table width=\"700\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\">";
echo "<tr bgcolor=\"#CCCCCC\" align=\"center\">";
echo "<td nowrap bgcolor=\"#FFFFFF\" height=\"16\">";
echo "<div align=\"left\"><a href=\"index.php\">";
echo "<font color=#006699>Home</font></a> &gt; ";
echo "<a href=\"socialnetworks.php\">";
echo "<font color=#006699>Social Networks</font></a> &gt; Dispersion</div>";
echo "</td>";
echo "<td nowrap bgcolor=\"#FFFFFF\" height=\"16\" colspan=\"2\">";
echo "<div align=\"right\">";
		include($baseDir . "common/_options.php");
echo "</div>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</center>";

		echo "<br><center>";

		echo "<center>Team $net</center><br>";

		// compute the five indices - Sites, Isolation, Separation, Deviation, Overlap

		$sql="SELECT * FROM networks WHERE uID=$uID AND netname=\"$net\"";
		$result = mysql_query($sql) or die(sqlError($sql));
		$row = mysql_fetch_array($result);

		$stat= new GDWT($uID,$net);

		echo "Site Index=$row[site]<br>";

		echo "Isolation Index=$row[isolation]<br>";

		if(!isset($row['separation'])){
			$row['separation']=FALSE;
		}
		$separation = $stat->computeSeparation($miles);
		echo "Separation Index=$row[separation]<br>";

		if(!isset($row['deviation'])){
			$row['deviation']=FALSE;
		}
		$deviation = $stat->computeDeviation($miles);
		echo "Deviation Index=$row[deviation]<br>";

		if(!isset($row['overlap'])){
			$row['overlap']=FALSE;
		}
		$overlap = $stat->computeOverlap($shared);
		echo "Overlap Index=$row[overlap]<br>";

		echo "<br><a href=\"gdwt_measures.php\"><font color=#006699>Back to Network Selection</font></a><br>";
		echo "</center><br>";
		include($baseDir . "common/_footer.php");
	}
?>
Return current item: NetVis Module