<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
 */

/**
 * Udata Generator class
 *
 * @package  Models
 * @since    2.1
 */

class Generator_Sasn extends Billrun_Generator_ConfigurableCDRAggregationCsv {
	
	static $type = 'sasn';
	
	protected $data = null;
	protected $grouping = array();
	protected $match = array();
	protected $translations = array();
	protected $fieldDefinitions =  array();
	protected $preProject = array();
	protected $unwind = array();
	
	
	public function generate() {
		$fileData = $this->getNextFileData();
		$this->writeRows();
		$this->logDB($fileData);
	}
	
	public function getNextFileData() {
		$seq = $this->getNextSequenceData(static::$type);
		
		return array( 'seq' => $seq , 'filename' =>  'SASN_PREP_'.sprintf('%05.5d',$seq).'_'.date('YmdHis') , 'source' => static::$type);
	}
	
	//--------------------------------------------  Protected ------------------------------------------------

	protected function writeRows() {
		foreach($this->data as $line) {
			$this->writeRowToFile($this->translateCdrFields($line, $this->translations), $this->fieldDefinitions);
			$this->markLines($line['stamps']);
		}
	}
	
	// ------------------------------------ Helpers -----------------------------------------
	// 
	
	
	protected function transalteDuration($value, $parameters, $line) {
		return date($parameters['date_format'], $line[$parameters['end_field']]->sec - $line[$parameters['start_field']]->sec);
	}
	

	protected function transalteRatingGroup($value, $mapping, $line) {<commit_msg>Split  the  SASN  lines  to maximum 1 GB<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
 */

/**
 * Udata Generator class
 *
 * @package  Models
 * @since    2.1
 */

class Generator_Sasn extends Billrun_Generator_ConfigurableCDRAggregationCsv {
	
	static $type = 'sasn';
	static $ONE_GB = 1024*1024*1024;
	
	protected $data = null;
	protected $grouping = array();
	protected $match = array();
	protected $translations = array();
	protected $fieldDefinitions =  array();
	protected $preProject = array();
	protected $unwind = array();
	

	
	
	public function generate() {
		$fileData = $this->getNextFileData();
		$this->writeRows();
		$this->logDB($fileData);
	}
	
	public function getNextFileData() {
		$seq = $this->getNextSequenceData(static::$type);
		
		return array( 'seq' => $seq , 'filename' =>  'SASN_PREP_'.sprintf('%05.5d',$seq).'_'.date('YmdHis') , 'source' => static::$type);
	}
	
	//--------------------------------------------  Protected ------------------------------------------------

	protected function writeRows() {
		foreach($this->data as $line) {
			if($line['data_volume_gprs_downlink'] > static::$ONE_GB) {
				while($line['data_volume_gprs_downlink'] > 0) {
					$brokenLine = $line->getRawData();
					$brokenLine['orig_data_volume_gprs_downlink'] = $brokenLine['orig_data_volume_gprs_downlink'] > 0 
																				? ($line['orig_data_volume_gprs_downlink'] > static::$ONE_GB ? static::$ONE_GB  :  $line['orig_data_volume_gprs_downlink']) 
																				: 0;
					$brokenLine['data_volume_gprs_downlink'] =  $line['data_volume_gprs_downlink'] > static::$ONE_GB ? static::$ONE_GB  :  $line['data_volume_gprs_downlink'];
					$this->writeRowToFile($this->translateCdrFields($brokenLine, $this->translations), $this->fieldDefinitions);
					$line['record_opening_time'] = new MongoDate($line['record_opening_time']->sec+1);
					$line['data_volume_gprs_downlink'] -= static::$ONE_GB;
					$line['orig_data_volume_gprs_downlink'] -= static::$ONE_GB;
				}
				
			} else {
				$this->writeRowToFile($this->translateCdrFields($line, $this->translations), $this->fieldDefinitions);
			}
				$this->markLines($line['stamps']);
			
		}
	}
	
	// ------------------------------------ Helpers -----------------------------------------
	// 
	
	
	protected function transalteDuration($value, $parameters, $line) {
		return date($parameters['date_format'], $line[$parameters['end_field']]->sec - $line[$parameters['start_field']]->sec);
	}
	

	protected function transalteRatingGroup($value, $mapping, $line) {
{'fraction_non_alphanumeric': 0.22887724891824185, 'fraction_numerical': 0.010248235026189934, 'mean_word_length': 2.9460916442048517, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 44, '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': '6186401', 'n_tokens_mistral': 1506, 'n_tokens_neox': 1348, 'n_words': 246}