<commit_before><?php namespace App\Console\Commands\Loggers;

use App\Contracts\HTTP;
use App\Contracts\Inverter;

class PVOutputLogger {
	
	/*
	|--------------------------------------------------------------------------
	| PVOutput Logger
	|--------------------------------------------------------------------------
	|
	| Sends inverter measurements to the PVOutput API.
	|
	*/

	/**
	 * The PVOutput host.
	 *
	 * @const string
	 */
	const PVOUTPUT_HOST = 'http://pvoutput.org';

	/**
	 * The URI to the PVOutput Status Service.
	 *
	 * @const string
	 */
	const STATUS_URI = '/service/r2/addstatus.jsp';

	/**
	 * The HTTP service.
	 *
	 * @var App\Contracts\HTTP
	 */
	protected $http;

	/**
	 * The inverter.
	 *
	 * @var App\Contracts\Inverter
	 */
	protected $inverter;

	/**
	 * The PVOutput system ID.
	 *
	 * @var int
	 */
	protected $sid;

	/**
	 * The PVOutput API key.
	 *
	 * @var string
	 */
	protected $api_key;

	/**
	 * Create a new PVOutput Logger instance.
	 *
	 * @param  App\Contracts\HTTP      $http;
	 * @param  App\Contracts\Inverter  $inverter;
	 * @return void
	 */
	public function __construct(HTTP $http, Inverter $inverter)
	{
		$this->http     = $http;
		$this->inverter = $inverter;

		$this->sid     = env('PVOUTPUT_SID');
		$this->api_key = env('PVOUTPUT_API_KEY');
	}

	/**
	 * Update PVOutput with a given set of measurements at a certain time.
	 *
	 * @param  int  $timestamp
	 * @param  int  $generation
	 * @param  int  $ac_power
	 * @param  int  $dc_voltage
	 * @return void
	 */
	public function update_with($timestamp, $generation, $ac_power, $dc_voltage)
	{
		$headers = [
			"X-Pvoutput-Apikey: {$this->api_key}",
			"X-Pvoutput-SystemId: {$this->sid}"
		];

		$status = [
			'd'  => date('Ymd', $timestamp),
			't'  => date('H:i', $timestamp),
			'v1' => $generation,
			'v2' => $ac_power,
			'v6' => $dc_voltage
		];

		$this->http->post(self::PVOUTPUT_HOST, self::STATUS_URI, $status, $headers);
	}

	/**
	 * Update PVOutput with the current measurements.
	 *
	 * @return void
	 */
	public function update()
	{
		$measurements = $this->inverter->measurements();
		$timestamp = time();

		$generation = $measurements['generation'];
		$ac_power   = $measurements['ac_power'];
		$dc_voltage = $measurements['dc_voltage'];

		$this->update_with($timestamp, $generation, $ac_power, $dc_voltage);
	}

}

?><commit_msg>Check if PVOutput was fully configured.<commit_after><?php namespace App\Console\Commands\Loggers;

use App\Contracts\HTTP;
use App\Contracts\Inverter;

class PVOutputLogger {
	
	/*
	|--------------------------------------------------------------------------
	| PVOutput Logger
	|--------------------------------------------------------------------------
	|
	| Sends inverter measurements to the PVOutput API.
	|
	*/

	/**
	 * The PVOutput host.
	 *
	 * @const string
	 */
	const PVOUTPUT_HOST = 'http://pvoutput.org';

	/**
	 * The URI to the PVOutput Status Service.
	 *
	 * @const string
	 */
	const STATUS_URI = '/service/r2/addstatus.jsp';

	/**
	 * The HTTP service.
	 *
	 * @var App\Contracts\HTTP
	 */
	protected $http;

	/**
	 * The inverter.
	 *
	 * @var App\Contracts\Inverter
	 */
	protected $inverter;

	/**
	 * The PVOutput system ID.
	 *
	 * @var int
	 */
	protected $sid;

	/**
	 * The PVOutput API key.
	 *
	 * @var string
	 */
	protected $api_key;

	/**
	 * Create a new PVOutput Logger instance.
	 *
	 * @param  App\Contracts\HTTP      $http;
	 * @param  App\Contracts\Inverter  $inverter;
	 * @return void
	 */
	public function __construct(HTTP $http, Inverter $inverter)
	{
		$this->http     = $http;
		$this->inverter = $inverter;

		$this->sid     = env('PVOUTPUT_SID');
		$this->api_key = env('PVOUTPUT_API_KEY');
	}

	/**
	 * Check if PVOutput is fully configured.
	 *
	 * @return boolean
	 */
	protected function is_configured()
	{
		if ($this->sid && $this->api_key) {
			return true;
		}

		return false;
	}

	/**
	 * Update PVOutput with a given set of measurements at a certain time.
	 *
	 * @param  int  $timestamp
	 * @param  int  $generation
	 * @param  int  $ac_power
	 * @param  int  $dc_voltage
	 * @return void
	 */
	public function update_with($timestamp, $generation, $ac_power, $dc_voltage)
	{
		if ($this->is_configured()) {

			$headers = [
				"X-Pvoutput-Apikey: {$this->api_key}",
				"X-Pvoutput-SystemId: {$this->sid}"
			];

			$status = [
				'd'  => date('Ymd', $timestamp),
				't'  => date('H:i', $timestamp),
				'v1' => $generation,
				'v2' => $ac_power,
				'v6' => $dc_voltage
			];

			$this->http->post(self::PVOUTPUT_HOST, self::STATUS_URI, $status, $headers);

		}
	}

	/**
	 * Update PVOutput with the current measurements.
	 *
	 * @return void
	 */
	public function update()
	{
		if ($this->is_configured()) {

			$measurements = $this->inverter->measurements();
			$timestamp = time();

			$generation = $measurements['generation'];
			$ac_power   = $measurements['ac_power'];
			$dc_voltage = $measurements['dc_voltage'];

			$this->update_with($timestamp, $generation, $ac_power, $dc_voltage);

		}
	}

}

?>
{'fraction_non_alphanumeric': 0.21279554937413073, 'fraction_numerical': 0.0015895092390224518, 'mean_word_length': 2.3807924781732708, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '970351', 'n_tokens_mistral': 1932, 'n_tokens_neox': 1660, 'n_words': 375}