Esempio n. 1
0
 public static function cache_get($directory, $file, $later_than = "-5 minutes")
 {
     $file = TBA::cache_clean_filename($file);
     if (!file_exists("{$directory}/{$file}.json")) {
         return FALSE;
     }
     $file_contents = json_decode(file_get_contents("{$directory}/{$file}.json"), 1);
     if (!count($file_contents)) {
         return FALSE;
     }
     if (!is_integer($later_than) && strlen($later_than)) {
         $later_than = strtotime($later_than);
     }
     if ($later_than > $file_contents["timestamp"]) {
         return FALSE;
     }
     return $file_contents["contents"];
 }
<?php

$api_dir = __DIR__;
require_once "{$api_dir}/helpers.php";
require_all("{$base_dir}/classes");
require "{$api_dir}/pages/team/default-fields.php";
$default_fields = $output["fields"];
$user = array("organization_id" => 1, "id" => 1);
$dbh = new DBHandler(json_decode(file_get_contents("{$api_dir}/dbconfig.json"), 1));
$sdb = new ScoutingDB($dbh, $user["organization_id"], 1, $user["id"]);
$tba = new TBA();
$file = $argv[1];
if (!file_exists($file)) {
    die("{$file} does not exist");
}
$file_contents = file_get_contents($file);
$data = array("stats" => array("defenses" => json_decode($file_contents, 1)));
$team_stats = array();
foreach ($data["stats"] as $stat => $teams) {
    if (is_string($teams)) {
        $teams = json_decode($teams, 1);
    }
    foreach ($teams as $team_number => $stats) {
        if (!isset($team_stats[$team_number])) {
            $team_stats[$team_number] = array();
        }
        $team_stats[$team_number][$stat] = $stats;
    }
}
$json_fields = array("questions", "stats");
foreach ($team_stats as $team_number => $stats) {
Esempio n. 3
0
<?php

// Import teams route (api/team/import)
// Import teams from a tba event code (e.g. "2016ncral")
global $dbh;
// Auth user
$user = Auth::authAPICall($dbh);
// Initialize scouting db
$sdb = new ScoutingDB($dbh, $user["organization_id"], 1, $user["id"]);
$tba = new TBA();
require __DIR__ . "/default-fields.php";
$default_fields = $output["fields"];
$required_fields = array("event_code" => "Event Code");
$other_fields = array();
$errors = array();
$success = true;
if (isset($post) && count($post) && $_SERVER["REQUEST_METHOD"] == "POST") {
    $team_data = array();
    foreach ($required_fields as $field => $label) {
        if (isset($post[$field]) && strlen(trim($post[$field]))) {
            $team_data[$field] = trim($post[$field]);
        } else {
            $errors[] = array("field" => $field, "msg" => "{$label} is required");
            $success = false;
        }
    }
    foreach ($other_fields as $field) {
        if (isset($post[$field]) && strlen(trim($post[$field]))) {
            $team_data[$field] = trim($post[$field]);
        }
    }
Esempio n. 4
0
<?php

// Get tba result (api/tba)
global $dbh;
// Auth user
$user = Auth::authAPICall($dbh);
// Initialize scouting db
$sdb = new ScoutingDB($dbh, $user["organization_id"], 1, $user["id"]);
$tba = new TBA();
$data = array_merge(array("url" => "", "later_than" => ""), $_GET);
$output["data"] = $tba->get($data["url"], $data["later_than"]);