new things

This commit is contained in:
Dan Chadwick 2024-04-14 21:54:51 -07:00
parent 4eb7bf6220
commit 6ad2ed7b29
5 changed files with 39 additions and 16 deletions

View File

@ -7,5 +7,4 @@ const container = document.getElementById('recent-fights');
const root = createRoot(container);
root.render(<FightCard />);
// root.render(<FirstFunc />);
// root.render(<Table type="table-dark table-striped table" />);

View File

@ -184,23 +184,47 @@ private function extractValuesFromFields(int $id, array $field_names, string $pr
* This needs to be between 0-1
*/
private function normalizeData(array $data): array {
// @todo - this creates an issue where duration of fight is the largest number which isnt really correct
// and smaller duration would be better
//
$min = min(array_values($data));
$max = max(array_values($data));
$normalized = [];
foreach ($data as $key => $value) {
$norm_val = 0;
if ($max - $min == 0) {
$normalized[$key] = $norm_val;
}
else {
$norm_val = ($value - $min) / ($max - $min);
$normalized[$key] = $norm_val;
}
$value = (float) $value;
$normalized[$key] = $this->convertToDecimal($value);
/* $norm_val = 0; */
/* if ($max - $min == 0) { */
/* $normalized[$key] = $norm_val; */
/* } */
/* else { */
/* $norm_val = ($value - $min) / ($max - $min); */
/* $normalized[$key] = $norm_val; */
/* } */
}
return $normalized;
}
public function convertToDecimal(float $input) {
$output = 0;
if ($input > 0 && $input <= 1) {
$output = $input / 100;
}
elseif ($input > 1 && $input < 10) {
$output = $input / 100;
}
elseif ($input > 10 && $input < 100) {
$output = $input / 1000;
}
elseif ($input > 100 && $input < 1000) {
$output = $input / 10000;
}
return $output;
}
/**
* Gets the trained neural network.
*/

View File

@ -34,15 +34,16 @@ public static function create(ContainerInterface $container) {
public function getRecentFights() {
$query = $this->entityTypeManager->getStorage('node')->getQuery();
$query->accessCheck(TRUE);
$query->condition('type', 'fight')->sort('created', 'DESC')->sort('nid', 'DESC');
$query->range(0, 13);
$query->condition('type', 'fight')->sort('field_fight_date', 'DESC');
$query->range(0, 15);
$nids = $query->execute();
$all_fights = Node::loadMultiple($nids);
$fights = [];
foreach ($all_fights as $fight) {
$f1 = Node::load($fight->field_fighter_one->target_id);
$f2 = Node::load($fight->field_fighter_two->target_id);
$result = Node::load($fight->field_result->target_id);
/* $result = Node::load($fight->field_result->target_id) ?? FALSE; */
$alias = \Drupal::service('path_alias.manager')->getAliasByPath("/" . $fight->toUrl()->getInternalPath());
if ($f1 && $f2) {
@ -57,7 +58,6 @@ public function getRecentFights() {
'fighter_one_image' => $f1_pic_url,
'fighter_two' => $f2->getTitle(),
'fighter_two_image' => $f2_pic_url,
'result' => $result->getTitle(),
'url' => $alias
];
}

View File

@ -178,7 +178,6 @@ public function loopThroughFighterPages($base_url): void {
* Extract fighters from an html string.
*/
public function extractFighters(string $input): void {
// @todo REBUILD THIS NOW!!
$fighter_list = [];
$crawler = new Crawler($input);
$athlete_flipcards = $crawler->filter('.c-listing-athlete-flipcard');

View File

@ -4,9 +4,10 @@ document.addEventListener('readystatechange', event => {
highlightFightHistory();
let train = false;
if (train) {
trainTheBrain();
setTimeout(() => {
trainTheBrain();
}, 5000);
}
}
}, { passive: true });