Changeset - 303e331cb53f
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 13 years ago 2012-08-30 12:18:21
ohnobinki@ohnopublishing.net
Make the Semester class smarter about guessing it start and end times based on season to support crawling without getting exact times, fixing dordt semester detection for now.
1 file changed with 18 insertions and 0 deletions:
0 comments (0 inline, 0 general)
inc/class.semester.inc
Show inline comments
 
modified file chmod 100755 => 100644
 
@@ -314,48 +314,54 @@ class Semester
 
   *   The new time_end to consider.
 
   */
 
  public function time_end_set_test($time_end)
 
  {
 
    if ($time_end && $time_end > $this->time_end)
 
      $this->time_end_set($time_end);
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Add a potential end time to the pool of end times.
 
   */
 
  public function time_end_pool_add($time_end)
 
  {
 
    $this->time_ends[] = $time_end;
 
  }
 

	
 
  public function time_end_get()
 
  {
 
    if (count($this->time_ends))
 
      {
 
        $times = filter_outliers($this->time_ends);
 
        $this->time_end = max($times);
 
      }
 
    elseif (!$this->time_end)
 
      {
 
        /* Return, but don't store, a guess. */
 
        $fourmonths = gmmktime(0, 0, 0, 5, 2012) - gmmktime(0, 0, 0, 1, 2012);
 
        return $this->time_start_get() + $fourmonths;
 
      }
 

	
 
    return $this->time_end;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Update the time_start.
 
   *
 
   * The time_start is a unix timestamp roughly estimating the time at
 
   * which a semester starts. It is used when guessing what semester a
 
   * user is interested in.
 
   *
 
   * \param $time_start
 
   *   The new time_start.
 
   */
 
  public function time_start_set($time_start)
 
  {
 
    $this->time_start = $time_start;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Only update the time_start if the time_start isn't yet set or
 
   *   if the given time_start is earlier than the stored one.
 
@@ -375,48 +381,60 @@ class Semester
 

	
 
  /**
 
   * \brief
 
   *   Add a potential semester start time to the pool of potential
 
   *   start times.
 
   *
 
   * The idea is that there might be erroneous entries in a school's
 
   * database (
 
   * http://www.facebook.com/CalvinRegistrar/posts/299438720070457 )
 
   * which would skew the detected start time. Use statistics to
 
   * detect and kill outliers by using a pool of endtimes :-D.
 
   */
 
  public function time_start_pool_add($time_start)
 
  {
 
    $this->time_starts[] = $time_start;
 
  }
 

	
 
  public function time_start_get()
 
  {
 
    if (count($this->time_starts))
 
      {
 
        $times = filter_outliers($this->time_starts);
 
        $this->time_end = min($times);
 
      }
 
    elseif (!$this->time_start)
 
      {
 
        /* Return, but don't store, a guess. */
 
        $season_starts = array(
 
          'spring' => 0,
 
          'summer' => 5,
 
          'fall' => 8,
 
          'winter' => 12,
 
        );
 
        if (!empty($season_starts[$this->season]))
 
            return gmmktime(0, 0, 0, $season_starts[$this->season], $this->year);
 
      }
 

	
 
    return $this->time_start;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Get a semester's year.
 
   */
 
  public function year_get()
 
  {
 
    return $this->year;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Get a semester's season.
 
   */
 
  public function season_get()
 
  {
 
    return $this->season;
 
  }
 

	
 
  /**
 
   * \brief
0 comments (0 inline, 0 general)