Changeset - 0e55e98d752c
[Not reviewed]
default
0 2 0
Nathan Brink (binki) - 15 years ago 2011-03-23 09:39:27
ohnobinki@ohnopublishing.net
Support crawling course titles for calvin.
2 files changed with 16 insertions and 8 deletions:
0 comments (0 inline, 0 general)
inc/class.semester.inc
Show inline comments
 
@@ -147,22 +147,24 @@ class Semester
 
   * \param $dept
 
   *   The department this section belongs to.
 
   * \param $class
 
   *   The class this section belongs to.
 
   * \param $section
 
   *   The section itself.
 
   * \param $title
 
   *   The course human-friendly title.
 
   */
 
  public function section_add($dept, $class, Section $section)
 
  public function section_add($dept, $class, Section $section, $title = NULL)
 
  {
 
    $dept = strtoupper($dept);
 
    $class = strtoupper($class);
 

	
 
    if (!isset($this->departments[$dept])
 
	|| !isset($this->departments[$dept][$class]))
 
      {
 
	$classobj = new Course($dept . '-' . $class);
 
	$classobj = new Course($dept . '-' . $class, $title);
 
	$this->class_add($classobj);
 
      }
 
    else
 
      {
 
	$classobj = $this->departments[$dept][$class];
 
      }
school.d/calvin.crawl.inc
Show inline comments
 
@@ -270,22 +270,28 @@ function calvin_crawl(array &$semesters,
 
	  $credits = dom_input_value($results_dom, 'SEC.MIN.CRED_' . $list_row); /* or id="SEC_FACULTY_INFO_$list_row" */
 
	  $comment = dom_id_content($results_dom, 'SEC_COMMENTS_' . $list_row); /* or name="SEC.COMMENTS_$list_row" */
 

	
 
	  /* parse */
 
	  $section_id = Section::parse($sec_short_title);
 
	  $synonym = NULL;
 
	  if (preg_match(';\(([0-9]+)\);', $sec_short_title, $matches))
 
	  $title = NULL;
 
	  if (preg_match(';\(([0-9]+)\)(.*);', $sec_short_title, $matches))
 
	    {
 
	    $synonym = $matches[1];
 
	      $title = $matches[2];
 
	    }
 

	
 
	  school_crawl_logf($school_crawl_log, 10, "");
 
	  school_crawl_logf($school_crawl_log, 10, implode('-', $section_id) . ': ' . $sec_short_title);
 
	  school_crawl_logf($school_crawl_log, 10, $openness);
 
	  school_crawl_logf($school_crawl_log, 10, $sec_meeting_info);
 
	  school_crawl_logf($school_crawl_log, 10, $faculty_name);
 
	  school_crawl_logf($school_crawl_log, 10, $credits);
 
	  school_crawl_logf($school_crawl_log, 10, $comment);
 
	  school_crawl_logf($school_crawl_log, 10, "synonym: %s", $synonym);
 
	  school_crawl_logf($school_crawl_log, 10, "title: %s", $title);
 

	
 
	  /*
 
	   * The input format for this is, thankfully, pretty rigid
 
	   * :-D. Example input format:
 
	   *
 
	   * '01/31/2011-05/11/2011 Lecture Monday, Wednesday 01:00PM - 03:50PM, Spoelhof Center, Room 101'
 
@@ -313,26 +319,26 @@ function calvin_crawl(array &$semesters,
 
	    {
 
	      school_crawl_logf($school_crawl_log, 8, 'Skipping class because of incomplete meeting time information: '
 
				. implode('-', $section_id) . ' has meeting info of `'
 
				. $sec_meeting_info . '\'');
 
	      $skipped_sections['incomplete meeting info'] ++;
 
	      /* Still add to have less confusing autocomplete */
 
	      calvin_crawl_course_add($semester, $section_id['department'], $section_id['course']);
 
	      calvin_crawl_course_add($semester, $section_id['department'], $section_id['course'], $title);
 
	      continue;
 
	    }
 

	
 
	  if (!preg_match(';^([0-9]{2}/[0-9]{2}/[0-9]{4})-([0-9]{2}/[0-9]{2}/[0-9]{4}) (([^ ,]+ )+)([^0-9]+) ([^ ]+) - ([^ ]+), (.*)$;', $sec_meeting_info, $meeting_info_matches))
 
	    {
 
	      school_crawl_logf($school_crawl_log, 8, 'Unable to parse calvin section meeting info string into start/end/days information for '
 
				. implode('-', $section_id) . ': ``' . $sec_meeting_info . '\'\'');
 
	      $skipped_sections['invalid meeting info format'] ++;
 
	      /*
 
	       * Still add at least the course to the semester so that
 
	       * it shows up in autocmoplete.
 
	       */
 
	      calvin_crawl_course_add($semester, $section_id['department'], $section_id['course']);
 
	      calvin_crawl_course_add($semester, $section_id['department'], $section_id['course'], $title);
 
	      continue;
 
	    }
 
	  $date_start = $meeting_info_matches[1];
 
	  $date_end = $meeting_info_matches[2];
 
	  /* e.g., 'Lecture', 'Practicum' */
 
	  $meeting_type = strtolower(trim($meeting_info_matches[3]));
 
@@ -343,13 +349,13 @@ function calvin_crawl(array &$semesters,
 
	  $meeting_place = $meeting_info_matches[8];
 

	
 
	  foreach (array('date_start', 'date_end', 'meeting_type', 'days', 'time_start', 'time_end', 'meeting_place', 'meeting_type') as $var)
 
	    school_crawl_logf($school_crawl_log, 10, "%s:%s", $var, ${$var});
 

	
 
	  $section = new Section($section_id['section'], array(new SectionMeeting($days, $time_start, $time_end, $meeting_place, $meeting_type)), $synonym, $faculty_name);
 
	  $semester->section_add($section_id['department'], $section_id['course'], $section);
 
	  $semester->section_add($section_id['department'], $section_id['course'], $section, $title);
 

	
 
	  /*
 
	   * Try to update semester's longetivity stats to help the
 
	   * school_semester_guess() function:
 
	   */
 
	  $date_start_time = strptime($date_start, '%m/%d/%Y');
 
@@ -493,11 +499,11 @@ function calvin_crawl_noscript_filter($h
 
 * \param $deparmtent
 
 *   The department of the course to add.
 
 * \param $course_id
 
 *   The course_id which, with the department string, forms a
 
 *   fully-qualified course_id.
 
 */
 
function calvin_crawl_course_add(Semester $semester, $department, $course_id)
 
function calvin_crawl_course_add(Semester $semester, $department, $course_id, $title)
 
{
 
  if ($semester->class_get($department, $course_id) == NULL)
 
    $semester->class_add(new Course($department . '-' . $course_id));
 
    $semester->class_add(new Course($department . '-' . $course_id, $title));
 
}
0 comments (0 inline, 0 general)