private function collectStats(&$pubs) { assert('isset($this->aicml_pi_authors)'); assert('isset($this->aicml_pdf_students_staff_authors)'); $this->stats['fy_pubs'] = array(); foreach ($pubs as $pub_id => &$pub) { $pub->dbLoad($this->db, $pub_id, pdPublication::DB_LOAD_VENUE | pdPublication::DB_LOAD_CATEGORY | pdPublication::DB_LOAD_AUTHOR_FULL); $isT1 = $pub->rank_id == 1 ? 'Y' : 'N'; $fy = $this->getFiscalYearKey($pub->published); if ($fy === false) { continue; } if (!isset($this->stats['fy_pubs'][$fy])) { $this->stats['fy_pubs'][$fy] = array(); } $this->stats['fy_pubs'][$fy][$pub_id] = true; $pub_pi_authors = array_intersect_key($pub->authorsToArray(), $this->aicml_pi_authors); foreach ($pub_pi_authors as $author_id => $author_name) { // make sure publication published while at AICML $published_stamp = date2Timestamp($pub->published); if ($published_stamp < $this->aicml_pi_dates[$author_id][0] || $this->aicml_pi_dates[$author_id][1] > 0 && $published_stamp > $this->aicml_pi_dates[$author_id][1]) { unset($pub_pi_authors[$author_id]); } } if (count($pub_pi_authors) > 0) { $names = implode('; ', $pub_pi_authors); if (!isset($this->stats['pi'][$fy][$isT1][$names])) { $this->stats['pi'][$fy][$isT1][$names] = array(); } array_push($this->stats['pi'][$fy][$isT1][$names], $pub->pub_id); foreach ($pub_pi_authors as $author_id => $author_name) { if (!isset($this->stats['per_pi'][$author_name][$fy][$isT1][$names])) { $this->stats['per_pi'][$author_name][$fy][$isT1][$names] = array(); } array_push($this->stats['per_pi'][$author_name][$fy][$isT1][$names], $pub->pub_id); } } $pub_staff_authors = array_intersect_key($pub->authorsToArray(), $this->aicml_pdf_students_staff_authors); foreach ($pub_staff_authors as $author_id => $author_name) { // make sure publication published while at AICML $published_stamp = date2Timestamp($pub->published); if ($published_stamp < $this->aicml_pdf_students_staff_dates[$author_id][0] || $this->aicml_pdf_students_staff_dates[$author_id][1] > 0 && $published_stamp > $this->aicml_pdf_students_staff_dates[$author_id][1]) { unset($pub_staff_authors[$author_id]); } } if (count($pub_staff_authors) > 0) { $names = implode('; ', $pub_staff_authors); if (count($pub_pi_authors) > 0) { $names = implode('; ', $pub_pi_authors) . '; ' . $names; } if (!isset($this->stats['staff'][$fy][$isT1][$names])) { $this->stats['staff'][$fy][$isT1][$names] = array(); } array_push($this->stats['staff'][$fy][$isT1][$names], $pub->pub_id); } } krsort($this->stats); krsort($this->stats['per_pi']); // get totals foreach (array('pi', 'staff') as $group) { if (!isset($this->stats['fy_count'][$group])) { $this->stats['fy_count'][$group] = array('all' => 0, 'N' => 0, 'Y' => 0); } foreach ($this->stats[$group] as $fy => $subarr1) { if (!isset($this->stats['fy_count'][$group][$fy])) { $this->stats['fy_count'][$group][$fy] = array('all' => 0, 'N' => 0, 'Y' => 0); } foreach ($subarr1 as $t1 => $subarr2) { foreach ($subarr2 as $authors => $pub_ids) { $this->stats['fy_count'][$group][$fy][$t1] += count($pub_ids); } $this->stats['fy_count'][$group][$t1] += $this->stats['fy_count'][$group][$fy][$t1]; $this->stats['fy_count'][$group][$fy]['all'] += $this->stats['fy_count'][$group][$fy][$t1]; $this->stats['fy_count'][$group]['all'] += $this->stats['fy_count'][$group][$fy][$t1]; } } } }
/** * Returns the corresponding fiscal year for the date passed in. * * @param string $date in YYYY-MM-DD format. * @return unknown */ protected function getFiscalYearKey($date) { $datestamp = date2Timestamp($date); foreach ($this->fiscal_year_ts as $key => $fyts) { if ($fyts[0] <= $datestamp && $fyts[1] >= $datestamp) { return $key; } } //throw new Exception("date not within fiscal years: " + $date); return false; }