diff --git a/calc.php b/calc.php new file mode 100755 index 0000000..0f8dbbc --- /dev/null +++ b/calc.php @@ -0,0 +1,10 @@ + 400) ? ((($rb - $ra) > 0) ? 400 : -400) : ($rb - $ra)) / 400)); + } + + function getNew($win, $ra, $rate) { + $k = 10; + return $ra + $k * ($win - $rate); + } +?> diff --git a/connect.php b/connect.php new file mode 100755 index 0000000..773a076 --- /dev/null +++ b/connect.php @@ -0,0 +1,4 @@ + diff --git a/images/keep-dir b/images/keep-dir new file mode 100644 index 0000000..e69de29 diff --git a/index.php b/index.php new file mode 100755 index 0000000..9d5e52d --- /dev/null +++ b/index.php @@ -0,0 +1,87 @@ + + + + ProMash + + +

ProMash

+ + "; + if ($i > (intval(getNumberOfPros()) / 2)) { + resetParing(); + $i = 0; + $id = getRandom(); + } + $pid = intval(getPartner($id)); + + echo ""; + + if ($id == $pid) + continue; + if ($pid === false) + $id = intval(getNextId($id)); + else + break; + $i++; + } + setPartners($id, $pid); + if (!$_SESSION['idLeft']) { + $tmp = $id; + $id = $pid; + $pid = $tmp; + } + $_SESSION['active'] = $id; + $_SESSION['against'] = $pid; + $leftImg = getImage($id); + $rightImg = getImage($pid); + $leftRate = getRateByIds($id, $pid); + $rightRate = 1 - $leftRate; + ?> +









+
+ Who's better? Click to choose. +
+



+
+
+
+ + + +
+
+ or +
+
+ + + +
+
+
+
+ Left: %
+ Right: %
+
+ +
+Elo rating - Image copyright - You don't want to rate the current image? Just press F5. +
+ + diff --git a/result.php b/result.php new file mode 100755 index 0000000..377d859 --- /dev/null +++ b/result.php @@ -0,0 +1,39 @@ + diff --git a/setup.php b/setup.php new file mode 100755 index 0000000..cd587a9 --- /dev/null +++ b/setup.php @@ -0,0 +1,20 @@ +"; + $sql = "INSERT INTO pros (image, value) VALUES ('" . $i . "', 1024)"; + mysql_query($sql); + } +?> diff --git a/system.php b/system.php new file mode 100755 index 0000000..af0130b --- /dev/null +++ b/system.php @@ -0,0 +1,110 @@ + 0) + return $staticNumberOfPros; + + $sql = "SELECT id FROM pros"; + $resource = mysql_query($sql); + $staticNumberOfPros = mysql_num_rows($resource); + return $staticNumberOfPros; + } + function resetParing() { + $_SESSION['idLeft'] = true; + $_SESSION['active'] = false; + $_SESSION['against'] = false; + $_SESSION['pArray'] = array(); + $_SESSION['debug'] = array(); + } + function setPartners($id, $pid) { + $hash = getHash($id, $pid); + //$_SESSION['debug'][] = array("setPartners", $id, $pid, $hash); + $_SESSION['pArray'][] = $hash; + } + function getNextId($id) { + $number = getNumberOfPros(); + $id++; + if ($id >= $number) + $id -= $number; + return $id; + } + function getPartner($id) { + $id = intval($id); + $sql = "SELECT id, value FROM pros ORDER BY value"; + $resource = mysql_query($sql); + $all = array(); + $i = 0; + $activ = -1; + while ($row = mysql_fetch_object($resource)) { + if (intval($row->id) == $id) + $activ = $i; + $all[] = $row; + $i++; + } + if ($activ < 0) { + echo "something happend:\n\n"; + echo "$i, $activ, $id"; + die(); + } + + + $number = getNumberOfPros(); + $up = true; + $offset = 1; + $i = 0; + do { + if ($i > ($number / 4 * 3)) + return false; + $newIndex = $activ + (($up) ? ($offset) : (-$offset)); + $newIndex %= $number; + + $offset += ($up) ? (0) : (1); + $up = !$up; + $pid = $all[$newIndex]->id; + + if ($id == $pid) { + echo "something happend:\n\n"; + echo "$i, $number, $activ, " . intval($up) . ", $offset"; + die(); + } + + $i++; + } while (allreadyPartner($id, $pid)); + return $pid; + } + + function allreadyPartner($id, $pid) { + foreach ($_SESSION['pArray'] as $hash) + if ($hash == getHash($id, $pid)) + return true; + return false; + } + function getHash($id, $pid) { + return $id ^ $pid; + } + function getImage($id) { + $sql = "SELECT image FROM pros WHERE id = " . intval($id); + $result = mysql_query($sql); + $row = mysql_fetch_object($result); + return $row->image; + } + function getPoints($id) { + $sql = "SELECT value FROM pros WHERE id = " . intval($id); + $result = mysql_query($sql); + $row = mysql_fetch_object($result); + return $row->value; + } + function getRateByIds($id, $pid) { + $ra = getPoints($id); + $rb = getPoints($pid); + return getRate($ra, $rb); + } +?> diff --git a/test.php b/test.php new file mode 100755 index 0000000..1347ac1 --- /dev/null +++ b/test.php @@ -0,0 +1,10 @@ +"; + print_r($_SESSION); +?>