<commit_before><?php

namespace Lacroix\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="production_lines")
 */
class ProductionLine {
  /**
   * @ORM\Id
   * @ORM\Column(type="integer");
   * @ORM\GeneratedValue(strategy="AUTO");
   */
  protected $id;

  /**
   * @ORM\Column(type="string")
   */
  protected $name;

  /**
   * @ORM\Column(type="float")
   */
  protected $speed_adjustment;

  /**
   * @ORM\ManyToOne(targetEntity="Room", fetch="LAZY")
   * @ORM\JoinColumn(name="room_id", referencedColumnName="id")
   */
  protected $room;

  protected $_data_entry_repository;
  protected $_translator;

  // It is not a wise idea to add readings referencne here; as long as
  // array  reference  materializes  when accessed,  this  means  that
  // Doctrine would attempt  to read the complete entry  history for a
  // production line; use DataEntry  repository to access the requried
  // history subset instead

  public function getRoomName() {
    $room = $this->getRoom();
    if (!$room) { 
      return null; 
    };

    return $room->getName();
  }

  public function getLastReading() {
    return $this->getDataEntryRepository()->getLastReadingForLine($this);
  }

  public function getLastProductName() {
    $reading = $this->getLastReading();
    return $reading ? $reading->getProductName() : $this->getTranslator()->translate('N/A');
  }

  public function getLastProductId() {
    $reading = $this->getLastReading();
    return $reading ? $reading->getProductId() : null;
  }

  public function getLastEmployees() {
    $reading = $this->getLastReading();
    return $reading ? $reading->getEmployees() : $this->getTranslator()->translate('N/A');
  }

  public function getLastSpeed() {
    $reading = $this->getLastReading();
    return $reading ? $reading->getSpeed() : $this->getTranslator()->translate('N/A');
  }

  public function getLastTargetProductivity() {
    $reading = $this->getLastReading();
    return $reading ? $reading->getTargetProductivity() : -1;
  }

  public function getStatusClass() {
    if ($this->getLastSpeed() > $this->getLastTargetProductivity()) {
      return 'ok';
    };

    if ($this->getLastSpeed() >= $this->getLastTargetProductivity() * 0.95) {
      return 'warning';
    };

    return 'bad';
  }

  public function getLastUpdateTime($format) {
    $reading = $this->getLastReading();
    if (!$reading) {
      return $this->getTranslator()->translate('N/A');
    };

    $datetime = new \DateTime();
    $datetime->setTimestamp($reading->getCreatedAt());
    return $datetime->format($format);
  }

  public function getProductivityOptions() {
    $reading = $this->getLastReading();
    if (!$reading) {
      return array();
    };

    return array(array('motor' => $reading->getReading() + 1,
                       'result' => $reading->estimateSpeed($reading->getReading() + 1)),
                 array('motor' => $reading->getReading() + 3,
                       'result' => $reading->estimateSpeed($reading->getReading() + 3)));
  }

  /*
   * Misc getters / setters
   */

  public function getId() {
    return $this->id;
  }

  public function getName() {
    return $this->name;<commit_msg>Added datetime functionnality ala Facebook style " x time ago "<commit_after><?php

namespace Lacroix\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="production_lines")
 */
class ProductionLine {
  /**
   * @ORM\Id
   * @ORM\Column(type="integer");
   * @ORM\GeneratedValue(strategy="AUTO");
   */
  protected $id;

  /**
   * @ORM\Column(type="string")
   */
  protected $name;

  /**
   * @ORM\Column(type="float")
   */
  protected $speed_adjustment;

  /**
   * @ORM\ManyToOne(targetEntity="Room", fetch="LAZY")
   * @ORM\JoinColumn(name="room_id", referencedColumnName="id")
   */
  protected $room;

  protected $_data_entry_repository;
  protected $_translator;

  // It is not a wise idea to add readings referencne here; as long as
  // array  reference  materializes  when accessed,  this  means  that
  // Doctrine would attempt  to read the complete entry  history for a
  // production line; use DataEntry  repository to access the requried
  // history subset instead

  public function getRoomName() {
    $room = $this->getRoom();
    if (!$room) { 
      return null; 
    };

    return $room->getName();
  }

  public function getLastReading() {
    return $this->getDataEntryRepository()->getLastReadingForLine($this);
  }

  public function getLastProductName() {
    $reading = $this->getLastReading();
    return $reading ? $reading->getProductName() : $this->getTranslator()->translate('N/A');
  }

  public function getLastProductId() {
    $reading = $this->getLastReading();
    return $reading ? $reading->getProductId() : null;
  }

  public function getLastEmployees() {
    $reading = $this->getLastReading();
    return $reading ? $reading->getEmployees() : $this->getTranslator()->translate('N/A');
  }

  public function getLastSpeed() {
    $reading = $this->getLastReading();
    return $reading ? $reading->getSpeed() : $this->getTranslator()->translate('N/A');
  }

  public function getLastTargetProductivity() {
    $reading = $this->getLastReading();
    return $reading ? $reading->getTargetProductivity() : -1;
  }

  public function getStatusClass() {
    if ($this->getLastSpeed() > $this->getLastTargetProductivity()) {
      return 'ok';
    };

    if ($this->getLastSpeed() >= $this->getLastTargetProductivity() * 0.95) {
      return 'warning';
    };

    return 'bad';
  }

  public function getLastUpdateTime($format) {
    $reading = $this->getLastReading();
    if (!$reading) {
      return $this->getTranslator()->translate('N/A');
    };
    
    return $this->formatDateXTimeAgo($reading->getCreatedAt());
  }
  
  public function formatDateXTimeAgo($date) {
    $stf = 0;
	$cur_time = time();
	$diff = $cur_time - $date;
	$phrase = array('second','minute','hour','day','week','month','year','decade');
	$length = array(1,60,3600,86400,604800,2630880,31570560,315705600);

	for($i = sizeof($length)-1; ($i >=0) && (($no =  $diff/$length[$i]) <= 1); $i--); if($i < 0) $i=0; $_time = $cur_time  -($diff%$length[$i]);
	$no = floor($no); 
	if($no > 1) $phrase[$i] .='s'; 
	$value=sprintf("%d %s ",$no,$phrase[$i]);

	if(($stf == 1)&&($i >= 1)&&(($cur_tm-$_time) > 0)) $value .= time_ago($_time);

	return $value.' ago ';
  }

  public function getProductivityOptions() {
    $reading = $this->getLastReading();
    if (!$reading) {
      return array();
    };

    return array(array('motor' => $reading->getReading() + 1,
                       'result' => $reading->estimateSpeed($reading->getReading() + 1)),
                 array('motor' => $reading->getReading() + 3,
                       'result' => $reading->estimateSpeed($reading->getReading() + 3)));
  }

  /*
   * Misc getters / setters
   */

  public function getId() {
    return $this->id;
  }

  public function getName() {
    return $this->name;
{'fraction_non_alphanumeric': 0.17427267541357672, 'fraction_numerical': 0.009697661152310326, 'mean_word_length': 3.347799132052077, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 96, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3950157', 'n_tokens_mistral': 2378, 'n_tokens_neox': 2204, 'n_words': 458}