All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openmetadata.service.dataInsight.DailyActiveUsersAggregator Maven / Gradle / Ivy

There is a newer version: 1.5.11
Show newest version
package org.openmetadata.service.dataInsight;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import org.openmetadata.schema.dataInsight.type.DailyActiveUsers;

public abstract class DailyActiveUsersAggregator
    implements DataInsightAggregatorInterface {
  private final A aggregations;

  protected DailyActiveUsersAggregator(A aggregations) {
    this.aggregations = aggregations;
  }

  @Override
  public List aggregate() throws ParseException {
    H histogramBucket = getHistogramBucket(this.aggregations);
    List data = new ArrayList<>();
    for (B bucket : getBuckets(histogramBucket)) {
      Long timestamp = getKeyAsEpochTimestamp(bucket);
      long activeUsers = getDocCount(bucket);

      data.add(new DailyActiveUsers().withTimestamp(timestamp).withActiveUsers((int) activeUsers));
    }
    return data;
  }

  protected abstract H getHistogramBucket(A aggregations);

  protected abstract List getBuckets(H histogramBucket);

  protected abstract long getKeyAsEpochTimestamp(B bucket);

  protected abstract Long getDocCount(B bucket);
}