<commit_before><?php

use Pheal\Pheal;

final class miscUtils {

	const TIER1COST = 33000;
	const TIER2COST = 29000;
	const TIER3COST = 25000;

	static function computeCostPerDays( $memberCount, $days )
	{
		if( $memberCount == 0 )
		{
			return 0;
		}

		$total = 25420*$memberCount + 283650;
		return $total*$days;
	}


	static function parseIngameSigExport( $string )
	{
		$resultingSigs = array();

		$lines = explode("\n", $string);
		foreach( $lines as $line )
		{
			$rawdata = explode("\t", $line);
			if( count($rawdata) < 2 )
			{
				continue;
			}

			$sigData = array('type' => 'none', 'sig' => '', 'siteID' => 0);

			$matches = array();

			/*eliminate junk items, :CCP: sometimes
			inject mix spaces/tabs that cause the tab split to not be clean */
			$data = array();
			foreach($rawdata as $item)
			{
				$item = trim($item);
				if( empty($item) )
					continue;
				$data[] = $item;
			}

			foreach($data as $k => $item)
			{
				$item = trim($item);
				if( empty($item) )
					continue;

				preg_match("/^([a-zA-Z]{3})-([0-9]{3})$/", $item, $matches );
				if( count($matches) == 3 )	//SIG-NUM, SIG, NUM
				{
					$sigData['sig'] = $matches[1];
					continue;
				}

				$regex = "/^(".__('Wormhole')."|".__('Data Site')."|".__('Gas Site')."|".__('Relic Site')."|".__('Ore Site')."|".__('Combat Site').")$/";

				preg_match($regex, $item, $matches );
				if( count($matches) == 2 )
				{
					switch( $matches[1] )
					{
						case __('Wormhole'):
							$sigData['type'] = 'wh';
							$sigData['siteID'] = 0;
							break;
						case __('Data Site'):
							$sigData['type'] = 'data';
							$sigData['siteID'] = self::siteIDLookupByName( $data[$k+1], $sigData['type'] );
							break;
						case __('Gas Site'):
							$sigData['type'] = 'gas';
							$sigData['siteID'] = self::siteIDLookupByName( $data[$k+1], $sigData['type'] );
							break;
						case __('Relic Site'):
							$sigData['type'] = 'relic';
							$sigData['siteID'] = self::siteIDLookupByName( $data[$k+1], $sigData['type'] );
							break;
						case __('Ore Site'):
							$sigData['type'] = 'ore';
							$sigData['siteID'] = self::siteIDLookupByName( $data[$k+1], $sigData['type'] );
							break;
						case __('Combat Site'):
							$sigData['type'] = 'anomaly';
							$sigData['siteID'] = self::siteIDLookupByName( $data[$k+1], $sigData['type'] );
							break;
					}
					continue;
				}
			}

			if( $sigData['sig'] != '' )
			{
				$resultingSigs[] = $sigData;
			}
		}
		return $resultingSigs;
	}

	static function siteIDLookupByName( $name, $type )
	{
		$sites = DB::query(Database::SELECT, "SELECT * FROM sites WHERE type = :type")
											->param(':type', $type)
					  ->execute()->as_array();

		foreach( $sites as $site )
		{
			if( __($site['name']) == $name )
			{
				return $site['id'];
			}
		}

		return 0;
	}
	
	static function isWspaceID($id)
	{
		if( $id >= 31000000 )
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	static function searchEVEEntityByName( $names, $type = 'corp' )
	{
		if( $type == 'corp' )
		{
			$nameArray = explode(',', $names);
			$queryArray = array();
			foreach($nameArray as $name)
			{
				$name = trim($name);
				if(!empty($name))
				{
					$queryArray[] = "corporationName LIKE ".Database::instance()->escape("%".$name."%");
				}
			}
			$querySQL = implode(" OR ", $queryArray);
			$results = DB::query(Database::SELECT, 'SELECT * FROM corporations WHERE '.$querySQL)->execute()->as_array();

			if( count( $results ) )
			{
				return $results;
			}
		}

		PhealHelper::configure();
		$pheal = new Pheal(null,null,'eve');

		$result = $pheal->CharacterID( array( 'names' => $names ) )->toArray();
		$potentialCorps = $result['result']['characters'];

		if( $type == 'corp' )
		{
			$pheal->scope = 'corp';
		}
		else
		{
			$pheal->scope = 'eve';
		}

		$resultArray = array();<commit_msg>Reduce corporation DB wildcard search to just one sided LIKE<commit_after><?php

use Pheal\Pheal;

final class miscUtils {

	const TIER1COST = 33000;
	const TIER2COST = 29000;
	const TIER3COST = 25000;

	static function computeCostPerDays( $memberCount, $days )
	{
		if( $memberCount == 0 )
		{
			return 0;
		}

		$total = 25420*$memberCount + 283650;
		return $total*$days;
	}


	static function parseIngameSigExport( $string )
	{
		$resultingSigs = array();

		$lines = explode("\n", $string);
		foreach( $lines as $line )
		{
			$rawdata = explode("\t", $line);
			if( count($rawdata) < 2 )
			{
				continue;
			}

			$sigData = array('type' => 'none', 'sig' => '', 'siteID' => 0);

			$matches = array();

			/*eliminate junk items, :CCP: sometimes
			inject mix spaces/tabs that cause the tab split to not be clean */
			$data = array();
			foreach($rawdata as $item)
			{
				$item = trim($item);
				if( empty($item) )
					continue;
				$data[] = $item;
			}

			foreach($data as $k => $item)
			{
				$item = trim($item);
				if( empty($item) )
					continue;

				preg_match("/^([a-zA-Z]{3})-([0-9]{3})$/", $item, $matches );
				if( count($matches) == 3 )	//SIG-NUM, SIG, NUM
				{
					$sigData['sig'] = $matches[1];
					continue;
				}

				$regex = "/^(".__('Wormhole')."|".__('Data Site')."|".__('Gas Site')."|".__('Relic Site')."|".__('Ore Site')."|".__('Combat Site').")$/";

				preg_match($regex, $item, $matches );
				if( count($matches) == 2 )
				{
					switch( $matches[1] )
					{
						case __('Wormhole'):
							$sigData['type'] = 'wh';
							$sigData['siteID'] = 0;
							break;
						case __('Data Site'):
							$sigData['type'] = 'data';
							$sigData['siteID'] = self::siteIDLookupByName( $data[$k+1], $sigData['type'] );
							break;
						case __('Gas Site'):
							$sigData['type'] = 'gas';
							$sigData['siteID'] = self::siteIDLookupByName( $data[$k+1], $sigData['type'] );
							break;
						case __('Relic Site'):
							$sigData['type'] = 'relic';
							$sigData['siteID'] = self::siteIDLookupByName( $data[$k+1], $sigData['type'] );
							break;
						case __('Ore Site'):
							$sigData['type'] = 'ore';
							$sigData['siteID'] = self::siteIDLookupByName( $data[$k+1], $sigData['type'] );
							break;
						case __('Combat Site'):
							$sigData['type'] = 'anomaly';
							$sigData['siteID'] = self::siteIDLookupByName( $data[$k+1], $sigData['type'] );
							break;
					}
					continue;
				}
			}

			if( $sigData['sig'] != '' )
			{
				$resultingSigs[] = $sigData;
			}
		}
		return $resultingSigs;
	}

	static function siteIDLookupByName( $name, $type )
	{
		$sites = DB::query(Database::SELECT, "SELECT * FROM sites WHERE type = :type")
											->param(':type', $type)
					  ->execute()->as_array();

		foreach( $sites as $site )
		{
			if( __($site['name']) == $name )
			{
				return $site['id'];
			}
		}

		return 0;
	}
	
	static function isWspaceID($id)
	{
		if( $id >= 31000000 )
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	static function searchEVEEntityByName( $names, $type = 'corp' )
	{
		if( $type == 'corp' )
		{
			$nameArray = explode(',', $names);
			$queryArray = array();
			foreach($nameArray as $name)
			{
				$name = trim($name);
				if(!empty($name))
				{
					$queryArray[] = "corporationName LIKE ".Database::instance()->escape($name."%");
				}
			}
			$querySQL = implode(" OR ", $queryArray);
			$results = DB::query(Database::SELECT, 'SELECT * FROM corporations WHERE '.$querySQL)->execute()->as_array();

			if( count( $results ) )
			{
				return $results;
			}
		}

		PhealHelper::configure();
		$pheal = new Pheal(null,null,'eve');

		$result = $pheal->CharacterID( array( 'names' => $names ) )->toArray();
		$potentialCorps = $result['result']['characters'];

		if( $type == 'corp' )
		{
			$pheal->scope = 'corp';
		}
		else
		{
			$pheal->scope = 'eve';
		}

		$resultArray = array();
{'fraction_non_alphanumeric': 0.20948464207685388, 'fraction_numerical': 0.014394036756201002, 'mean_word_length': 2.850569025235032, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, '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': '5303708', 'n_tokens_mistral': 3724, 'n_tokens_neox': 2850, 'n_words': 582}