<commit_before><?php

namespace NatureQuizzer\Database\Model;


use Nette\InvalidArgumentException;
use Nette\Utils\Arrays;
use Nette\Utils\DateTime;

class OrganismCommonness extends Table
{

	public function getMaximum()
	{
		$output = $this->getConnection()->query('
			SELECT MAX(value) FROM organism_commonness
		')->fetchField();
		if ($output === FALSE) {
			return 1; // fallback for the case where there are no data
		} else {
			return $output;
		}
	}

	public function setValue($organismId, $value)
	{
		$row = $this->getTable()->where('id_organism = ?', $organismId)->fetch();
		if ($row === FALSE) {
			$this->getTable()->insert(['id_organism' => $organismId, 'value' => (int) $value]);
		} else {
			$this->getTable()->where('id_organism = ?', $organismId)->update(['value' => $value]);
		}
	}
}
<commit_msg>Hotfix for unexpected division by zero when there are no data in database.<commit_after><?php

namespace NatureQuizzer\Database\Model;


use Nette\InvalidArgumentException;
use Nette\Utils\Arrays;
use Nette\Utils\DateTime;

class OrganismCommonness extends Table
{

	public function getMaximum()
	{
		$output = $this->getConnection()->query('
			SELECT MAX(value) FROM organism_commonness
		')->fetchField();
		if ($output === FALSE || $output == NULL) {
			return 1; // fallback for the case where there are no data
		} else {
			return $output;
		}
	}

	public function setValue($organismId, $value)
	{
		$row = $this->getTable()->where('id_organism = ?', $organismId)->fetch();
		if ($row === FALSE) {
			$this->getTable()->insert(['id_organism' => $organismId, 'value' => (int) $value]);
		} else {
			$this->getTable()->where('id_organism = ?', $organismId)->update(['value' => $value]);
		}
	}
}

{'fraction_non_alphanumeric': 0.1751740139211137, 'fraction_numerical': 0.001160092807424594, 'mean_word_length': 4.4245283018867925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '665744', 'n_tokens_mistral': 611, 'n_tokens_neox': 562, 'n_words': 132}