SpreadQuiz/cli_actions.php
2025-10-11 20:06:07 +02:00

72 lines
2.0 KiB
PHP

<?php
require_once "vendor/autoload.php";
require_once "class/TestMgr.php";
require_once "class/GameMgr.php";
require_once "class/LogicFunction.php";
ini_set('display_errors', 1);
const longopts = [
"action:", // execute some CLI action
"tick", // tick timed objects (e.g. timed tests)
];
$options = getopt("", longopts);
// CLI actions
if (isset($options["action"])) {
$action = $options["action"];
switch ($action) {
case "upgrade_tests":
{
printf("Upgrading tests...");
$testMgr = new TestMgr();
$testMgr->upgradeTests();
printf("OK!\n");
}
break;
case "upgrade_games":
{
printf("Upgrading games...");
$gameMgr = new GameMgr();
$gameMgr->upgradeGames();
printf("OK!\n");
}
break;
case "get_timed_tests":
{
$testMgr = new TestMgr();
printf("Expired timed tests: %s\n", join(", ", $testMgr->extractExpiredTimedTestIds()));
}
break;
case "gen_random":
{
$lf = LogicFunction::genRandom(["a", "b", "c"], 2, 4);
//$lf = LogicFunction::genRandomDF(["a", "b", "c"]);
printf("Verilog-form: %s\nTeX-form: %s\n", $lf->getExpression(), $lf->getExpression("tex"));
print_r($lf->getTruthTable());
print_r($lf->toDNF());
//$lf->drawNetwork("TESTING/network.svg");
}
break;
case "verify":
{
printf("Verifying expression\n");
$ok = LogicFunction::isCorrectDNF(["a", "b", "c"], "(a & ~b & c) | (b & ~c & a)");
printf("%d\n", $ok);
}
break;
}
}
// Tick tests
if (isset($options["tick"])) {
$testMgr = new TestMgr();
$timedTestIDs = $testMgr->extractExpiredTimedTestIds();
$testMgr->upgradeTests($timedTestIDs);
}