Exemple #1
0
/* debug-ageout */
static void cmd_debug_ageout(
    struct watchman_client* client,
    const json_ref& args) {

  /* resolve the root */
  if (json_array_size(args) != 3) {
    send_error_response(client,
                        "wrong number of arguments for 'debug-ageout'");
    return;
  }

  auto root = resolve_root_or_err(client, args, 1, false);
  if (!root) {
    return;
  }

  std::chrono::seconds min_age(json_integer_value(json_array_get(args, 2)));

  auto resp = make_response();

  root->performAgeOut(min_age);

  resp.set("ageout", json_true());
  send_and_dispose_response(client, std::move(resp));
}
Exemple #2
0
void CategoryInfo::DoExecute() {


  auto categories = model_->categories();
  vector<string> names = categories->category_names();
  /*
  cache_ << "*category_info: " << label_ << "\n";
  for(string name : names) {
    cache_ << "Category: " << name << "\n";
    cache_ << "min_age: " << categories->min_age(name) << "\n";
    cache_ << "max_age: " << categories->max_age(name) << "\n";

    vector<unsigned> years = categories->years(name);
    cache_ << "years: ";
    for (unsigned year : years)
      cache_ << year << " ";
    cache_ << "\n\n";
  }
  */
  cache_ << "*" << label_ << " " << "("<< type_ << ")"<<"\n";
  for(string name : names) {
    cache_ << name << " " << REPORT_R_LIST<<"\n";
    cache_ << "min_age: " << categories->min_age(name) << "\n";
    cache_ << "max_age: " << categories->max_age(name) << "\n";

    vector<unsigned> years = categories->years(name);
    cache_ << "years: ";
    for (unsigned year : years)
      cache_ << year << " ";
    cache_ << "\n";
    cache_ << REPORT_R_LIST_END << "\n";
  }


  ready_for_writing_ = true;
}
/**
 * Validate our Maturation Rate process
 *
 * - Check for the required parameters
 * - Assign variables from our parameters
 * - Verify the categories are real
 * - If proportions or selectivities only has 1 element specified
 *   add more elements until they match number of categories
 * - Verify vector lengths are all the same
 * - Verify categories From->To have matching age ranges
 * - Check all proportions are between 0.0 and 1.0
 */
void TransitionCategory::DoValidate() {
  LOG_TRACE();
  from_category_names_ = model_->categories()->ExpandLabels(from_category_names_, parameters_.Get(PARAM_FROM));
  to_category_names_ = model_->categories()->ExpandLabels(to_category_names_, parameters_.Get(PARAM_TO));

  if (selectivity_names_.size() == 1)
    selectivity_names_.assign(from_category_names_.size(), selectivity_names_[0]);

  // Validate Categories
  auto categories = model_->categories();
  for (const string& label : from_category_names_) {
    if (!categories->IsValid(label))
      LOG_ERROR_P(PARAM_FROM) << ": category " << label << " does not exist. Have you defined it?";
  }
  for(const string& label : to_category_names_) {
    if (!categories->IsValid(label))
      LOG_ERROR_P(PARAM_TO) << ": category " << label << " does not exist. Have you defined it?";
  }

  // Validate the from and to vectors are the same size
  if (from_category_names_.size() != to_category_names_.size()) {
    LOG_ERROR_P(PARAM_TO)
        << ": Number of 'to' categories provided does not match the number of 'from' categories provided."
        << " Expected " << from_category_names_.size() << " but got " << to_category_names_.size();
  }

  // Allow a one to many relationship between proportions and number of categories.
  if (proportions_.size() == 1)
    proportions_.resize(to_category_names_.size(),proportions_[0]);

  // Validate the to category and proportions vectors are the same size
  if (to_category_names_.size() != proportions_.size()) {
    LOG_ERROR_P(PARAM_PROPORTIONS)
        << ": Number of proportions provided does not match the number of 'to' categories provided."
        << " Expected " << to_category_names_.size() << " but got " << proportions_.size();
  }

  // Validate the number of selectivities matches the number of proportions
  if (proportions_.size() != selectivity_names_.size() && proportions_.size() != 1) {
    LOG_ERROR_P(PARAM_SELECTIVITIES)
        << ": Number of selectivities provided does not match the number of proportions provided."
        << " Expected " << proportions_.size() << " but got " << selectivity_names_.size();
  }

  // Validate that each from and to category have the same age range.
  for (unsigned i = 0; i < from_category_names_.size(); ++i) {
    if (categories->min_age(from_category_names_[i]) != categories->min_age(to_category_names_[i])) {
      LOG_ERROR_P(PARAM_FROM) << ": Category " << from_category_names_[i] << " does not"
          << " have the same age range as the 'to' category " << to_category_names_[i];
    }

    if (categories->max_age(from_category_names_[i]) != categories->max_age(to_category_names_[i])) {
      LOG_ERROR_P(PARAM_FROM) << ": Category " << from_category_names_[i] << " does not"
          << " have the same age range as the 'to' category " << to_category_names_[i];
    }
  }

  // Validate the proportions are between 0.0 and 1.0
  for (Double proportion : proportions_) {
    if (proportion < 0.0 || proportion > 1.0)
      LOG_ERROR_P(PARAM_PROPORTIONS) << ": proportion " << AS_DOUBLE(proportion) << " must be between 0.0 and 1.0 (inclusive)";
  }

  for (unsigned i = 0; i < from_category_names_.size(); ++i)
    proportions_by_category_[from_category_names_[i]] = proportions_[i];
}