コード例 #1
0
 public static function begin_concept_assignment($hierarchy_id = null, $use_synonyms_for_merging = false)
 {
     $mysqli =& $GLOBALS['mysqli_connection'];
     if (!defined('SOLR_SERVER') || !SolrAPI::ping(SOLR_SERVER, 'hierarchy_entries')) {
         debug("ERROR: No Solr server; cannot begin_concept_assignment");
         return false;
     }
     // looking up which hierarchies might have nodes in preview mode
     // this will save time later on when we need to check published vs preview taxa
     self::lookup_preview_harvests();
     $confirmed_exclusions = self::check_curator_assertions();
     $hierarchies_compared = array();
     if ($default_id = Hierarchy::default_id()) {
         $default_hierarchy = Hierarchy::find($default_id);
         // TODO: This should NOT be hard-coded. ...particularly without an
         // explanation. :| ...And isn't this just ... undone as soon as we
         // leave this block by "$hierarchy_lookup_ids2 = array();"? ...This
         // seems stupid.
         if (@$default_hierarchy->id) {
             $hierarchy_lookup_ids2 = array($default_id => 1475377);
         }
     }
     $hierarchy_lookup_ids2 = array();
     // TODO: This is a SLOW, huge query. If we had a denormalized HE count
     // on each hierarchy (and, truly, we should), it would be super-fast. Do
     // this.
     $result = $mysqli->query("SELECT id ,hierarchy_entries_count as count FROM hierarchies ");
     while ($result && ($row = $result->fetch_assoc())) {
         // TODO: DON'T hard-code this (this is GBIF Nub Taxonomy).
         // Instead, add an attribute to hierarchies called "no_comparisons"
         // and check that, and make sure the migration for that sets the
         // value of that field to true for all hierarchies with a ).
         // Also make sure curators can set that value from the resource
         // page.
         if ($row['id'] == 129) {
             continue;
         }
         $hierarchy_lookup_ids2[$row['id']] = $row['count'];
     }
     // TODO: This is, again, a GBIF Nub taxonomy:
     $hierarchy_lookup_ids2[800] = 1;
     arsort($hierarchy_lookup_ids2);
     // if the function is passed a hierarchy_id then make the first loop
     // just that hierarchy otherwise make the first loop the same as the
     // inner loop - compare everything with everything else
     if ($hierarchy_id) {
         $hierarchy1 = Hierarchy::find($hierarchy_id);
         // TODO: Don't we have this in $hierarchy_lookup_ids2 ?
         $count1 = $hierarchy1->count_entries();
         $hierarchy_lookup_ids1[$hierarchy_id] = $count1;
     } else {
         $hierarchy_lookup_ids1 = $hierarchy_lookup_ids2;
     }
     foreach ($hierarchy_lookup_ids1 as $id1 => $count1) {
         $hierarchy1 = Hierarchy::find($id1);
         if (@(!$hierarchy1->id)) {
             debug("ERROR: Attempt to compare hierarchy {$id1}, but it was missing");
             continue;
         }
         foreach ($hierarchy_lookup_ids2 as $id2 => $count2) {
             $hierarchy2 = Hierarchy::find($id2);
             if (@(!$hierarchy2->id)) {
                 debug("WARNING: Skipping compare of missing hierarchy {$id2}");
                 continue;
             }
             // already compared - skip
             if (isset($hierarchies_compared[$hierarchy1->id][$hierarchy2->id])) {
                 continue;
             }
             debug("Comparing hierarchy {$id1} ({$hierarchy1->label}; {$count1} entries) to {$id2} ({$hierarchy2->label}; {$count2} entries)");
             // have the smaller hierarchy as the first parameter so the
             // comparison will be quicker
             if ($count1 < $count2) {
                 self::assign_concepts_across_hierarchies($hierarchy1, $hierarchy2, $confirmed_exclusions, $use_synonyms_for_merging);
             } else {
                 self::assign_concepts_across_hierarchies($hierarchy2, $hierarchy1, $confirmed_exclusions, $use_synonyms_for_merging);
             }
             $hierarchies_compared[$hierarchy1->id][$hierarchy2->id] = 1;
             $hierarchies_compared[$hierarchy2->id][$hierarchy1->id] = 1;
         }
     }
 }
コード例 #2
0
 function get_count_of_taxa_pages_per_partner($user_id)
 {
     $totals = array();
     if ($user_id == $this->bhl_user_id) {
         $bhl_file_path = PAGE_METRICS_TEXT_PATH . "taxon_concept_with_bhl_links.txt";
         $bhl_concept_ids = array();
         foreach (new FileIterator($bhl_file_path) as $line_number => $line) {
             $fields = explode("\t", $line);
             $taxon_concept_id = trim($fields[0]);
             $bhl_concept_ids[$taxon_concept_id] = 1;
         }
         $totals[] = count($bhl_concept_ids);
     } elseif ($user_id == $this->col_user_id) {
         $result = $this->mysqli->query("SELECT COUNT(taxon_concept_id) count FROM hierarchy_entries WHERE hierarchy_id = " . Hierarchy::default_id());
         $row = $result->fetch_row();
         $totals[] = $row[0];
     } else {
         $concept_ids = array();
         $query = "SELECT r.* FROM resources r JOIN content_partners cp ON r.content_partner_id = cp.id WHERE cp.user_id = {$user_id}";
         $resources = $this->mysqli->query($query);
         while ($resources && ($resource_row = $resources->fetch_assoc())) {
             $query = "SELECT MAX(he.id) latest_harvest_event_id FROM harvest_events he\n                    WHERE he.resource_id = " . $resource_row['id'] . " AND he.published_at IS NOT NULL AND he.published_at < '" . $this->year . "-" . ($this->month + 1) . "-01'";
             $result = $this->mysqli->query($query);
             $row = $result->fetch_row();
             $latest_harvest_event_id = $row[0];
             if (!$latest_harvest_event_id) {
                 continue;
             }
             $query = "SELECT tc.id taxon_concept_id\n                        FROM harvest_events_hierarchy_entries hehe\n                        STRAIGHT_JOIN hierarchy_entries he ON hehe.hierarchy_entry_id = he.id\n                        STRAIGHT_JOIN taxon_concepts tc ON he.taxon_concept_id = tc.id\n                        WHERE tc.published=1 AND tc.supercedure_id=0 AND hehe.harvest_event_id={$latest_harvest_event_id}";
             $result = $this->mysqli->query($query);
             while ($result && ($row = $result->fetch_assoc())) {
                 $taxon_concept_id = $row['taxon_concept_id'];
                 $concept_ids[$taxon_concept_id] = '';
             }
         }
         $totals[] = count($concept_ids);
     }
     $query = "SELECT COUNT(gapt.taxon_concept_id) FROM google_analytics_partner_taxa gapt WHERE gapt.user_id = {$user_id} AND gapt.`year` = {$this->year} AND gapt.`month` = {$this->month}";
     $result = $this->mysqli->query($query);
     $row = $result->fetch_row();
     $totals[] = $row[0];
     // $totals[0] => total taxa for user_id
     // $totals[1] => taxa viewed for user_id this month
     return $totals;
 }