<commit_before><?php

namespace models;

class StatisticsDaoImpl implements \models\StatisticsDao {

	public function __construct() {
		if (!\F3::exists('db')) {
			\F3::set('db', new \DB\SQL(
				'mysql:host=' . \F3::get('db_host') . ';port=' . \F3::get('db_port') . ';dbname=' . \F3::get('db_database'),
				\F3::get('db_username'),
				\F3::get('db_password'),
				[\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]
			));
		}
	}

	/**
	 * @see \models\StatisticsDao#readStatistics()
	 */
	function readStatistics() {
		$query = "SELECT rf.value,
						 COUNT(rf.fk_registration) AS registrations
				  FROM " . \F3::get('db_table_prefix') . "registration_fields rf
				  WHERE rf.name = 'home-club'
				  GROUP BY rf.value
				  ORDER BY registrations DESC,
				  		   rf.value";
		$result = \F3::get('db')->exec($query);

		$stats = ['registrations-by-club' => []];
		foreach ($result as $row) {
			$stats['registrations-by-club'][] = (object)[
				'name' => json_decode($row['value']),
				'count' => $row['registrations'],
			];
		}
		return $stats;
	}

}
<commit_msg>Method to extract officers registered by club<commit_after><?php

namespace models;

class StatisticsDaoImpl implements \models\StatisticsDao {

	public function __construct() {
		if (!\F3::exists('db')) {
			\F3::set('db', new \DB\SQL(
				'mysql:host=' . \F3::get('db_host') . ';port=' . \F3::get('db_port') . ';dbname=' . \F3::get('db_database'),
				\F3::get('db_username'),
				\F3::get('db_password'),
				[\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]
			));
		}
	}

	/**
	 * @see \models\StatisticsDao#readStatistics()
	 */
	function readStatistics() {
		$query = "SELECT rf.value,
						 COUNT(rf.fk_registration) AS registrations
				  FROM " . \F3::get('db_table_prefix') . "registration_fields rf
				  WHERE rf.name = 'home-club'
				  GROUP BY rf.value
				  ORDER BY registrations DESC,
				  		   rf.value";
		$result = \F3::get('db')->exec($query);

		$stats = ['registrations-by-club' => []];
		foreach ($result as $row) {
			$stats['registrations-by-club'][] = (object)[
				'name' => json_decode($row['value']),
				'count' => $row['registrations'],
			];
		}
		return $stats;
	}

	function readOfficersByClub() {
		$query = "SELECT rf1.value AS club,
						 COUNT(rf2.fk_registration) AS officers,
						 GROUP_CONCAT(rf2.value SEPARATOR \"|\") AS positions
				  FROM " . \F3::get('db_table_prefix') . "registration_fields rf1
				  LEFT JOIN " . \F3::get('db_table_prefix') . "registration_fields rf2
					ON rf1.fk_registration = rf2.fk_registration
					AND rf2.name = 'exec-position'
					AND rf2.value <> '\"none\"'
				  WHERE rf1.name = 'home-club'
				  GROUP BY rf1.value
				  ORDER BY rf1.value";
		$result = \F3::get('db')->exec($query);

		$stats = [];
		foreach ($result as $row) {
			$stats[] = (object)[
				'name' => json_decode($row['club']),
				'count' => $row['officers'],
				'positions' => array_map(function ($item) {
					return json_decode($item);
				}, explode("|", $row['positions'])),
			];
		}
		return $stats;
	}

}

{'fraction_non_alphanumeric': 0.19717384160368057, 'fraction_numerical': 0.010844561288202431, 'mean_word_length': 3.2752808988764044, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 18, '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': '1985315', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1106, 'n_words': 201}