Example #1
0
void Analyzer::compute_attribute_stat(const AttributeID& attr_id) {
  TableStatistic* tab_stat =
      StatManager::getInstance()->getTableStatistic(attr_id.table_id);
  assert(tab_stat != 0);
  if (tab_stat->getAttributeStatistics(attr_id)) {
    printf("attribute statistics is already existed!\n");
    return;
  }
  unsigned long distinct_cardinality;
  if (Catalog::getInstance()
          ->getTable(attr_id.table_id)
          ->getAttribute(attr_id.offset)
          .isUnique()) {
    /**
     * for attribute that has UNIQUE property, gathering the number of distinct
     * values is unnecessary.
     */
    distinct_cardinality = tab_stat->number_of_tuples_;
  } else {
    distinct_cardinality = Analyzer::getDistinctCardinality(attr_id);
  }
  AttributeStatistics* attr_stat = new AttributeStatistics();
  attr_stat->setDistinctCardinality(distinct_cardinality);
  printf("Distinct values:%d\n", distinct_cardinality);
  if (Analyzer::isBeneficalFromHistrogram(distinct_cardinality,
                                          tab_stat->number_of_tuples_)) {
    //		Analyzer::analyse(attr_id);
    Histogram* his = Analyzer::computeHistogram(
        attr_id, decideNumberOfBucketsForHistogram(
                     distinct_cardinality, tab_stat->number_of_tuples_));
    his->Print(Catalog::getInstance()
                   ->getTable(attr_id.table_id)
                   ->getAttribute(attr_id.offset)
                   .attrType->type);
    attr_stat->setHistogram(his);
  }

  attr_stat->print();
  printf("----%s----\n", Catalog::getInstance()
                             ->getTable(attr_id.table_id)
                             ->getAttribute(attr_id.offset)
                             .getName()
                             .c_str());
  tab_stat->addAttributeStatistics(attr_id, attr_stat);
}
//================================================
void DynamicalGraph::DiversityHistoOutput( const char* filename) {
  std::ofstream fout(filename);
  diversity_histo.Print( fout );
  fout.close();
}
//================================================
void DynamicalGraph::ExtinctionSizeHistoOutput( const char* filename) {
  std::ofstream fout(filename);
  extinction_histo.Print( fout );
  fout.close();
}
//================================================
void DynamicalGraph::LifetimeHistoOutput( const char* filename) {
  std::ofstream fout(filename);
  lifetime_histo.Print( fout );
  fout.close();
}