<commit_before><?php

/**
 * @package         Billing
 * @copyright       Copyright (C) 2012-2016 S.D.O.C. LTD. All rights reserved.
 * @license         GNU Affero General Public License Version 3; see LICENSE.txt
 */

/**
 * Billing Importer For The PP Threshold of a customer Plan.
 * Imports from Csv to mongo collection plans
 *
 * @package  Billrun
 * @since    4.0
 * @author <NAME>
 */
class Billrun_Importer_PPThreshold extends Billrun_Importer_Csv {

	protected $fieldsColumns = null;
	
	protected $thresholdTable = array();
	protected $cos;
	protected $ppID;
	
	public function __construct($options) {
		parent::__construct($options);
		$this->fields = Billrun_Factory::config()->getConfigValue('importer.PPThreshold.fields', array());
	}
	
	protected function getCollectionName() {
		return 'plans';
	}

	
	protected function getCOS($rowData) {
		$field = $this->fields['COS']['i'];
		$this->cos = $rowData[$field];
		return null;
	}
	
	protected function getPPId($rowData) {
		$this->ppID =  $rowData[$this->fields['PP_Id']['i']];
		return null;
	}
	
	protected function getMax($rowData) {
		$this->thresholdTable[$this->cos][$this->ppID] = $rowData[$this->fields['Max']['i']];
		return null;
	}
	
	public function save() {
		try {
			$error = '';
			$updateOptions = array(
				'multi' => true,
				'upsert' => false
			);
			$collectionName = $this->getCollectionName();
			$collection = Billrun_Factory::db()->getCollection($collectionName);
			
			$updateQuery = array();
			$findQuery = array("type" => "customer");
			
			$count = 0;
			$success = true;
			// GO through the list of COS values.
			foreach ($this->thresholdTable as $COS => $PP) {
				$findQuery['name'] = $COS;
				$updateQuery = array('$set' => array("pp_threshold" => $PP));
				
				$res = $collection->update($findQuery, $updateQuery,$updateOptions);
				$success = $res['ok'];
				if(!$success) {
					break;
				}
				Billrun_Factory::log("Inserted: " . $COS . " => " . print_r($PP,1));<commit_msg>Imported the threshold as negative values<commit_after><?php

/**
 * @package         Billing
 * @copyright       Copyright (C) 2012-2016 S.D.O.C. LTD. All rights reserved.
 * @license         GNU Affero General Public License Version 3; see LICENSE.txt
 */

/**
 * Billing Importer For The PP Threshold of a customer Plan.
 * Imports from Csv to mongo collection plans
 *
 * @package  Billrun
 * @since    4.0
 * @author <NAME>
 */
class Billrun_Importer_PPThreshold extends Billrun_Importer_Csv {

	protected $fieldsColumns = null;
	
	protected $thresholdTable = array();
	protected $cos;
	protected $ppID;
	
	public function __construct($options) {
		parent::__construct($options);
		$this->fields = Billrun_Factory::config()->getConfigValue('importer.PPThreshold.fields', array());
	}
	
	protected function getCollectionName() {
		return 'plans';
	}

	
	protected function getCOS($rowData) {
		$field = $this->fields['COS']['i'];
		$this->cos = $rowData[$field];
		return null;
	}
	
	protected function getPPId($rowData) {
		$this->ppID =  $rowData[$this->fields['PP_Id']['i']];
		return null;
	}
	
	protected function getMax($rowData) {
		$this->thresholdTable[$this->cos][$this->ppID] = (int)(($rowData[$this->fields['Max']['i']]) *-1);
		return null;
	}
	
	public function save() {
		try {
			$error = '';
			$updateOptions = array(
				'multi' => true,
				'upsert' => false
			);
			$collectionName = $this->getCollectionName();
			$collection = Billrun_Factory::db()->getCollection($collectionName);
			
			$updateQuery = array();
			$findQuery = array("type" => "customer");
			
			$count = 0;
			$success = true;
			// GO through the list of COS values.
			foreach ($this->thresholdTable as $COS => $PP) {
				$findQuery['name'] = $COS;
				$updateQuery = array('$set' => array("pp_threshold" => $PP));
				
				$res = $collection->update($findQuery, $updateQuery,$updateOptions);
				$success = $res['ok'];
				if(!$success) {
					break;
				}
				Billrun_Factory::log("Inserted: " . $COS . " => " . print_r($PP,1));
{'fraction_non_alphanumeric': 0.1691963174919134, 'fraction_numerical': 0.006718089076884797, 'mean_word_length': 3.6853146853146854, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 47, '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': '5094984', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1295, 'n_words': 297}