当前位置: 首页>>代码示例>>C++>>正文


C++ Aggregate::aggregate方法代码示例

本文整理汇总了C++中Aggregate::aggregate方法的典型用法代码示例。如果您正苦于以下问题:C++ Aggregate::aggregate方法的具体用法?C++ Aggregate::aggregate怎么用?C++ Aggregate::aggregate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Aggregate的用法示例。


在下文中一共展示了Aggregate::aggregate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: aggregate

void ResultSet::aggregate(const std::string& prefix,
                          const std::string& filename) {
  // Parse prefix
  char* prefix_data = strdup(prefix.data());
  char* reason          = strtok(prefix_data, "/");
  char* appName         = strtok(NULL, "/");
  char* channel         = strtok(NULL, "/");
  char* version         = strtok(NULL, "/");
  char* strBuildId      = strtok(NULL, ".");
  char* submissionDate  = strtok(NULL, ".");
  if (!reason || !appName || !channel || !version || !strBuildId ||
      !submissionDate) {
    fprintf(stderr, "Prefix '%s' missing parts \n", prefix.data());
    free(prefix_data);
    return;
  }
  // Intern strBuildId
  InternedString buildId = Aggregate::internBuildIdString(strBuildId);

  // Get build date, ignore the rest
  if (strlen(strBuildId) < 8) {
    fprintf(stderr, "BuildId '%s' is not valid, too short\n", strBuildId);
    free(prefix_data);
    return;
  }
  string buildDate(strBuildId, 8);

  // Decide if we should skip submission date
  bool skipBySubmissionDate = false;
  {
    // Parse submission date and buildDate
    time_t submissionTime = parseDate(submissionDate);
    time_t buildTime      = parseDate(buildDate.data());

    // Skip aggregation by submission date of it's been more than 60 days since
    // build date
    if (difftime(submissionTime, buildTime) > 60 * 60 * 24 * 60) {
      skipBySubmissionDate = true;
    }
  }

  // Reduce version to major version (discard everything after the dot)
  {
    char* c = version;
    while(*c != '.' && *c != '\0') c++;
    *c = '\0';
  }

  // Find/create ChannelVersion object
  ChannelVersion* cv = nullptr;
  {
    string channelVersion = string(channel) + "/" + string(version);
    // Find channel version in hash table
    auto it = _channelVersionMap.find(channelVersion);
    // If not present create ChannelVersion
    if (it == _channelVersionMap.end()) {
      cv = new ChannelVersion(_measureStringCtx, _filterStringCtx);
      it = _channelVersionMap.insert({channelVersion, cv}).first;
    }
    cv = it->second;
  }
  assert(cv);

  // Create filterPath start
  string reasonAppName = string(reason) + "/" + string(appName) + "/";

  // Allocate a string to hold <measure>/<by-date-type>
  string measureFilename;
  measureFilename.reserve(2048);

  FILE* input = fopen(filename.data(), "r");
  {
    // Read file line by line
    CompressedFileReader reader(input);
    char* line = nullptr;
    int nb_line = 0;
    while ((line = reader.nextLine()) != nullptr) {
      nb_line++;
      // Find tab
      char* tab = strchr(line, '\t');
      if (!tab) {
        fprintf(stderr, "No tab on line %i\n", nb_line);
        continue;
      }

      // Set tab = \0 creating two C-strings
      *tab = '\0';
      char* uuid = line;
      char* json = tab + 1;

      UNUSED(uuid);

      // Parse the JSON line
      Document d;
      d.Parse<0>(json);

      // Check that we have an object
      if (!d.IsObject()) {
        fprintf(stderr, "JSON root is not an object on line %i\n", nb_line);
        continue;
//.........这里部分代码省略.........
开发者ID:Uberi,项目名称:telemetry-aggregator,代码行数:101,代码来源:ResultSet.cpp


注:本文中的Aggregate::aggregate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。