Changeset - 6583b0529782
[Not reviewed]
default
0 4 0
Nathan Brink (binki) - 15 years ago 2011-03-26 11:57:37
ohnobinki@ohnopublishing.net
Fix the school_crawl_days_format() school crawler support function to log errors through school_crawl_logf() instead of error_log().
4 files changed with 13 insertions and 9 deletions:
0 comments (0 inline, 0 general)
inc/school.crawl.inc
Show inline comments
 
@@ -140,88 +140,92 @@ function school_crawl_mktime(array $tm)
 
		$tm['tm_mon'] + 1, $tm['tm_mday'], $tm['tm_year'] + 1900);
 
}
 

	
 
/**
 
 * \brief
 
 *   Take an array of day names and assemble them into
 
 *   slate_permutate's internal (weird) representation of a set of
 
 *   weekdays.
 
 *
 
 * This function is intended to make it easy for one to take the
 
 * output of an explode() call. For example, to decode $days_str =
 
 * 'Monday, Tuesday, Friday', one would do
 
 * school_crawl_days_format(explode(', ', $days_str));
 
 * school_crawl_days_format($school_crawl_log, explode(', ', $days_str));
 
 *
 
 * \param $school_crawl_log
 
 *   A school_crawl_log handle to report errors to.
 
 * \param $days
 
 *   An array of day names. These may be common abbreviations or
 
 *   truncations (any truncations must be two chars long for
 
 *   simplicity. One-char representations are supported, however, but
 
 *   use 'm', 't', 'w', 'h', 'f' to distinguish Thursday and
 
 *   Tuesday. 'r' may also be used for Thursday.). Case does not
 
 *   matter. 's' is for Saturday, based on CCBCMD.
 
 * \return
 
 *   slate_permutate's strange internal days representation.
 
 */
 
function school_crawl_days_format($days)
 
function school_crawl_days_format(array $school_crawl_log, $days)
 
{
 
  static $daymap_1 = array('m' => 'm', 't' => 't', 'w' => 'w', 'h' => 'h', 'r' => 'h', 'f' => 'f', 's' => 's');
 
  static $daymap_2 = array('th' => 'h');
 

	
 
  $my_days = array();
 
  foreach ($days as $day)
 
    {
 
      $day_orig = $day;
 
      $day = strtolower(substr(trim($day), 0, 2));
 

	
 
      /*
 
       * convert from two-char representation to one-char
 
       * representation.n
 
       */
 
      if (strlen($day) > 1)
 
	{
 
	  if (isset($daymap_2[$day]))
 
	    $day = $daymap_2[$day];
 
	  else
 
	    $day = substr($day, 0, 1);
 
	}
 
      if (isset($daymap_1[$day]))
 
	$my_days[$daymap_1[$day]] = TRUE;
 
      else
 
	error_log('school_crawl_days_format() got invalid day specifier:'
 
		  . ' `' . $day_orig . '\' => `' . $day . '\'');
 
	school_crawl_logf($school_crawl_log, 5, "school_crawl_days_format() got invalid day specifier: `%s' => `%s'.",
 
			  $day_orig, $day);
 
    }
 

	
 
  $day_str = '';
 
  foreach ($my_days as $day_val => $junk)
 
    $day_str .= $day_val;
 

	
 
  return $day_str;
 
}
 

	
 
/**
 
 * \brief
 
 *   Take a string of day initials and format it.
 
 *
 
 * \param $school_crawl_log
 
 *   The school_crawl_log handle to write errors out to.
 
 * \param $days_str
 
 *   Example input: 'mwf', 'TR'.
 
 * \return
 
 *   Same as school_crawl_days_format()
 
 */
 
function school_crawl_days_str_format($days_str)
 
function school_crawl_days_str_format(array $school_crawl_log, $days_str)
 
{
 
  $day_initials = array();
 
  for ($i = 0; $i < strlen($days_str); $i ++)
 
    $day_initials[] = $days_str[$i];
 

	
 
  return school_crawl_days_format($day_initials);
 
  return school_crawl_days_format($school_crawl_log, $day_initials);
 
}
 

	
 
/**
 
 * \brief
 
 *   Try to guess a more standardized section_meeting type.
 
 *
 
 * \param $meeting_type
 
 *   The upstream's meeting_type, such as 'LEC', 'lec', 'LAB',
 
 *   etc. New mappings should be added to this function as long as
 
 *   they are general enough.
 
 */
 
function school_crawl_meeting_type($meeting_type = 'lecture')
school.d/calvin.crawl.inc
Show inline comments
 
@@ -334,25 +334,25 @@ function calvin_crawl(array &$semesters,
 
	      /*
 
	       * 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'], $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]));
 

	
 
	  $days = school_crawl_days_format(explode(', ', $meeting_info_matches[5]));
 
	  $days = school_crawl_days_format($school_crawl_log, explode(', ', $meeting_info_matches[5]));
 
	  $time_start = school_crawl_time_format(strptime($meeting_info_matches[6], '%I:%M%p'));
 
	  $time_end = school_crawl_time_format(strptime($meeting_info_matches[7], '%I:%M%p'));
 
	  $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, $faculty_name)), $synonym);
 
	  $semester->section_add($section_id['department'], $section_id['course'], $section, $title);
 

	
 
	  /*
 
	   * Try to update semester's longetivity stats to help the
school.d/ccbcmd.crawl.inc
Show inline comments
 
@@ -219,25 +219,25 @@ function ccbcmd_crawl(array &$semesters,
 
	    school_crawl_logf($school_crawl_log, 0, "College seems to support multiple meeting times per semester which we don't know how to parse (even though slate_permutate itself can handle this situation): ``%s'' time_end_text: ``%s''.",
 
		    $time_range_text, $time_end_text);
 
	    return 1;
 
	  }
 
	$time_end = strptime($time_end_text, '%I:%M %p');
 
	if ($time_end === FALSE || $time_start === FALSE)
 
	  {
 
	    school_crawl_logf($school_crawl_log, 0, "Error parsing start or end time: start: ``%s'' end: ``%s''.",
 
		    $time_start_text, $time_end_text);
 
	    return 1;
 
	  }
 

	
 
	$days = school_crawl_days_str_format($children->item($section_offsets['days'])->textContent);
 
	$days = school_crawl_days_str_format($school_crawl_log, $children->item($section_offsets['days'])->textContent);
 

	
 
	$section_meetings[] = new SectionMeeting($days, school_crawl_time_format($time_start), school_crawl_time_format($time_end),
 
						 $children->item($section_offsets['location'])->textContent,
 
						 $instructor);
 

	
 
	/* check if a semester's date range should be increased */
 
	$section_dates = $children->item($section_offsets['dates'])->textContent;
 
	if (preg_match(';^([0-9]+)/([0-9]+)-([0-9]+)/([0-9]+)$;', $section_dates, $section_dates_matches))
 
	  {
 
	    $semester->time_start_set_test(mktime(0, 0, 0, $section_dates_matches[1], $section_dates_matches[2], $semester->year_get()));
 
	    $semester->time_end_set_test(  mktime(0, 0, 0, $section_dates_matches[3], $section_dates_matches[4], $semester->year_get()));
 
	  }
school.d/cedarville.crawl.inc
Show inline comments
 
@@ -220,25 +220,25 @@ function cedarville_crawl(array &$semest
 
		      school_crawl_logf($school_crawl_log, 8, "Skipping some meeting data for %s because it is a date range: `%s'.",
 
					implode('-', $section_parts), $meeting_matches[0]);
 
		      $meetings_str = substr($meetings_str, strlen($meeting_matches[0]));
 
		      continue;
 
		    }
 

	
 
		  school_crawl_logf($school_crawl_log, 6, "Error parsing meeting time. Given `%s'. Skipping %s.", $meetings_str, implode('-', $section_parts));
 
		  break;
 
		}
 
	      /* prepare for parsing the next meeting time */
 
	      $meetings_str = substr($meetings_str, strlen($meeting_matches[0]));
 

	
 
	      $days = school_crawl_days_str_format($meeting_matches[3]);
 
	      $days = school_crawl_days_str_format($school_crawl_log, $meeting_matches[3]);
 
	      $time_start = school_crawl_time_format(strptime($meeting_matches[4] . 'M', '%I:%M%p'));
 
	      $time_end = school_crawl_time_format(strptime($meeting_matches[5] . 'M', '%I:%M%p'));
 
	      $room = $meeting_matches[2];
 

	
 
	      $type = school_crawl_meeting_type($meeting_matches[1]);
 

	
 
	      /* check for daterange information -- i.e., if the first regex successfully matched: */
 
	      if (count($meeting_matches) > 7)
 
		{
 
		  $date_start = school_crawl_mktime(strptime($meeting_matches[6], '%m/%d/%y'));
 
		  $date_end = school_crawl_mktime(strptime($meeting_matches[7], '%m/%d/%y'));
 
		  if (!empty($date_start) && !empty($date_end))
0 comments (0 inline, 0 general)