new things
This commit is contained in:
parent
4eb7bf6220
commit
6ad2ed7b29
@ -7,5 +7,4 @@ const container = document.getElementById('recent-fights');
|
|||||||
const root = createRoot(container);
|
const root = createRoot(container);
|
||||||
|
|
||||||
root.render(<FightCard />);
|
root.render(<FightCard />);
|
||||||
// root.render(<FirstFunc />);
|
|
||||||
// root.render(<Table type="table-dark table-striped table" />);
|
// root.render(<Table type="table-dark table-striped table" />);
|
||||||
|
|||||||
@ -184,23 +184,47 @@ private function extractValuesFromFields(int $id, array $field_names, string $pr
|
|||||||
* This needs to be between 0-1
|
* This needs to be between 0-1
|
||||||
*/
|
*/
|
||||||
private function normalizeData(array $data): array {
|
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));
|
$min = min(array_values($data));
|
||||||
$max = max(array_values($data));
|
$max = max(array_values($data));
|
||||||
$normalized = [];
|
$normalized = [];
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
$norm_val = 0;
|
|
||||||
if ($max - $min == 0) {
|
$value = (float) $value;
|
||||||
$normalized[$key] = $norm_val;
|
$normalized[$key] = $this->convertToDecimal($value);
|
||||||
}
|
/* $norm_val = 0; */
|
||||||
else {
|
/* if ($max - $min == 0) { */
|
||||||
$norm_val = ($value - $min) / ($max - $min);
|
/* $normalized[$key] = $norm_val; */
|
||||||
$normalized[$key] = $norm_val;
|
/* } */
|
||||||
}
|
/* else { */
|
||||||
|
/* $norm_val = ($value - $min) / ($max - $min); */
|
||||||
|
/* $normalized[$key] = $norm_val; */
|
||||||
|
/* } */
|
||||||
}
|
}
|
||||||
|
|
||||||
return $normalized;
|
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.
|
* Gets the trained neural network.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -34,15 +34,16 @@ public static function create(ContainerInterface $container) {
|
|||||||
public function getRecentFights() {
|
public function getRecentFights() {
|
||||||
$query = $this->entityTypeManager->getStorage('node')->getQuery();
|
$query = $this->entityTypeManager->getStorage('node')->getQuery();
|
||||||
$query->accessCheck(TRUE);
|
$query->accessCheck(TRUE);
|
||||||
$query->condition('type', 'fight')->sort('created', 'DESC')->sort('nid', 'DESC');
|
$query->condition('type', 'fight')->sort('field_fight_date', 'DESC');
|
||||||
$query->range(0, 13);
|
$query->range(0, 15);
|
||||||
$nids = $query->execute();
|
$nids = $query->execute();
|
||||||
$all_fights = Node::loadMultiple($nids);
|
$all_fights = Node::loadMultiple($nids);
|
||||||
$fights = [];
|
$fights = [];
|
||||||
foreach ($all_fights as $fight) {
|
foreach ($all_fights as $fight) {
|
||||||
$f1 = Node::load($fight->field_fighter_one->target_id);
|
$f1 = Node::load($fight->field_fighter_one->target_id);
|
||||||
$f2 = Node::load($fight->field_fighter_two->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());
|
$alias = \Drupal::service('path_alias.manager')->getAliasByPath("/" . $fight->toUrl()->getInternalPath());
|
||||||
if ($f1 && $f2) {
|
if ($f1 && $f2) {
|
||||||
|
|
||||||
@ -57,7 +58,6 @@ public function getRecentFights() {
|
|||||||
'fighter_one_image' => $f1_pic_url,
|
'fighter_one_image' => $f1_pic_url,
|
||||||
'fighter_two' => $f2->getTitle(),
|
'fighter_two' => $f2->getTitle(),
|
||||||
'fighter_two_image' => $f2_pic_url,
|
'fighter_two_image' => $f2_pic_url,
|
||||||
'result' => $result->getTitle(),
|
|
||||||
'url' => $alias
|
'url' => $alias
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -178,7 +178,6 @@ public function loopThroughFighterPages($base_url): void {
|
|||||||
* Extract fighters from an html string.
|
* Extract fighters from an html string.
|
||||||
*/
|
*/
|
||||||
public function extractFighters(string $input): void {
|
public function extractFighters(string $input): void {
|
||||||
// @todo REBUILD THIS NOW!!
|
|
||||||
$fighter_list = [];
|
$fighter_list = [];
|
||||||
$crawler = new Crawler($input);
|
$crawler = new Crawler($input);
|
||||||
$athlete_flipcards = $crawler->filter('.c-listing-athlete-flipcard');
|
$athlete_flipcards = $crawler->filter('.c-listing-athlete-flipcard');
|
||||||
|
|||||||
@ -4,9 +4,10 @@ document.addEventListener('readystatechange', event => {
|
|||||||
highlightFightHistory();
|
highlightFightHistory();
|
||||||
let train = false;
|
let train = false;
|
||||||
if (train) {
|
if (train) {
|
||||||
|
setTimeout(() => {
|
||||||
trainTheBrain();
|
trainTheBrain();
|
||||||
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}, { passive: true });
|
}, { passive: true });
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user