diff --git a/README.md b/README.md
index ff01d47..ec0c9ff 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,5 @@
# USACO Rating
+
[USACO Rating](https://codetiger.me/project/usaco/) is a tool to estimate the difficulties of USACO problems in terms of CodeForces rating.

diff --git a/backend/data.php b/backend/data.php
index ccc12c2..f868fb7 100644
--- a/backend/data.php
+++ b/backend/data.php
@@ -1,419 +1,440 @@
query("SELECT * FROM problems");
- while($row = $res -> fetch_assoc()) {
- $obj["id"] = $row["id"];
- $obj["contest"] = $row["contest"];
- $obj["name"] = $row["name"];
- $obj["url"] = $row["url"];
- $obj["type"] = $row["type"];
- $obj["rating"] = $row["rating"];
- $obj["quality"] = $row["quality"];
- $obj["rating2"] = $row["rating2"];
- $obj["quality2"] = $row["quality2"];
- $obj["cnt1"] = $row["cnt1"];
- $obj["cnt2"] = $row["cnt2"];
- array_push($data,$obj);
- }
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- exit("");
- }else if($type == 2) {
- // Retrieve user data
- $data = [];
- $uid = $_POST["id"];
- $stmt = $conn -> prepare("SELECT * FROM users WHERE id=?");
- $stmt -> bind_param("s",$uid);
- $stmt -> execute();
- $res = $stmt -> get_result();
- if($res -> num_rows == 0) {
- array_push($data,-1);
- }else{
- $info = $res -> fetch_assoc();
- array_push($data,$info);
- }
- $stmt -> close();
- $stmt = $conn -> prepare("SELECT * FROM rating WHERE id=?");
- $stmt -> bind_param("s",$uid);
- $stmt -> execute();
- $res = $stmt -> get_result();
- $rating = [];
- if($res -> num_rows > 0) {
- while($row = $res -> fetch_assoc()) {
- array_push($rating,$row);
- }
- }
- array_push($data,$rating);
- $stmt -> close();
- $stmt = $conn -> prepare("SELECT * FROM quality WHERE id=?");
- $stmt -> bind_param("s",$uid);
- $stmt -> execute();
- $res = $stmt -> get_result();
- $quality = [];
- if($res -> num_rows > 0) {
- while($row = $res -> fetch_assoc()) {
- array_push($quality,$row);
- }
- }
- array_push($data,$quality);
- $stmt -> close();
-
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- }else if($type == 3) {
- // Register an account
- if($_POST["pwd"] == PASSWORD) {
- $uid = generateRandomString();
- $name = $_POST["name"];
- $cf = $_POST["cf"];
-
- registerAccount($conn,$uid,$name,$cf);
-
- $data = [];
- $data["id"] = $uid;
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- }else{
-
- }
- }else if($type == 4) {
- // Update votes according to data
- $data = [];
- $uid = $_POST["id"];
- $votes = json_decode($_POST["votes"]);
- if(!checkUserExist($conn,$uid)) {
- $data["status"] = -1;
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- exit("");
- }
- for($i = 0;$i < count($votes[0]);$i++) {
- updateVotesRating($conn,$uid,$i + 1,$votes[0][$i]);
- }
- for($i = 0;$i < count($votes[1]);$i++) {
- updateVotesQuality($conn,$uid,$i + 1,$votes[1][$i]);
- }
- recalculateEverything($conn);
- $data["status"] = 1;
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- }else if($type == 5) {
- // Temporary and should be removed once done
- // recalculateEverything($conn);
- }else if($type == 6) {
- // Increase visit counter :D
- $date = date("m-d-Y");
- $conn -> query("INSERT INTO stats (type,value) VALUES ('" . $date . "',1)
+// Sensitive information about the database
+include("mysql_info.php");
+$conn = new mysqli("localhost", USERNAME, PASSWORD, "usaco");
+
+$type = $_POST['type'];
+if ($type == 1) {
+ // Retrieve all data
+ $data = [];
+ $res = $conn->query("SELECT * FROM problems");
+ while ($row = $res->fetch_assoc()) {
+ $obj["id"] = $row["id"];
+ $obj["contest"] = $row["contest"];
+ $obj["name"] = $row["name"];
+ $obj["url"] = $row["url"];
+ $obj["type"] = $row["type"];
+ $obj["rating"] = $row["rating"];
+ $obj["quality"] = $row["quality"];
+ $obj["rating2"] = $row["rating2"];
+ $obj["quality2"] = $row["quality2"];
+ $obj["cnt1"] = $row["cnt1"];
+ $obj["cnt2"] = $row["cnt2"];
+ array_push($data, $obj);
+ }
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+ exit("");
+} else if ($type == 2) {
+ // Retrieve user data
+ $data = [];
+ $uid = $_POST["id"];
+ $stmt = $conn->prepare("SELECT * FROM users WHERE id=?");
+ $stmt->bind_param("s", $uid);
+ $stmt->execute();
+ $res = $stmt->get_result();
+ if ($res->num_rows == 0) {
+ array_push($data, -1);
+ } else {
+ $info = $res->fetch_assoc();
+ array_push($data, $info);
+ }
+ $stmt->close();
+ $stmt = $conn->prepare("SELECT * FROM rating WHERE id=?");
+ $stmt->bind_param("s", $uid);
+ $stmt->execute();
+ $res = $stmt->get_result();
+ $rating = [];
+ if ($res->num_rows > 0) {
+ while ($row = $res->fetch_assoc()) {
+ array_push($rating, $row);
+ }
+ }
+ array_push($data, $rating);
+ $stmt->close();
+ $stmt = $conn->prepare("SELECT * FROM quality WHERE id=?");
+ $stmt->bind_param("s", $uid);
+ $stmt->execute();
+ $res = $stmt->get_result();
+ $quality = [];
+ if ($res->num_rows > 0) {
+ while ($row = $res->fetch_assoc()) {
+ array_push($quality, $row);
+ }
+ }
+ array_push($data, $quality);
+ $stmt->close();
+
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+} else if ($type == 3) {
+ // Register an account
+ if ($_POST["pwd"] == PASSWORD) {
+ $uid = generateRandomString();
+ $name = $_POST["name"];
+ $cf = $_POST["cf"];
+
+ registerAccount($conn, $uid, $name, $cf);
+
+ $data = [];
+ $data["id"] = $uid;
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+ } else {
+
+ }
+} else if ($type == 4) {
+ // Update votes according to data
+ $data = [];
+ $uid = $_POST["id"];
+ $votes = json_decode($_POST["votes"]);
+ if (!checkUserExist($conn, $uid)) {
+ $data["status"] = -1;
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+ exit("");
+ }
+ for ($i = 0; $i < count($votes[0]); $i++) {
+ updateVotesRating($conn, $uid, $i + 1, $votes[0][$i]);
+ }
+ for ($i = 0; $i < count($votes[1]); $i++) {
+ updateVotesQuality($conn, $uid, $i + 1, $votes[1][$i]);
+ }
+ recalculateEverything($conn);
+ $data["status"] = 1;
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+} else if ($type == 5) {
+ // Temporary and should be removed once done
+ // recalculateEverything($conn);
+} else if ($type == 6) {
+ // Increase visit counter :D
+ $date = date("m-d-Y");
+ $conn->query("INSERT INTO stats (type,value) VALUES ('" . $date . "',1)
ON DUPLICATE KEY UPDATE value = value + 1;");
- $conn -> query("UPDATE stats SET value = value + 1 WHERE type = 'visit'");
- }else if($type == 7) {
- // Automatic registration
-
- if(!isset($_POST["username"]) || !isset($_POST["name"])) {
- $data["success"] = -5;
- $data["message"] = "A required field is empty";
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- exit("");
- }
-
- $username = strtolower($_POST["username"]);
- $CFUsers = callAPI("http://codeforces.com/api/user.info?handles=" . $username) -> result;
-
- if(count($CFUsers) == 0) {
- $data["success"] = -1;
- $data["message"] = "The codeforces account does not exist!";
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- exit("");
- }
-
- $CFUsers = $CFUsers[0];
- $firstName = $CFUsers -> firstName;
- $rating = $CFUsers -> rating;
-
- // 1900 Threshold
- if($rating < 1900) {
- $data["success"] = -2;
- $data["message"] = "The codeforces account's rating does not meet the 1900 threshold. If you believe you are still qualified, please fill out the manual review form.";
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- exit("");
- }
-
- if(trim($firstName) != "USACO-Rating-verify") {
- $data["success"] = -3;
- $data["message"] = "The codeforces account's first name is not 'USACO-Rating-verify'";
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- exit("");
- }
-
- if(checkCodeForcesExist($conn,$username)) {
- $data["success"] = -4;
- $data["message"] = "You have already registered an account! Contact CodeTiger on discord if you lost your personalized link.";
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- exit("");
- }
-
- // Everything passes :D
- $uid = generateRandomString();
- $name = $_POST["name"];
-
- registerAccount($conn,$uid,$name,$username);
-
- $data["status"] = 1;
- $data["id"] = $uid;
- $data["message"] = "Success!";
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- }else if($type == 8) {
- // Invitation Link Recovery
-
- if(!isset($_POST["username"])) {
- $data["success"] = -1;
- $data["message"] = "A required field is empty";
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- exit("");
- }
-
- $username = strtolower($_POST["username"]);
-
- if(!checkCodeForcesExist($conn,$username)) {
- $data["success"] = -2;
- $data["message"] = "The account does not exist!";
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- exit("");
- }
-
- $CFUsers = callAPI("http://codeforces.com/api/user.info?handles=" . $username) -> result;
-
- if(count($CFUsers) == 0) {
- $data["success"] = -4;
- $data["message"] = "The codeforces account does not exist!";
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- exit("");
- }
-
- $CFUsers = $CFUsers[0];
- $firstName = $CFUsers -> firstName;
-
- if(trim($firstName) != "USACO-Rating-verify") {
- $data["success"] = -3;
- $data["message"] = "The codeforces account's first name is not 'USACO-Rating-verify'";
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- exit("");
- }
-
- $uid = getUserId($conn,$_POST["username"]);
- $data["success"] = 0;
- $data["id"] = $uid;
- header('Content-type:application/json;charset=utf-8');
- echo json_encode($data);
- exit("");
-
- }
-
- function registerAccount($conn,$uid,$name,$cf) {
- $stmt = $conn -> prepare("INSERT INTO users (id,name,cf) VALUES (?,?,?)");
- $stmt -> bind_param("sss",$uid,$name,$cf);
- $stmt -> execute();
- $stmt -> close();
- }
-
- function recalculateEverything($conn) {
- recalculateRatings($conn);
- recalculateQualities($conn);
- }
-
- function updateVotesRating($conn,$uid,$pid,$rating) {
- if($rating == -2) return;
- if($rating != -1 && ($rating < 800 || $rating > 3500)) return;
- $stmt = $conn -> prepare("SELECT * FROM rating WHERE id=? AND pid=?");
- $stmt -> bind_param("si",$uid,$pid);
- $stmt -> execute();
- $res = $stmt -> get_result();
- $stmt -> close();
- if($res -> num_rows == 0) {
- if($rating == -1) return;
- $stmt = $conn -> prepare("INSERT INTO rating (id,pid,val) VALUES (?,?,?)");
- $stmt -> bind_param("sid",$uid,$pid,$rating);
- $stmt -> execute();
- $stmt -> close();
- return;
- }
- $stmt = $conn -> prepare("UPDATE rating SET val=? WHERE id=? AND pid=?");
- $stmt -> bind_param("dsi",$rating,$uid,$pid);
- $stmt -> execute();
- $stmt -> close();
- return;
- }
-
- function updateVotesQuality($conn,$uid,$pid,$quality) {
- if($quality == -2) return;
- if($quality != -1 && ($quality < 1 || $quality > 5)) return;
- $stmt = $conn -> prepare("SELECT * FROM quality WHERE id=? AND pid=?");
- $stmt -> bind_param("si",$uid,$pid);
- $stmt -> execute();
- $res = $stmt -> get_result();
- $stmt -> close();
- if($res -> num_rows == 0) {
- if($quality == -1) return;
- $stmt = $conn -> prepare("INSERT INTO quality (id,pid,val) VALUES (?,?,?)");
- $stmt -> bind_param("sid",$uid,$pid,$quality);
- $stmt -> execute();
- $stmt -> close();
- return;
- }
- $stmt = $conn -> prepare("UPDATE quality SET val=? WHERE id=? AND pid=?");
- $stmt -> bind_param("dsi",$quality,$uid,$pid);
- $stmt -> execute();
- $stmt -> close();
- return;
- }
-
- function findAverage($arr) {
- return $average = array_sum($arr) / count($arr);
- }
-
- function findMedian($arr) {
- sort($arr);
- return $arr[floor(count($arr) / 2)];
- }
-
- function recalculateRatings($conn) {
- $stmt = $conn -> prepare("SELECT * FROM problems");
- $stmt -> execute();
- $res = $stmt -> get_result();
- $N = $res -> num_rows;
- $stmt -> close();
- $rating = [];
- for($i = 1;$i <= $N;$i++) {
- $rating[$i] = [];
- }
- $stmt = $conn -> prepare("SELECT * FROM rating");
- $stmt -> execute();
- $res = $stmt -> get_result();
- $stmt -> close();
- if($res -> num_rows > 0) {
- while($row = $res -> fetch_assoc()) {
- if($row["val"] != -1) array_push($rating[$row["pid"]],$row["val"]);
- }
- }
- for($i = 1;$i <= $N;$i++) {
- if(count($rating[$i]) == 0) {
- $stmt = $conn -> prepare("UPDATE problems SET rating=NULL,rating2=NULL,cnt1=0 WHERE id=" . $i);
- $stmt -> execute();
- $stmt -> close();
- continue;
- }
- $stmt = $conn -> prepare("UPDATE problems SET rating=?,rating2=?,cnt1=? WHERE id=?");
- $average = findAverage($rating[$i]);
- $median = findMedian($rating[$i]);
- $arrLen = count($rating[$i]);
- $stmt -> bind_param("ddii",$average,$median,$arrLen,$i);
- $stmt -> execute();
- $stmt -> close();
- }
- return;
- }
-
- function recalculateQualities($conn) {
- $stmt = $conn -> prepare("SELECT * FROM problems");
- $stmt -> execute();
- $res = $stmt -> get_result();
- $N = $res -> num_rows;
- $stmt -> close();
- $quality = [];
- for($i = 1;$i <= $N;$i++) {
- $quality[$i] = [];
- }
- $stmt = $conn -> prepare("SELECT * FROM quality");
- $stmt -> execute();
- $res = $stmt -> get_result();
- $stmt -> close();
- if($res -> num_rows > 0) {
- while($row = $res -> fetch_assoc()) {
- if($row["val"] != -1) array_push($quality[$row["pid"]],$row["val"]);
- }
- }
- for($i = 1;$i <= $N;$i++) {
- if(count($quality[$i]) == 0) {
- $stmt = $conn -> prepare("UPDATE problems SET quality=NULL,quality2=NULL,cnt2=0 WHERE id=" . $i);
- $stmt -> execute();
- $stmt -> close();
- continue;
- }
- $stmt = $conn -> prepare("UPDATE problems SET quality=?,quality2=?,cnt2=? WHERE id=?");
- $average = findAverage($quality[$i]);
- $median = findMedian($quality[$i]);
- $arrLen = count($quality[$i]);
- $stmt -> bind_param("ddii",$average,$median,$arrLen,$i);
- $stmt -> execute();
- $stmt -> close();
- }
- return;
- }
-
- function checkUserExist($conn,$uid) {
- $stmt = $conn -> prepare("SELECT * FROM users WHERE id=?");
- $stmt -> bind_param("s",$uid);
- $stmt -> execute();
- $res = $stmt -> get_result();
- if($res -> num_rows == 0) {
- return false;
- }
- return true;
- }
-
- function generateRandomString($length = 10) {
- $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $charactersLength = strlen($characters);
- $randomString = '';
- for($i = 0;$i < $length;$i++) {
- $randomString .= $characters[rand(0, $charactersLength - 1)];
- }
- return $randomString;
- }
-
- function callAPI($url){
- $result = json_decode(file_get_contents($url));
- return $result;
- }
-
- function checkCodeForcesExist($conn,$cf) {
- $stmt = $conn -> prepare("SELECT * FROM users WHERE cf=?");
- $stmt -> bind_param("s",$cf);
- $stmt -> execute();
- $res = $stmt -> get_result();
- if($res -> num_rows == 0) {
- return false;
- }
- return true;
- }
-
- function getUserId($conn,$cf_handle) {
- $stmt = $conn -> prepare("SELECT * FROM users WHERE cf=?");
- $stmt -> bind_param("s",$cf_handle);
- $stmt -> execute();
- $res = $stmt -> get_result();
- if($res -> num_rows == 0) {
- return "-1";
- }
- $info = $res -> fetch_assoc();
- return $info["id"];
- }
+ $conn->query("UPDATE stats SET value = value + 1 WHERE type = 'visit'");
+} else if ($type == 7) {
+ // Automatic registration
+
+ if (!isset($_POST["username"]) || !isset($_POST["name"])) {
+ $data["success"] = -5;
+ $data["message"] = "A required field is empty";
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+ exit("");
+ }
+
+ $username = strtolower($_POST["username"]);
+ $CFUsers = callAPI("http://codeforces.com/api/user.info?handles=" . $username)->result;
+
+ if (count($CFUsers) == 0) {
+ $data["success"] = -1;
+ $data["message"] = "The codeforces account does not exist!";
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+ exit("");
+ }
+
+ $CFUsers = $CFUsers[0];
+ $firstName = $CFUsers->firstName;
+ $rating = $CFUsers->rating;
+
+ // 1900 Threshold
+ if ($rating < 1900) {
+ $data["success"] = -2;
+ $data["message"] = "The codeforces account's rating does not meet the 1900 threshold. If you believe you are still qualified, please fill out the manual review form.";
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+ exit("");
+ }
+
+ if (trim($firstName) != "USACO-Rating-verify") {
+ $data["success"] = -3;
+ $data["message"] = "The codeforces account's first name is not 'USACO-Rating-verify'";
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+ exit("");
+ }
+
+ if (checkCodeForcesExist($conn, $username)) {
+ $data["success"] = -4;
+ $data["message"] = "You have already registered an account! Contact CodeTiger on discord if you lost your personalized link.";
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+ exit("");
+ }
+
+ // Everything passes :D
+ $uid = generateRandomString();
+ $name = $_POST["name"];
+
+ registerAccount($conn, $uid, $name, $username);
+
+ $data["status"] = 1;
+ $data["id"] = $uid;
+ $data["message"] = "Success!";
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+} else if ($type == 8) {
+ // Invitation Link Recovery
+
+ if (!isset($_POST["username"])) {
+ $data["success"] = -1;
+ $data["message"] = "A required field is empty";
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+ exit("");
+ }
+
+ $username = strtolower($_POST["username"]);
+
+ if (!checkCodeForcesExist($conn, $username)) {
+ $data["success"] = -2;
+ $data["message"] = "The account does not exist!";
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+ exit("");
+ }
+
+ $CFUsers = callAPI("http://codeforces.com/api/user.info?handles=" . $username)->result;
+
+ if (count($CFUsers) == 0) {
+ $data["success"] = -4;
+ $data["message"] = "The codeforces account does not exist!";
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+ exit("");
+ }
+
+ $CFUsers = $CFUsers[0];
+ $firstName = $CFUsers->firstName;
+
+ if (trim($firstName) != "USACO-Rating-verify") {
+ $data["success"] = -3;
+ $data["message"] = "The codeforces account's first name is not 'USACO-Rating-verify'";
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+ exit("");
+ }
+
+ $uid = getUserId($conn, $_POST["username"]);
+ $data["success"] = 0;
+ $data["id"] = $uid;
+ header('Content-type:application/json;charset=utf-8');
+ echo json_encode($data);
+ exit("");
+
+}
+
+function registerAccount($conn, $uid, $name, $cf)
+{
+ $stmt = $conn->prepare("INSERT INTO users (id,name,cf) VALUES (?,?,?)");
+ $stmt->bind_param("sss", $uid, $name, $cf);
+ $stmt->execute();
+ $stmt->close();
+}
+
+function recalculateEverything($conn)
+{
+ recalculateRatings($conn);
+ recalculateQualities($conn);
+}
+
+function updateVotesRating($conn, $uid, $pid, $rating)
+{
+ if ($rating == -2)
+ return;
+ if ($rating != -1 && ($rating < 800 || $rating > 3500))
+ return;
+ $stmt = $conn->prepare("SELECT * FROM rating WHERE id=? AND pid=?");
+ $stmt->bind_param("si", $uid, $pid);
+ $stmt->execute();
+ $res = $stmt->get_result();
+ $stmt->close();
+ if ($res->num_rows == 0) {
+ if ($rating == -1)
+ return;
+ $stmt = $conn->prepare("INSERT INTO rating (id,pid,val) VALUES (?,?,?)");
+ $stmt->bind_param("sid", $uid, $pid, $rating);
+ $stmt->execute();
+ $stmt->close();
+ return;
+ }
+ $stmt = $conn->prepare("UPDATE rating SET val=? WHERE id=? AND pid=?");
+ $stmt->bind_param("dsi", $rating, $uid, $pid);
+ $stmt->execute();
+ $stmt->close();
+ return;
+}
+
+function updateVotesQuality($conn, $uid, $pid, $quality)
+{
+ if ($quality == -2)
+ return;
+ if ($quality != -1 && ($quality < 1 || $quality > 5))
+ return;
+ $stmt = $conn->prepare("SELECT * FROM quality WHERE id=? AND pid=?");
+ $stmt->bind_param("si", $uid, $pid);
+ $stmt->execute();
+ $res = $stmt->get_result();
+ $stmt->close();
+ if ($res->num_rows == 0) {
+ if ($quality == -1)
+ return;
+ $stmt = $conn->prepare("INSERT INTO quality (id,pid,val) VALUES (?,?,?)");
+ $stmt->bind_param("sid", $uid, $pid, $quality);
+ $stmt->execute();
+ $stmt->close();
+ return;
+ }
+ $stmt = $conn->prepare("UPDATE quality SET val=? WHERE id=? AND pid=?");
+ $stmt->bind_param("dsi", $quality, $uid, $pid);
+ $stmt->execute();
+ $stmt->close();
+ return;
+}
+
+function findAverage($arr)
+{
+ return $average = array_sum($arr) / count($arr);
+}
+
+function findMedian($arr)
+{
+ sort($arr);
+ return $arr[floor(count($arr) / 2)];
+}
+
+function recalculateRatings($conn)
+{
+ $stmt = $conn->prepare("SELECT * FROM problems");
+ $stmt->execute();
+ $res = $stmt->get_result();
+ $N = $res->num_rows;
+ $stmt->close();
+ $rating = [];
+ for ($i = 1; $i <= $N; $i++) {
+ $rating[$i] = [];
+ }
+ $stmt = $conn->prepare("SELECT * FROM rating");
+ $stmt->execute();
+ $res = $stmt->get_result();
+ $stmt->close();
+ if ($res->num_rows > 0) {
+ while ($row = $res->fetch_assoc()) {
+ if ($row["val"] != -1)
+ array_push($rating[$row["pid"]], $row["val"]);
+ }
+ }
+ for ($i = 1; $i <= $N; $i++) {
+ if (count($rating[$i]) == 0) {
+ $stmt = $conn->prepare("UPDATE problems SET rating=NULL,rating2=NULL,cnt1=0 WHERE id=" . $i);
+ $stmt->execute();
+ $stmt->close();
+ continue;
+ }
+ $stmt = $conn->prepare("UPDATE problems SET rating=?,rating2=?,cnt1=? WHERE id=?");
+ $average = findAverage($rating[$i]);
+ $median = findMedian($rating[$i]);
+ $arrLen = count($rating[$i]);
+ $stmt->bind_param("ddii", $average, $median, $arrLen, $i);
+ $stmt->execute();
+ $stmt->close();
+ }
+ return;
+}
+
+function recalculateQualities($conn)
+{
+ $stmt = $conn->prepare("SELECT * FROM problems");
+ $stmt->execute();
+ $res = $stmt->get_result();
+ $N = $res->num_rows;
+ $stmt->close();
+ $quality = [];
+ for ($i = 1; $i <= $N; $i++) {
+ $quality[$i] = [];
+ }
+ $stmt = $conn->prepare("SELECT * FROM quality");
+ $stmt->execute();
+ $res = $stmt->get_result();
+ $stmt->close();
+ if ($res->num_rows > 0) {
+ while ($row = $res->fetch_assoc()) {
+ if ($row["val"] != -1)
+ array_push($quality[$row["pid"]], $row["val"]);
+ }
+ }
+ for ($i = 1; $i <= $N; $i++) {
+ if (count($quality[$i]) == 0) {
+ $stmt = $conn->prepare("UPDATE problems SET quality=NULL,quality2=NULL,cnt2=0 WHERE id=" . $i);
+ $stmt->execute();
+ $stmt->close();
+ continue;
+ }
+ $stmt = $conn->prepare("UPDATE problems SET quality=?,quality2=?,cnt2=? WHERE id=?");
+ $average = findAverage($quality[$i]);
+ $median = findMedian($quality[$i]);
+ $arrLen = count($quality[$i]);
+ $stmt->bind_param("ddii", $average, $median, $arrLen, $i);
+ $stmt->execute();
+ $stmt->close();
+ }
+ return;
+}
+
+function checkUserExist($conn, $uid)
+{
+ $stmt = $conn->prepare("SELECT * FROM users WHERE id=?");
+ $stmt->bind_param("s", $uid);
+ $stmt->execute();
+ $res = $stmt->get_result();
+ if ($res->num_rows == 0) {
+ return false;
+ }
+ return true;
+}
+
+function generateRandomString($length = 10)
+{
+ $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ $charactersLength = strlen($characters);
+ $randomString = '';
+ for ($i = 0; $i < $length; $i++) {
+ $randomString .= $characters[rand(0, $charactersLength - 1)];
+ }
+ return $randomString;
+}
+
+function callAPI($url)
+{
+ $result = json_decode(file_get_contents($url));
+ return $result;
+}
+
+function checkCodeForcesExist($conn, $cf)
+{
+ $stmt = $conn->prepare("SELECT * FROM users WHERE cf=?");
+ $stmt->bind_param("s", $cf);
+ $stmt->execute();
+ $res = $stmt->get_result();
+ if ($res->num_rows == 0) {
+ return false;
+ }
+ return true;
+}
+
+function getUserId($conn, $cf_handle)
+{
+ $stmt = $conn->prepare("SELECT * FROM users WHERE cf=?");
+ $stmt->bind_param("s", $cf_handle);
+ $stmt->execute();
+ $res = $stmt->get_result();
+ if ($res->num_rows == 0) {
+ return "-1";
+ }
+ $info = $res->fetch_assoc();
+ return $info["id"];
+}
?>
\ No newline at end of file
diff --git a/backend/problems_importer.php b/backend/problems_importer.php
index 787d324..d0d50a1 100644
--- a/backend/problems_importer.php
+++ b/backend/problems_importer.php
@@ -1,18 +1,19 @@
prepare("INSERT INTO problems (contest,name,url,type) VALUES (?,?,?,?)");
- $stmt -> bind_param("sssi",$info[0],$info[1],$info[2],$info[3]);
- $stmt -> execute();
- $stmt -> close();
- }
+while (!feof($file)) {
+ $line = fgets($file);
+ $info = explode("|", $line);
+ $stmt = $conn->prepare("INSERT INTO problems (contest,name,url,type) VALUES (?,?,?,?)");
+ $stmt->bind_param("sssi", $info[0], $info[1], $info[2], $info[3]);
+ $stmt->execute();
+ $stmt->close();
+}
- fclose($file);
+fclose($file);
?>
\ No newline at end of file
diff --git a/css/main.css b/css/main.css
index 41bd245..948f6d8 100644
--- a/css/main.css
+++ b/css/main.css
@@ -1,37 +1,37 @@
.main-container {
- margin-top: 3rem;
- margin-left: 6%;
- margin-right: 6%;
- margin-bottom: 80px;
- width: 88%;
+ margin-top: 3rem;
+ margin-left: 6%;
+ margin-right: 6%;
+ margin-bottom: 80px;
+ width: 88%;
}
span.difficulty-circle {
- display: inline-block;
- border-radius: 50%;
- border-style: solid;
- border-width: 1px;
- margin-right: 5px;
- height: 12px;
- width: 12px;
+ display: inline-block;
+ border-radius: 50%;
+ border-style: solid;
+ border-width: 1px;
+ margin-right: 5px;
+ height: 12px;
+ width: 12px;
}
.vote-input {
- border: none;
- outline: none;
- font-size: 18px;
- width: 100%;
+ border: none;
+ outline: none;
+ font-size: 18px;
+ width: 100%;
}
.grayContainer {
margin-bottom: 60px;
width: 80%;
margin-left: 10%;
- background-color: #FAFAFA;
+ background-color: #fafafa;
box-shadow: 0 4px 6px rgb(8 8 8 / 10%), 0 0 0 1px rgb(8 8 8 / 10%);
padding: 40px 50px 40px 50px;
word-break: break-word;
word-wrap: break-word;
font-size: 18px;
color: #404040;
-}
\ No newline at end of file
+}
diff --git a/css/utility.css b/css/utility.css
index da29708..cd8755e 100644
--- a/css/utility.css
+++ b/css/utility.css
@@ -1,11 +1,11 @@
hr {
- margin-top: 10px;
- margin-bottom: 10px
+ margin-top: 10px;
+ margin-bottom: 10px;
}
.unselectable {
- -moz-user-select: none;
- -webkit-user-select: none;
- -ms-user-select: none;
- user-select: none;
-}
\ No newline at end of file
+ -moz-user-select: none;
+ -webkit-user-select: none;
+ -ms-user-select: none;
+ user-select: none;
+}
diff --git a/frontend/about.html b/frontend/about.html
index 5bcc845..7bce530 100644
--- a/frontend/about.html
+++ b/frontend/about.html
@@ -1,78 +1,170 @@
-
- USACO Rating - About
-
-
-
-
-
-
-
+
+ USACO Rating - About
+
+
+
-
-
+
+
+
-
-
-
+
+
-
-
-
+
+
+
-
-
- USACO Rating
-
-
-
+
+
+
-
-
+
+
+ USACO Rating
+
+
+
-
-
About the Author
-
-
-
CodeTiger
-
-
Hello. I am an active Competitive-Programmer who has been doing USACO since 7th grade. You can find more about me on my personal website . The reason I created this project was because there currently isn't a concrete system for evaluating USACO problem difficulties. I remember when I first started USACO, I had no idea what to train on. Especially as I reach higher divisions, problems on the same contest can be vastly different in terms of difficulties. Some were in my range, some were too hard, and some were too easy. Furthermore, since I did not know the difficulties beforehand, I often waste a high-quality problem that isn't in my reach by reading the editorial. Therefore I hope this project serves as a remedy for that issue. By quantifying the difficulties and qualities, people can much easily train on problems that fit for them.
-
Contact
-
-
Email :
codetiger927@gmail.com
-
Discord :
CodeTiger#1869
-
Github :
CodeTiger927
-
CodeForces :
codetiger927
-
-
-
\ No newline at end of file
+
+
+
+
+
About the Author
+
+
+
CodeTiger
+
+
+ Hello. I am an active Competitive-Programmer who has been doing
+ USACO since 7th grade. You can find more about me on my personal
+ website . The reason I created
+ this project was because there currently isn't a concrete system
+ for evaluating USACO problem difficulties. I remember when I
+ first started USACO, I had no idea what to train on. Especially
+ as I reach higher divisions, problems on the same contest can be
+ vastly different in terms of difficulties. Some were in my
+ range, some were too hard, and some were too easy. Furthermore,
+ since I did not know the difficulties beforehand, I often waste
+ a high-quality problem that isn't in my reach by reading the
+ editorial. Therefore I hope this project serves as a remedy for
+ that issue. By quantifying the difficulties and qualities,
+ people can much easily train on problems that fit for them.
+
+
+
Contact
+
+
Email :
+
codetiger927@gmail.com
+
Discord :
+
CodeTiger#1869
+
Github :
+
CodeTiger927
+
CodeForces :
+
codetiger927
+
+
+