knuts;
}
/**
* Enter description here...
*
* @param unknown_type $Username
* @param unknown_type $Level
*/
function MomAccess($Username,$Level){
$MinistrySql = mysql_query("SELECT COUNT(*) as Count FROM op_mom_appointments WHERE Username='$Username' AND Level='$Level'");
$Ministry = mysql_fetch_object($MinistrySql);
if($Ministry->Count <= 0){
message('Pass invalid','Your pass has either expired or you do not have one.
Go to The Atrium to apply');
}
$MinistrySql = mysql_query("SELECT * FROM op_mom_appointments WHERE Username='$Username'");
$Ministry = mysql_fetch_object($MinistrySql);
if($Ministry->Date < time()){
message('Pass invalid','Your pass has either expired or you do not have one.
Go to The Atrium to apply');
}
}
/**
* Enter description here...
*
* @param unknown_type $Username
* @param unknown_type $level
*/
function RenewMomAccess($Username,$level){
$MinistrySql = mysql_query("SELECT COUNT(*) as Count FROM op_mom_appointments WHERE username='$username' AND Level='$level'");
$Ministry = mysql_fetch_object($MinistrySql);
if($Ministry->Count <= 0){
$nextWeek = time() + (7 * 24 * 60 * 60);
mysql_query("INSERT INTO op_mom_appointments VALUES('','$nextWeek','$Username','$level')");
message('Thanks...','Thanks for applying for a pass you will be granted access to the area soon');
}
else{
$nextWeek = time() + (7 * 24 * 60 * 60);
mysql_query("UPDATE op_mom_appointments SET Date='$nextWeek' WHERE Username='$username' AND Level='$level'");
message('Thanks...','Thanks for updating your pass. You will be granted access to the area soon');
}
}
/**
* Enter description here...
*
* @param unknown_type $Username
* @param unknown_type $Broom
*/
function SetBroom($Username,$Broom){
$BroomSQL = mysql_query("SELECT * FROM items WHERE id='$Broom'");
$Broom = mysql_fetch_object($BroomSQL);
mysql_query("UPDATE members SET Broom='$Broom->name' WHERE username='$Username'");
$this->Broom = $Broom->name;
}
/**
* Enter description here...
*
* @param unknown_type $title
* @param unknown_type $Message
* @param unknown_type $Time
* @param unknown_type $Redirect
*/
function Message($title,$Message,$Time=0,$Redirect="") {
$bordercolor = "#000000";
$bgcolor = "#FFFFFF";
echo "
";
if (!empty($Redirect)) {
echo "";
}
if ($Time == 0) {
include("/home/op/public_html/footer.php");
die();
}
}
/**
* Enter description here...
*
*/
function MembersOnly() {
global $username;
if (!$username) {
message("OPRPG...","This page is for members only so please either login or register.");
}
}
/**
* Enter description here...
*
* @param unknown_type $location
* @return unknown
*/
function SetLocation($location){
if(!is_null($location)){
define('OP_PAGE',$location);
return true;
}
else{
return false;
}
}
/**
* Enter description here...
*
* @param unknown_type $Username
* @param unknown_type $location
*/
function LogTime($Username,$location,$session){
$Time = time();
mysql_query("INSERT INTO op_time_log VALUES('','$Username','$Time','$location','$session')");
mysql_query("INSERT INTO op_time_log_keep VALUES('','$Username','$Time','$location','$session')");
}
/**
* Returns conditional probability of $A given $B and $Data.
* $Data is an indexed array. Each element of the $Data array
* consists of an A measurement and B measurment on a sample
* item.
*/
function getConditionalProbabilty($A, $B, $Data) {
$NumAB = 0;
$NumB = 0;
$NumData = count($Data);
for ($i=0; $i < $NumData; $i++) {
if (in_array($B, $Data[$i])) {
$NumB++;
if (in_array($A, $Data[$i])) {
$NumAB++;
}
}
}
return $NumAB / $NumB;
}
}
class weather{
/**
* Enter description here...
*
* @var unknown_type
*/
public $weathernow;
/**
* Enter description here...
*
* @var unknown_type
*/
public $decay;
/**
* Enter description here...
*
* @return weather
*/
function weather (){
$sql = "SELECT * FROM layout";
$query = mysql_query($sql);
$weather = mysql_fetch_object($query);
}
/**
* Enter description here...
*
* @return unknown
*/
function rand_weather(){
$weather = $this->weather();
if($weather <= 30){
$this->weathernow = rand(1,40);
}
if($weather <= 40){
$this->weathernow = rand(20,50);
}
if($weather <= 50){
$this->weathernow = rand(30,60);
}
if($weather <= 60){
$this->weathernow = rand(40,70);
}
if($weather <= 70){
$this->weathernow = rand(50,80);
}
if($weather <= 80){
$this->weathernow = rand(60,90);
}
if($weather <= 90){
$this->weathernow = rand(70,100);
}
if($weather <= 100){
$this->weathernow = rand(80,110);
}
return($this->weathernow);
}
//decaying function
/**
* Enter description here...
*
*/
function weather_decay(){
$from=weather::weather();
$to=weather::rand_weather();
$time=rand(1,10);
$diff=$to-$from;
$decay=$time/$diff;
}
/**
* Enter description here...
*
*/
function change_weather(){
$time = time();
$from = weather::weather();
$weatherdiff=$decay+$from;
$sql="UPDATE weather SET";
mysql_query($sql);
}
}
/**
* Bayes
*
* Calculates posterior probabilities for m hypotheses and n evidence
* alternatives. The code was inspired by a procedural TrueBasic version
* (Bayes.tru) bundled with Grimstead and Snell's excellent online
* textbook "Introduction to Probability".
*/
class Bayes {
/**
* Number of evidence alternatives (that is, number of rows).
*/
var $m;
/**
* Number of hypothesis alternatives (that is, number of columns).
*/
var $n;
/**
* Output labels for evidence alternatives.
*/
var $row_labels = array();
/**
* Output labels for hypothesis alternatives.
*/
var $column_labels = array();
/**
* Vector container for prior probabilities.
*/
var $priors = array();
/**
* Matrix container for likelihood of evidence e given hypothesis h.
*/
var $likelihoods = array();
/**
* Matrix container for posterior probabilties.
*/
var $posterior = array();
/**
* Vector container for evidence probabilties.
*/
var $evidence = array();
/**
* Initialize the Bayes algorithm by setting the priors, likelihoods
* and dimensions of the likelihood and posterior matrices.
*/
function Bayes($priors, $likelihoods) {
$this->priors = $priors;
$this->likelihoods = $likelihoods;
$this->m = count($this->likelihoods); // num rows
$this->n = count($this->likelihoods[0]); // num cols
return true;
}
/**
* Output method for setting row labels prior to display.
*/
function setRowLabels($row_labels) {
$this->row_labels = $row_labels;
return true;
}
/**
* Output method for setting column labels prior to display.
*/
function setColumnLabels($column_labels) {
$this->column_labels = $column_labels;
return true;
}
/**
* Compute the posterior probability matrix given the priors and
* likelihoods.
*
* The first set of loops computes the denominator of the canonical
* Bayes equation. The probability appearing in the denominator
* serves a normalizing role in the computation - it ensures that
* posterior probabilities sum to 1.
*
* The second set of loops:
*
* 1. multiplies the prior[$h] by the likelihood[$h][$e]
* 2. divides the result by the denominator
* 3. assigns the result to the posterior[$e][$h] probability matrix
*/
function getPosterior() {
// Find probability of evidence e
for($e=0; $e < $this->n; $e++) {
for ($h=0; $h < $this->m; $h++) {
$this->evidence[$e] += $this->priors[$h]
* $this->likelihoods[$h][$e];
}
}
// Find probability of hypothesis given evidence
for($e=0; $e < $this->n; $e++) {
for ($h=0; $h < $this->m; $h++) {
$this->posterior[$e][$h] = $this->priors[$h] * $this->likelihoods[$h][$e] / $this->evidence[$e];
}
}
return true;
}
/**
* Output method for displaying posterior probability matrix
*/
function toHTML($number_format="%01.3f") {
?>
| |
m; $h++) {
?>
column_labels[$h] ?>
|
n; $e++) {
?>
| row_labels[$e] ?> |
m; $h++) {
?>
posterior[$e][$h]) ?>
|