From 7dac619cf1bce9fc61cf3ed87260cbe586c7afb6 Mon Sep 17 00:00:00 2001 From: marko Date: Sat, 3 Feb 2024 11:59:38 +0100 Subject: [PATCH 1/5] WIP: added promote function, still missing: promote form --- homepage/participo/pmelo.inc.php | 246 ++++++++++++++++++++++--------- 1 file changed, 176 insertions(+), 70 deletions(-) diff --git a/homepage/participo/pmelo.inc.php b/homepage/participo/pmelo.inc.php index 5cfaeb6..b6304a3 100644 --- a/homepage/participo/pmelo.inc.php +++ b/homepage/participo/pmelo.inc.php @@ -1,19 +1,20 @@ -var_log($_SESSION, "session"); @@ -21,106 +22,163 @@ class PmElo{ session_start(); // create 'pmelo' section in the sessions data - if(!array_key_exists('pmelo', $_SESSION)){ - $_SESSION['pmelo'] = []; - } - // - data storage for id-s of chosen fighters - if(!array_key_exists('fighterIds', $_SESSION['pmelo'])){ - $_SESSION['pmelo']['fighterIds'] = []; + if (!array_key_exists("pmelo", $_SESSION)) { + $_SESSION["pmelo"] = []; } - - // check for action in post data - if(array_key_exists('pmelo', $_POST)){ - if(array_key_exists('fighterIds', $_POST['pmelo'])){ - $_SESSION['pmelo']['fighterIds']=$_POST['pmelo']['fighterIds']; - } - // $this->var_log($_SESSION, "session"); + // - data storage for id-s of chosen fighters + if (!array_key_exists("fighterIds", $_SESSION["pmelo"])) { + $_SESSION["pmelo"]["fighterIds"] = []; } // load/recreate ranking data - if(!is_file(self::$pmeloJson)){ - $this->log['info'][] = "Couldn't find `".self::$pmeloJson."`. Create a new one!"; + if (!is_file(self::$pmeloJson)) { + $this->log["info"][] = + "Couldn't find `" . self::$pmeloJson . "`. Create a new one!"; file_put_contents(self::$pmeloJson, json_encode([])); } // init members $this->trainees = self::getTrainees(); - $this->var_log(array_map(function($user){return $user->getFirstName();},$this->trainees), "trainees from db"); + $this->var_log( + array_map(function ($user) { + return $user->getFirstName(); + }, $this->trainees), + "trainees from db" + ); $this->rankings = $this->createRankings(); - $this->var_log(array_map(function($id){return $this->trainees[$id]->getFirstName();},$this->rankings), "current ranking"); + $this->var_log( + array_map(function ($id) { + return $this->trainees[$id]->getFirstName(); + }, $this->rankings), + "current ranking" + ); $this->fighters = []; - foreach($_SESSION['pmelo']['fighterIds'] as $id){ + foreach ($_SESSION["pmelo"]["fighterIds"] as $id) { $this->fighters[$id] = $this->trainees[$id]; - }; - $this->var_log(array_map(function($user){return $user->getFirstName();},$this->fighters), "fighters"); - + } + $this->var_log( + array_map(function ($user) { + return $user->getFirstName(); + }, $this->fighters), + "fighters" + ); + + // @todo Can be split. Some actions need the members to be already filled, some could be done earlier. + // check for action in post data + if (array_key_exists("pmelo", $_POST)) { + // setting the current fighters + // - meaning: fighter list is automatically updated by posted fighters + if (array_key_exists("fighterIds", $_POST["pmelo"])) { + $_SESSION["pmelo"]["fighterIds"] = + $_POST["pmelo"]["fighterIds"]; + + header("Location: ."); + } + + if (array_key_exist("promote", $_POST["pmelo"])) { + $promote = $_POST["pmelo"]["promote"]; + $this->promote( + $promote["promoteeId"], + $promote["promoteeRank"], + $promote["degradeeId"], + $promote["degradeeRank"] + ); + + header("Location: ."); + } + + // $this->var_log($_SESSION, "session"); + } // save the updated ranking // @todo should be in destructor self::saveRankings($this->rankings); } - function __destruct(){ + function __destruct() + { // sad, the destructor is not allowed to use file_put_contents } - + // load all active trainees into a id=>User assoc array - public static function getTrainees(){ - $traineeList = array_map('User::fromDbArray', User::dbSelectWithAttribute(4)); + public static function getTrainees() + { + $traineeList = array_map( + "User::fromDbArray", + User::dbSelectWithAttribute(4) + ); $traineeAssocArray = []; - foreach($traineeList as $trainee){ + foreach ($traineeList as $trainee) { $traineeAssocArray[$trainee->getId()] = $trainee; } return $traineeAssocArray; } // load ranking from json file - public static function loadRankings(){ + public static function loadRankings() + { return json_decode(file_get_contents(self::$pmeloJson)); } - + // save a ranking to json file - public static function saveRankings(array $rankings){ + public static function saveRankings(array $rankings) + { file_put_contents(self::$pmeloJson, json_encode($rankings)); } // simple logger to a logging buffer - function var_log($variable, string $prefix=null, string $logChannel='info'){ - if(!in_array($logChannel, ['info', 'warning', 'error'])){ - $logChannel='info'; + function var_log( + $variable, + string $prefix = null, + string $logChannel = "info" + ) { + if (!in_array($logChannel, ["info", "warning", "error"])) { + $logChannel = "info"; } - $prefix = (!empty($prefix) ? $prefix.": " : ""); - $this->log[$logChannel][]=$prefix.var_export($variable, true); + $prefix = !empty($prefix) ? $prefix . ": " : ""; + $this->log[$logChannel][] = $prefix . var_export($variable, true); } // create the ranking for the current session (load saved ranking from file, remove old trainees, add new trainees) - public function createRankings(){ + public function createRankings() + { // load the last state of the ranking $loadedRanking = self::loadRankings(); - $this->var_log(array_map(function($id){$user=$this->trainees[$id]; return $user->getFirstName();}, $loadedRanking), "loaded ranking"); + $this->var_log( + array_map(function ($id) { + $user = $this->trainees[$id]; + return $user->getFirstName(); + }, $loadedRanking), + "loaded ranking" + ); // check if the ranked trainees still are in training // - the ranking with $cleanRanking = []; // - trainees that aren't currently in the ranking for later inserting $toBeInsertedTrainees = $this->trainees; - foreach($loadedRanking as $id){ - if(array_key_exists($id, $this->trainees)){ + foreach ($loadedRanking as $id) { + if (array_key_exists($id, $this->trainees)) { // userId is still in training, so append it to the cleaned up ranking $cleanRanking[] = $id; // trainees already in the ranking we won't have to insert manual unset($toBeInsertedTrainees[$id]); } } - + // get the ids of the to be inserted trainees sorted by the birthday - $newTraineesIds = array_map(function($u){return $u->getId();},$toBeInsertedTrainees); - usort( - $newTraineesIds - , function($lhs, $rhs){ - return $this->trainees[$lhs]->getStrBirthday() < $this->trainees[$rhs]->getStrBirthday() ? -1 : ($this->trainees[$lhs]->getStrBirthday() > $this->trainees[$rhs]->getStrBirthday() ? 1 : 0); - } - ); + $newTraineesIds = array_map(function ($u) { + return $u->getId(); + }, $toBeInsertedTrainees); + usort($newTraineesIds, function ($lhs, $rhs) { + return $this->trainees[$lhs]->getStrBirthday() < + $this->trainees[$rhs]->getStrBirthday() + ? -1 + : ($this->trainees[$lhs]->getStrBirthday() > + $this->trainees[$rhs]->getStrBirthday() + ? 1 + : 0); + }); // $this->var_log( // array_map( // function($id){return $this->trainees[$id]->getStrBirthday()." ".$this->trainees[$id]->getFirstName();} @@ -129,51 +187,99 @@ class PmElo{ // , "newTraineesBy B-Day" // ); - // now we do a mergesort (step) + // now we do a mergesort (step) $updatedRanking = []; - $idxNewTrainees = count($newTraineesIds)-1; - $idxRanking = count($cleanRanking)-1; + $idxNewTrainees = count($newTraineesIds) - 1; + $idxRanking = count($cleanRanking) - 1; // - while we can merge, we merge - while( ($idxRanking >= 0) && ($idxNewTrainees >= 0) ){ + while ($idxRanking >= 0 && $idxNewTrainees >= 0) { // $this->var_log( [$idxRanking.", ".$idxNewTrainees=>$updatedRanking] ); // $this->var_log( // [$this->trainees[$cleanRanking[$idxRanking]]->getStrBirthday(), $this->trainees[$newTraineesIds[$idxRanking]]->getStrBirthday()] // ); - if( - $this->trainees[$cleanRanking[$idxRanking]]->getDateOfBirth() - > $this->trainees[$newTraineesIds[$idxNewTrainees]]->getDateOfBirth() - ){ + if ( + $this->trainees[$cleanRanking[$idxRanking]]->getDateOfBirth() > + $this->trainees[ + $newTraineesIds[$idxNewTrainees] + ]->getDateOfBirth() + ) { // $this->var_log( $this->trainees[$cleanRanking[$idxRanking]]->getFirstName(), "merge ranking insert" ); array_unshift($updatedRanking, $cleanRanking[$idxRanking]); - $idxRanking-=1; - }else{ + $idxRanking -= 1; + } else { // $this->var_log( $this->trainees[$newTraineesIds[$idxNewTrainees]]->getFirstName(), "merge trainees insert" ); - array_unshift($updatedRanking, $newTraineesIds[$idxNewTrainees]); - $idxNewTrainees-=1; + array_unshift( + $updatedRanking, + $newTraineesIds[$idxNewTrainees] + ); + $idxNewTrainees -= 1; } } // $this->var_log( // ["idxR ".$idxRanking." idxNT ".$idxNewTrainees=>[$cleanRanking, $newTraineesIds]] // , "after merge" // ); - while( $idxRanking >= 0 ){ + while ($idxRanking >= 0) { // $this->var_log( $this->trainees[$cleanRanking[$idxRanking]]->getFirstName(), "rest ranking insert" ); array_unshift($updatedRanking, $cleanRanking[$idxRanking]); - $idxRanking-=1; + $idxRanking -= 1; } - while( $idxNewTrainees >= 0 ){ + while ($idxNewTrainees >= 0) { // $this->var_log( $this->trainees[$newTraineesIds[$idxNewTrainees]]->getFirstName(), "rest newTrainees insert" ); array_unshift($updatedRanking, $newTraineesIds[$idxNewTrainees]); - $idxNewTrainees-=1; + $idxNewTrainees -= 1; } return $updatedRanking; } - public $log = ['error'=>[], 'warning'=>[], 'info'=>[]]; + private function promote( + int $promoteeId, + int $promoteeRank, + int $degradeeId, + int $degradeeRank + ) { + // input sanitation + filterId($promoteeId); + filterId($promoteeRank); + filterId($degradeeId); + filterId($degradeeRank); + // check if both id are in the current fighter list + if ( + array_key_exists($promoteeId, $this->fighters) && + array_key_exists($degradeeId, $this->fighters) + ) { + // check their current rank + if ( + $this->rankings[$promoteeRank] == $promoteeId && + $this->rankings[$degradeeRank] == $degradeeId + ) { + // @todo check if they are rank neighbors in the fighter list + if (true) { + // do the actual switch + $this->rankings[$promoteeRank] = $degradeeId; + $this->rankings[$degradeeRank] = $promoteeId; + + $this->saveRankings(); + } + } + } + // save the updated ranking + } + // promotion means switching the position with another user + // id-s would already be sufficient, rank is just for controlling + function htmlPromoteButton( + int $promoteeId, + int $promoteeRank, + int $degradeeId, + int $degradeeRank + ) { + } + + public $log = ["error" => [], "warning" => [], "info" => []]; public $fighters = null; public $trainees = null; // list of id-s in the order of the current ranking public $rankings = null; - static $pmeloJson="./pmeloRanking.json"; -} \ No newline at end of file + static $pmeloJson = "./pmeloRanking.json"; +} From da2ccb3ba3c2f60e927ae1607137b404480face6 Mon Sep 17 00:00:00 2001 From: marko Date: Sat, 3 Feb 2024 20:08:36 +0100 Subject: [PATCH 2/5] pmelo working version --- homepage/participo/pmelo.inc.php | 64 +++++------------------ homepage/participo/pmelo.php | 88 +++++++++++++++++++------------- 2 files changed, 65 insertions(+), 87 deletions(-) diff --git a/homepage/participo/pmelo.inc.php b/homepage/participo/pmelo.inc.php index b6304a3..9a491dc 100644 --- a/homepage/participo/pmelo.inc.php +++ b/homepage/participo/pmelo.inc.php @@ -17,7 +17,6 @@ class PmElo { function __construct() { - // $this->var_log($_SESSION, "session"); // starting/continuing a session session_start(); @@ -39,29 +38,11 @@ class PmElo // init members $this->trainees = self::getTrainees(); - $this->var_log( - array_map(function ($user) { - return $user->getFirstName(); - }, $this->trainees), - "trainees from db" - ); $this->rankings = $this->createRankings(); - $this->var_log( - array_map(function ($id) { - return $this->trainees[$id]->getFirstName(); - }, $this->rankings), - "current ranking" - ); $this->fighters = []; foreach ($_SESSION["pmelo"]["fighterIds"] as $id) { $this->fighters[$id] = $this->trainees[$id]; } - $this->var_log( - array_map(function ($user) { - return $user->getFirstName(); - }, $this->fighters), - "fighters" - ); // @todo Can be split. Some actions need the members to be already filled, some could be done earlier. // check for action in post data @@ -72,10 +53,10 @@ class PmElo $_SESSION["pmelo"]["fighterIds"] = $_POST["pmelo"]["fighterIds"]; - header("Location: ."); + header("Location: pmelo"); } - if (array_key_exist("promote", $_POST["pmelo"])) { + if (array_key_exists("promote", $_POST["pmelo"])) { $promote = $_POST["pmelo"]["promote"]; $this->promote( $promote["promoteeId"], @@ -84,10 +65,9 @@ class PmElo $promote["degradeeRank"] ); - header("Location: ."); + header("Location: pmelo"); } - // $this->var_log($_SESSION, "session"); } // save the updated ranking @@ -144,13 +124,6 @@ class PmElo { // load the last state of the ranking $loadedRanking = self::loadRankings(); - $this->var_log( - array_map(function ($id) { - $user = $this->trainees[$id]; - return $user->getFirstName(); - }, $loadedRanking), - "loaded ranking" - ); // check if the ranked trainees still are in training // - the ranking with @@ -179,13 +152,6 @@ class PmElo ? 1 : 0); }); - // $this->var_log( - // array_map( - // function($id){return $this->trainees[$id]->getStrBirthday()." ".$this->trainees[$id]->getFirstName();} - // , $newTraineesIds - // ) - // , "newTraineesBy B-Day" - // ); // now we do a mergesort (step) $updatedRanking = []; @@ -193,21 +159,15 @@ class PmElo $idxRanking = count($cleanRanking) - 1; // - while we can merge, we merge while ($idxRanking >= 0 && $idxNewTrainees >= 0) { - // $this->var_log( [$idxRanking.", ".$idxNewTrainees=>$updatedRanking] ); - // $this->var_log( - // [$this->trainees[$cleanRanking[$idxRanking]]->getStrBirthday(), $this->trainees[$newTraineesIds[$idxRanking]]->getStrBirthday()] - // ); if ( $this->trainees[$cleanRanking[$idxRanking]]->getDateOfBirth() > $this->trainees[ $newTraineesIds[$idxNewTrainees] ]->getDateOfBirth() ) { - // $this->var_log( $this->trainees[$cleanRanking[$idxRanking]]->getFirstName(), "merge ranking insert" ); array_unshift($updatedRanking, $cleanRanking[$idxRanking]); $idxRanking -= 1; } else { - // $this->var_log( $this->trainees[$newTraineesIds[$idxNewTrainees]]->getFirstName(), "merge trainees insert" ); array_unshift( $updatedRanking, $newTraineesIds[$idxNewTrainees] @@ -215,17 +175,11 @@ class PmElo $idxNewTrainees -= 1; } } - // $this->var_log( - // ["idxR ".$idxRanking." idxNT ".$idxNewTrainees=>[$cleanRanking, $newTraineesIds]] - // , "after merge" - // ); while ($idxRanking >= 0) { - // $this->var_log( $this->trainees[$cleanRanking[$idxRanking]]->getFirstName(), "rest ranking insert" ); array_unshift($updatedRanking, $cleanRanking[$idxRanking]); $idxRanking -= 1; } while ($idxNewTrainees >= 0) { - // $this->var_log( $this->trainees[$newTraineesIds[$idxNewTrainees]]->getFirstName(), "rest newTrainees insert" ); array_unshift($updatedRanking, $newTraineesIds[$idxNewTrainees]); $idxNewTrainees -= 1; } @@ -259,20 +213,28 @@ class PmElo $this->rankings[$promoteeRank] = $degradeeId; $this->rankings[$degradeeRank] = $promoteeId; - $this->saveRankings(); + $this->saveRankings($this->rankings); } } } // save the updated ranking + $this->saveRankings($this->rankings); } // promotion means switching the position with another user // id-s would already be sufficient, rank is just for controlling - function htmlPromoteButton( + public static function htmlPromoteButton( int $promoteeId, int $promoteeRank, int $degradeeId, int $degradeeRank ) { + return "
" . + "" . + "" . + "" . + "" . + "". + "
"; } public $log = ["error" => [], "warning" => [], "info" => []]; diff --git a/homepage/participo/pmelo.php b/homepage/participo/pmelo.php index da60dfb..caf4e6e 100644 --- a/homepage/participo/pmelo.php +++ b/homepage/participo/pmelo.php @@ -1,4 +1,4 @@ - + @@ -6,7 +6,7 @@ - + @@ -32,7 +32,7 @@ cwsvJudoApps - + @@ -43,11 +43,16 @@
@@ -59,46 +64,57 @@ PlatzNameAufstieg - fighters)){ - foreach($pmelo->rankings as $rank=>$id){ - if(array_key_exists($id, $pmelo->fighters)){ - $fighter = $pmelo->fighters[$id]; - // echo("".$rank."".$fighter->getFirstName()."".PHP_EOL); - echo("".$rank."".$fighter->getFirstName()." ".$fighter->getName()."^".PHP_EOL); - } - } -} - ?> + fighters)) { + // remember the predecessor for the promoting form + $lastOne = null; + foreach ($pmelo->rankings as $rank => $id) { + if (array_key_exists($id, $pmelo->fighters)) { + $fighter = $pmelo->fighters[$id]; + echo "" . + "" . + $rank . + "" . + "" . + $fighter->getFirstName() . + " " . + $fighter->getName() . + "" . + "" . + (!is_null($lastOne) + ? $pmelo->htmlPromoteButton( + $fighter->getId(), + $rank, + $lastOne["id"], + $lastOne["rank"] + ) + : "") . + "" . + "" . + PHP_EOL; + $lastOne = ["id" => $fighter->getId(), "rank" => $rank]; + } + } + } ?>
  • Logs

  • -log as $logLevel=>$messages){ - if(!empty($messages)){ -?> +log as $logLevel => $messages) { + if (!empty($messages)) { ?>
    • -
    • - +
    • +
    • - +
    • - +
  • + - +} ?>
From b5d2655e8cd2c0b3102d75551029b6901c5d8b64 Mon Sep 17 00:00:00 2001 From: marko Date: Sun, 4 Feb 2024 19:32:30 +0100 Subject: [PATCH 3/5] pmelo cleaning up --- homepage/participo/pmelo.inc.php | 217 ++++++++++++++++++++++++++----- homepage/participo/pmelo.php | 80 +----------- 2 files changed, 189 insertions(+), 108 deletions(-) diff --git a/homepage/participo/pmelo.inc.php b/homepage/participo/pmelo.inc.php index 9a491dc..9db3b48 100644 --- a/homepage/participo/pmelo.inc.php +++ b/homepage/participo/pmelo.inc.php @@ -15,6 +15,7 @@ $pmelo = new PmElo(); class PmElo { + /** initialize the pmelo session */ function __construct() { // starting/continuing a session @@ -75,13 +76,31 @@ class PmElo self::saveRankings($this->rankings); } - function __destruct() - { - // sad, the destructor is not allowed to use file_put_contents + //// + // html code injection + /// + + /** Echo the fighterInputForm */ + public function htmlFighterInputForm(){ + echo($this->getFighterInputForm($this->trainees)); } - // load all active trainees into a id=>User assoc array - public static function getTrainees() + /** Echo the fighterTable */ + public function htmlFighterTable(){ + echo($this->getFighterTable($this->fighters, $this->rankings)); + } + + /** Echo logOutput */ + public function htmlLogOutput(){ + echo($this->getLogOutput($this->log)); + } + + //// + // saving and loading + //// + + /** load all active trainees into a id=>User assoc array */ + static private function getTrainees() { $traineeList = array_map( "User::fromDbArray", @@ -94,39 +113,34 @@ class PmElo return $traineeAssocArray; } - // load ranking from json file - public static function loadRankings() + /** load ranking from json file */ + static private function loadRankings() { return json_decode(file_get_contents(self::$pmeloJson)); } - // save a ranking to json file - public static function saveRankings(array $rankings) + /** save a ranking to json file */ + static private function saveRankings(array $rankings) { file_put_contents(self::$pmeloJson, json_encode($rankings)); } - // simple logger to a logging buffer - function var_log( - $variable, - string $prefix = null, - string $logChannel = "info" - ) { - if (!in_array($logChannel, ["info", "warning", "error"])) { - $logChannel = "info"; - } - $prefix = !empty($prefix) ? $prefix . ": " : ""; - $this->log[$logChannel][] = $prefix . var_export($variable, true); - } + //// + // member functions + //// - // create the ranking for the current session (load saved ranking from file, remove old trainees, add new trainees) - public function createRankings() + /** create the ranking for the current session + * + * - load saved ranking from file + * - remove old trainees + * - add new trainees + */ + private function createRankings() { // load the last state of the ranking $loadedRanking = self::loadRankings(); // check if the ranked trainees still are in training - // - the ranking with $cleanRanking = []; // - trainees that aren't currently in the ranking for later inserting $toBeInsertedTrainees = $this->trainees; @@ -186,6 +200,15 @@ class PmElo return $updatedRanking; } + /** promote a fighter + * + * Promotion means two fighter switch places + * + * $promoteeId (int>0) id to promote + * $promopteeRank (int>0) current rank of the one to be promoted + * $degradeeId (int>0) id to demote + * $degradeeRank (int>0) new rank of the promotee + */ private function promote( int $promoteeId, int $promoteeRank, @@ -212,17 +235,100 @@ class PmElo // do the actual switch $this->rankings[$promoteeRank] = $degradeeId; $this->rankings[$degradeeRank] = $promoteeId; - - $this->saveRankings($this->rankings); } } } // save the updated ranking $this->saveRankings($this->rankings); } - // promotion means switching the position with another user - // id-s would already be sufficient, rank is just for controlling - public static function htmlPromoteButton( + + //// + // helper for output generation + //// + + /** Assemble the Input form for the fighter selection + * + * $trainees (array(participo::user)) list of trainees that can be selected for fighting + * + * return fighterInputForm as html code + */ + static private function getFighterInputForm(array $trainees){ + $style = [ + 'classes'=>[ + 'input-field' => "input-field col s12" + ] + ]; + + $retHtml = + '
' + // selects have to be wrapped into an .input-field, limitation of materializeCss + .'
' + .''. + ''. + ''. + '
'. + '
'; + return $retHtml; + } + + /** Assemble the ranking table of the fighters + * + * $fighters (array(id=>participo::User)) list of fighters in the active round + * $ranking (array(rank=>id)) ranking of the current selected fighters + * + * return fighter ranking table as html code + */ + static private function getFighterTable(array $fighters, array $rankings){ + $retHtml = + ''. + ''. + ''; + if (!empty($fighters)) { + // cache the predecessor in the ranking for the promoting form + $lastOne = null; + foreach ($rankings as $rank => $id) { + if (array_key_exists($id, $fighters)) { + $fighter = $fighters[$id]; + $retHtml .= ''. + ''. + ''; + if (!is_null($lastOne)){ + $retHtml .= ''; + } + $retHtml .= ''; + $lastOne = ["id" => $fighter->getId(), "rank" => $rank]; + } + } + } + $retHtml .= + ''. + '
PlatzNameAufstieg
'.$rank.''.join(' ', [$fighter->getFirstName(), $fighter->getName()]).''.self::getPromoteButton( + $fighter->getId(),$rank, + $lastOne["id"],$lastOne["rank"] + ).'
'; + + return $retHtml; + } + + /** Assemble a Promote button + * + * $promoteeId (int>0) id to promote + * $promoteeRank (int>0) current rank of the promotee + * $degradeeId (int>0) id to demote + * $degradeeRank (int>0) rank of the to be demoted + */ + static private function getPromoteButton( int $promoteeId, int $promoteeRank, int $degradeeId, @@ -237,11 +343,60 @@ class PmElo ""; } - public $log = ["error" => [], "warning" => [], "info" => []]; + /** Assemble the log Output + * + * $log (array logLevel=>array(messages)) lists of log messages per logLevel + * + * return logOutput as html code + */ + private static function getLogOutput(array $log){ + $retHtml = + '
    '. + '
  • Logs

  • '; + foreach ($log as $logLevel => $messages) { + if (!empty($messages)) { + $retHtml .= + '
  • '. + '
      '. + '
    • '.$logLevel.'
    • '; + foreach ($messages as $message) { + $retHtml .= + '
    • '.$message.'
    • '; + } + $retHtml .= + '
    '. + '
  • '; + } + } + + return $retHtml; + } + + /** simple logger to a logging buffer */ + private function var_log( + $variable, + string $prefix = null, + string $logChannel = "info" + ) { + if (!in_array($logChannel, ["info", "warning", "error"])) { + $logChannel = "info"; + } + $prefix = !empty($prefix) ? $prefix . ": " : ""; + $this->log[$logChannel][] = $prefix . var_export($variable, true); + } + + //// + // member variables + //// + + /** current chosen trainees for fighting [id=>participo::User] */ public $fighters = null; + /** current trainees available for fighting as [id=>participo::User] */ public $trainees = null; - // list of id-s in the order of the current ranking + /** the current ranking as [rank=>id] */ public $rankings = null; + /** a place to save log messages for later output */ + public $log = ["error" => [], "warning" => [], "info" => []]; static $pmeloJson = "./pmeloRanking.json"; } diff --git a/homepage/participo/pmelo.php b/homepage/participo/pmelo.php index caf4e6e..1172690 100644 --- a/homepage/participo/pmelo.php +++ b/homepage/participo/pmelo.php @@ -39,83 +39,9 @@

    pmElo

    -
    -
    - - - -
    -
    - - - - - - - fighters)) { - // remember the predecessor for the promoting form - $lastOne = null; - foreach ($pmelo->rankings as $rank => $id) { - if (array_key_exists($id, $pmelo->fighters)) { - $fighter = $pmelo->fighters[$id]; - echo "" . - "" . - "" . - "" . - "" . - PHP_EOL; - $lastOne = ["id" => $fighter->getId(), "rank" => $rank]; - } - } - } ?> - -
    PlatzNameAufstieg
    " . - $rank . - "" . - $fighter->getFirstName() . - " " . - $fighter->getName() . - "" . - (!is_null($lastOne) - ? $pmelo->htmlPromoteButton( - $fighter->getId(), - $rank, - $lastOne["id"], - $lastOne["rank"] - ) - : "") . - "
    - -
      -
    • Logs

    • -log as $logLevel => $messages) { - if (!empty($messages)) { ?> -
    • -
        -
      • - -
      • - -
      • - -
      -
    • - - -
    + htmlFighterInputForm();?> + htmlFighterTable();?> + htmlLogOutput();?>
    From c4248aa2ea6da1369f7fd831add7b11fafdd8c09 Mon Sep 17 00:00:00 2001 From: marko Date: Sat, 24 Feb 2024 10:56:28 +0100 Subject: [PATCH 4/5] reformat, added trainee debug target --- homepage/participo/.vscode/launch.json | 14 +++- homepage/participo/testApi.py | 97 ++++++++++---------------- 2 files changed, 47 insertions(+), 64 deletions(-) diff --git a/homepage/participo/.vscode/launch.json b/homepage/participo/.vscode/launch.json index b2fddbf..35e98dd 100644 --- a/homepage/participo/.vscode/launch.json +++ b/homepage/participo/.vscode/launch.json @@ -15,6 +15,16 @@ "POST", "--input", "testShiai.json" ] - } - ] + }, + { + "name": "getTrainees", + "type": "python", + "request": "launch", + "program": "testApi.py", + "console": "integratedTerminal", + "justMyCode": true, + "args": [ + "GET", + "--endpoint", "trainees" ] + } ] } \ No newline at end of file diff --git a/homepage/participo/testApi.py b/homepage/participo/testApi.py index a43325c..9c8456b 100755 --- a/homepage/participo/testApi.py +++ b/homepage/participo/testApi.py @@ -5,49 +5,32 @@ import json class TestApi: + @staticmethod def __parse_arguments(): import argparse - argParser = argparse.ArgumentParser( - "testApi" - ) - argParser.add_argument( - "method", - choices=['GET', 'POST'] - ) - argParser.add_argument( - "--endpoint", - default="shiai" - ) - argParser.add_argument( - "--host", - default="cwsvjudo.bplaced.net" - ) - argParser.add_argument( - "--path", - default="participo/api" - ) - argParser.add_argument( - "--key", - default=None - ) - argParser.add_argument( - "--configFile", - type=argparse.FileType('r'), - default="testApi.config.yaml" - ) + argParser = argparse.ArgumentParser("testApi") + argParser.add_argument("method", choices=['GET', 'POST']) + argParser.add_argument("--endpoint", default="shiai") + argParser.add_argument("--host", default="cwsvjudo.bplaced.net") + argParser.add_argument("--path", default="participo/api") + argParser.add_argument("--key", default=None) + argParser.add_argument("--configFile", + type=argparse.FileType('r'), + default="testApi.config.yaml") _LOG_LEVEL = ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"] - argParser.add_argument( - "--logLevel", - choices=_LOG_LEVEL, - default="WARNING" - ) - argParser.add_argument( - "--input", "-i", - type=argparse.FileType("r"), - default="-" - ) + argParser.add_argument("--logLevel", + choices=_LOG_LEVEL, + default="WARNING") + argParser.add_argument("--input", + "-i", + type=argparse.FileType("r"), + default="-") + argParser.add_argument("--output", + "-o", + type=argparse.FileType("w"), + default="-") return argParser.parse_args() @@ -70,11 +53,8 @@ class TestApi: method=self.config.method, host=self.config.host, url="/".join([self.config.path, self.config.endpoint]), - headers={ - "Authorization": f"Basic {self.config.key}" - }, - input=load_json(self.config.input) - ) + headers={"Authorization": f"Basic {self.config.key}"}, + input=load_json(self.config.input)) def load_json(jsonFile): @@ -82,7 +62,9 @@ def load_json(jsonFile): with jsonFile as f: return json.load(f) + class apiCall: + @staticmethod def call( method: str, @@ -93,19 +75,15 @@ class apiCall: ) -> dict: import requests - if(method=="GET"): - r = requests.get( - url=f"http://{host}/{url}", - timeout=10, - headers=headers - ) - elif(method=="POST"): - r = requests.post( - json=input, - url=f"http://{host}/{url}", - timeout=10, - headers=headers - ) + if (method == "GET"): + r = requests.get(url=f"http://{host}/{url}", + timeout=10, + headers=headers) + elif (method == "POST"): + r = requests.post(json=input, + url=f"http://{host}/{url}", + timeout=10, + headers=headers) else: logging.error("This line should never been reached!") @@ -122,11 +100,6 @@ if __name__ == "__main__": response = testApi.apiCall() try: - print( - json.dumps( - response, - indent=2 - ) - ) + print(json.dumps(response, indent=2)) except Exception as e: logging.error(f"Exception {repr(e)} ({e}) while parsing json:") From 73d20dbe63cff0c38fc118fbbcb89cb1c71eb513 Mon Sep 17 00:00:00 2001 From: marko Date: Sat, 24 Feb 2024 11:57:50 +0100 Subject: [PATCH 5/5] newsletter kw 08 --- .../2022-02-24-Trainingsverlegung.md | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 infoZettelOrg/2022-02-24-Trainingsverlegung.md diff --git a/infoZettelOrg/2022-02-24-Trainingsverlegung.md b/infoZettelOrg/2022-02-24-Trainingsverlegung.md new file mode 100644 index 0000000..205294b --- /dev/null +++ b/infoZettelOrg/2022-02-24-Trainingsverlegung.md @@ -0,0 +1,56 @@ +--- +title: Trainingsverlegung am 1.3. +--- + +- [Verlegung des Trainingsortes am Freitag (01.03.2024)](#verlegung-des-trainingsortes-am-freitag-01032024) +- [Werbung in eigener Sache](#werbung-in-eigener-sache) + - [Sommerlager 20.6.- 25.6.2024](#sommerlager-206--2562024) + - [Schwimmen](#schwimmen) +- [Aktualisierung eMail](#aktualisierung-email) + + +## Verlegung des Trainingsortes am Freitag (01.03.2024) + +- Datum: 01.03.2024 +- Zeit: 16:00-18:00 Uhr alle +- Ort: [Gymnastikraum der Sachsenhalle][mapSachsenhalle] + +Am Freitag, dem 01.03.2024, werden wir unser Dojo den Karateka überlassen. Stattdessen weichen wir wieder mal in den [Gymnastikraum der Sachsenhalle][mapSachsenhalle] (Str. Usti nad Labem 275, 09119 Chemnitz) aus. + +Das Training der Großen wird diesmal nicht in der gewohnten Form stattfinden, stattdessen wird es einen Spieleabend geben: Jeder bringt ein kleines Spiel (vorzugsweise für die mehrere Teilnehmer und schnell zu erklären) und wir machen uns einen schönen, geselligen im Beratungsraum. + +Wer von den Großen nicht auf ganz auf das Judo verzichten möchte, kann gerne bei denKleinen schon mitmachen: Viele Leute (und vor allem viele verschiedene Gürtelfarben) und die große Halle wären die perfekte Gelegenheit für Seeungeheuer. + +## Werbung in eigener Sache + +### Sommerlager 20.6.- 25.6.2024 + +Auch im nächstes Jahr wollen wir wieder gemeinsam mit den Karateka ins Sommerlager fahren. Dieses Mal geht es vom 20.6.- 25.6.2024 ins Schullandheim Bautzen-Burk. + +Adresse: + +- Nimschützer Str. 10 +- 02625 Bautzen +- [Homepage des Schullandheimes Bautzen][schullandheimBautzen] + +Die Kosten belaufen sich diesmal auf 250,00 €. + +Die Plätze für die Judoka sind auf 10 begrenzt und 5 sind schon vergeben. Wer Interesse hat, kann sich bei mir melden. + +#### Schwimmen + +Erinnerung an unseren sonntäglichen Schwimmtreff: Jeden Sonntag 10:00 Uhr treffen wir uns am [Stadtbad Chemnitz (Mühlenstraße 27, 09111 Chemnitz)][stadtbad]. + +Es hat mich in letzter Zeit sehr gefreut nicht alleine schwimmen zu müssen und vielleicht hat der eine oder andere ja noch Lust darauf. + + +## Aktualisierung eMail + +Damit der NewsLetter ordentlich ankommt, hier mal die Bitte um Aktualisierung der eMail Adressen: Wer den NewsLetter an eine andere oder zusätzliche eMail haben möchte, soll mir das bitte mitteilen. Wenn jemand gar keinen NewsLetter bekommt, dann wahrscheinlich, weil ich die eMail Adresse nicht habe. Auch da die Bitte: Wer gerne den NewsLetter erhalten möchte, soll mir die Ziel Adresse mitteilen. + +Wenn das von den Eltern gewünscht ist, können auch die Kinder selber den NewsLetter mit erhalten. + + +MsG marko + +[stadtbad]: https://osm.org/go/0MIY_~XdV-