<commit_before><?php
/**
 * LeitnerChart Component.
 * 
 * Prepare the data for the front end Leitner var chart (Vue)
 *
 * The data is passed as a JSON string in a <input type="hidden" ...>
 */

class LeitnerChartComponent extends sfComponent
{
  public function execute($request)
  {
    $user_id = sfContext::getInstance()->getUser()->getUserId();

    $this->filter = ''; //$this->getUser()->getLocalPrefs()->get('review.graph.filter', '');

    $carddata = ReviewsPeer::getLeitnerBoxCounts($this->filter);

    $this->restudy_cards = $carddata[0]['expired_cards'];

    // count untested cards and add to graph
    $this->untested_cards = ReviewsPeer::getCountUntested($user_id, $this->filter);

    $carddata[0]['fresh_cards'] = $this->untested_cards;
    $carddata[0]['total_cards'] += $this->untested_cards;
    
    // count totals (save a database query)
    //$this->total_cards = 0;
    $this->expired_total = 0;
    for ($i = 0; $i < count($carddata); $i++)
    {
      $box =& $carddata[$i];
      //$this->total_cards += $box['total_cards'];
      
      // count expired cards, EXCEPT the red stack
      if ($i > 0)
      {
        $this->expired_total += $box['expired_cards'];
      }
    }

    $this->leitner_chart_data = $this->makeChartData($carddata);

    
//DBG::printr($this->chart_data);exit;

    $this->me = $this;

    return sfView::SUCCESS;
  }

  // Format data for the VueJS bar chart component
  protected function makeChartData($carddata)
  {
    $data  = new stdClass();
    $boxes = array();

    for ($i = 0; $i < count($carddata); $i++) {
      $boxes[] = array(
        // left stack, right stack
        array( 'value' => $carddata[$i]['expired_cards'] ),
        array( 'value' => $carddata[$i]['fresh_cards']   )
      );
    }
    
    $data->boxes = $boxes;

    /* links used in the chart (obsolete?  Jan 2017) */
    sfProjectConfiguration::getActive()->loadHelpers(array('Url'));
    $data->urls = array(
      'restudy'  => url_for('study/failedlist', array('absolute' => true)),
      'new'      => $this->getReviewUrl(array('type' => 'untested')),
      'due'      => $this->getReviewUrl(array('type' => 'expired'))
    );

    return $data;
  }

  /**
   * Returns url for the review page with given query parameters.
   * 
   * @param  array   $params    Query parameters
   * 
   * @return string  HTML for link tag
   */
  public function getReviewUrl($query_params)
  {
    return url_for('@review', array('absolute' => true)).'?'.http_build_query($this->addFilterParam($query_params));
  }
  
  // Add the current view filter param ('all', 'rtk1', 'rtk3', ...)
  protected function addFilterParam($query_params)
  {
    if ($this->filter !== '') {
      $query_params['filt'] = $this->filter;
    }
    return $query_params;
  }

  // Returns query_string for eview buttons given parameters + current filter.
  public function getQueryString($query_params)
  {
    return http_build_query($this->addFilterParam($query_params));
  }
}


<commit_msg>Fix empty Leitner Chart to show empty boxes so it doesn't stretch too much<commit_after><?php
/**
 * LeitnerChart Component.
 * 
 * Prepare the data for the front end Leitner var chart (Vue)
 *
 * The data is passed as a JSON string in a <input type="hidden" ...>
 */

class LeitnerChartComponent extends sfComponent
{
  public function execute($request)
  {
    $user_id = sfContext::getInstance()->getUser()->getUserId();

    $this->filter = ''; //$this->getUser()->getLocalPrefs()->get('review.graph.filter', '');

    $carddata = ReviewsPeer::getLeitnerBoxCounts($this->filter);

    $this->restudy_cards = $carddata[0]['expired_cards'];

    // count untested cards and add to graph
    $this->untested_cards = ReviewsPeer::getCountUntested($user_id, $this->filter);

    $carddata[0]['fresh_cards'] = $this->untested_cards;
    $carddata[0]['total_cards'] += $this->untested_cards;
    
    // count totals (save a database query)
    //$this->total_cards = 0;
    $this->expired_total = 0;
    for ($i = 0; $i < count($carddata); $i++)
    {
      $box =& $carddata[$i];
      //$this->total_cards += $box['total_cards'];
      
      // count expired cards, EXCEPT the red stack
      if ($i > 0)
      {
        $this->expired_total += $box['expired_cards'];
      }
    }

    $this->leitner_chart_data = $this->makeChartData($carddata);

    
//DBG::printr($this->chart_data);exit;

    $this->me = $this;

    return sfView::SUCCESS;
  }

  // Format data for the VueJS bar chart component
  protected function makeChartData($carddata)
  {
    $data  = new stdClass();
    $boxes = array();

    for ($i = 0; $i < count($carddata); $i++) {
      $boxes[] = array(
        // left stack, right stack
        array( 'value' => $carddata[$i]['expired_cards'] ),
        array( 'value' => $carddata[$i]['fresh_cards']   )
      );
    }

    // fill up with empty boxes so it doesn't stretch too much
    for ($i = count($boxes); $i < 5; $i++) {
      $boxes[] = [ ['value' => 0], ['value' => 0] ];
    }
    
    $data->boxes = $boxes;

    /* links used in the chart (obsolete?  Jan 2017) */
    sfProjectConfiguration::getActive()->loadHelpers(array('Url'));
    $data->urls = array(
      'restudy'  => url_for('study/failedlist', array('absolute' => true)),
      'new'      => $this->getReviewUrl(array('type' => 'untested')),
      'due'      => $this->getReviewUrl(array('type' => 'expired'))
    );

    return $data;
  }

  /**
   * Returns url for the review page with given query parameters.
   * 
   * @param  array   $params    Query parameters
   * 
   * @return string  HTML for link tag
   */
  public function getReviewUrl($query_params)
  {
    return url_for('@review', array('absolute' => true)).'?'.http_build_query($this->addFilterParam($query_params));
  }
  
  // Add the current view filter param ('all', 'rtk1', 'rtk3', ...)
  protected function addFilterParam($query_params)
  {
    if ($this->filter !== '') {
      $query_params['filt'] = $this->filter;
    }
    return $query_params;
  }

  // Returns query_string for eview buttons given parameters + current filter.
  public function getQueryString($query_params)
  {
    return http_build_query($this->addFilterParam($query_params));
  }
}



{'fraction_non_alphanumeric': 0.17043088258849912, 'fraction_numerical': 0.004965561428800256, 'mean_word_length': 3.067752442996743, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 85, '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': '1890249', 'n_tokens_mistral': 2084, 'n_tokens_neox': 2002, 'n_words': 461}