Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(analytics): Add WAU over the last 2 months chart #3252

Merged
merged 8 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,59 +45,77 @@ public final List<AnalyticsChartGroup> get(DataFetchingEnvironment environment)
*/
private List<AnalyticsChart> getProductAnalyticsCharts() {
final List<AnalyticsChart> charts = new ArrayList<>();
final DateTime endDate = DateTime.now();
final DateTime startDate = endDate.minusWeeks(1);
final DateRange dateRange =
new DateRange(String.valueOf(startDate.getMillis()), String.valueOf(endDate.getMillis()));
final DateTime now = DateTime.now();
final DateTime aWeekAgo = now.minusWeeks(1);
final DateRange lastWeekDateRange =
new DateRange(String.valueOf(aWeekAgo.getMillis()), String.valueOf(now.getMillis()));

final DateTime twoMonthsAgo = now.minusMonths(2);
final DateRange twoMonthsDateRange =
new DateRange(String.valueOf(twoMonthsAgo.getMillis()), String.valueOf(now.getMillis()));

// Chart 1: Time Series Chart
String title = "Searches Last Week";
DateInterval granularity = DateInterval.DAY;
String eventType = "SearchEvent";
String wauTitle = "Weekly Active Users";
DateInterval weeklyInterval = DateInterval.WEEK;

final List<NamedLine> wauTimeseries =
_analyticsService.getTimeseriesChart(AnalyticsService.DATAHUB_USAGE_EVENT_INDEX, twoMonthsDateRange, weeklyInterval,
Optional.empty(), ImmutableMap.of(), Optional.of("browserId"));
charts.add(TimeSeriesChart.builder()
.setTitle(wauTitle)
.setDateRange(twoMonthsDateRange)
.setInterval(weeklyInterval)
.setLines(wauTimeseries)
.build());

// Chart 2: Time Series Chart
String searchesTitle = "Searches Last Week";
DateInterval dailyInterval = DateInterval.DAY;
String searchEventType = "SearchEvent";

final List<NamedLine> searchesTimeseries =
_analyticsService.getTimeseriesChart(AnalyticsService.DATAHUB_USAGE_EVENT_INDEX, dateRange, granularity,
Optional.empty(), ImmutableMap.of("type", ImmutableList.of("SearchEvent")), Optional.empty());
_analyticsService.getTimeseriesChart(AnalyticsService.DATAHUB_USAGE_EVENT_INDEX, lastWeekDateRange, dailyInterval,
Optional.empty(), ImmutableMap.of("type", ImmutableList.of(searchEventType)), Optional.empty());
charts.add(TimeSeriesChart.builder()
.setTitle(title)
.setDateRange(dateRange)
.setInterval(granularity)
.setTitle(searchesTitle)
.setDateRange(lastWeekDateRange)
.setInterval(dailyInterval)
.setLines(searchesTimeseries)
.build());

// Chart 2: Table Chart
final String title2 = "Top Search Queries";
// Chart 3: Table Chart
final String topSearchTitle = "Top Search Queries";
final List<String> columns = ImmutableList.of("Query", "Count");

final List<Row> topSearchQueries =
_analyticsService.getTopNTableChart(AnalyticsService.DATAHUB_USAGE_EVENT_INDEX, Optional.of(dateRange),
"query.keyword", ImmutableMap.of("type", ImmutableList.of(eventType)), Optional.empty(), 10);
charts.add(TableChart.builder().setTitle(title2).setColumns(columns).setRows(topSearchQueries).build());
_analyticsService.getTopNTableChart(AnalyticsService.DATAHUB_USAGE_EVENT_INDEX, Optional.of(lastWeekDateRange),
"query.keyword", ImmutableMap.of("type", ImmutableList.of(searchEventType)), Optional.empty(), 10);
charts.add(TableChart.builder().setTitle(topSearchTitle).setColumns(columns).setRows(topSearchQueries).build());

// Chart 3: Bar Graph Chart
final String title3 = "Section Views across Entity Types";
// Chart 4: Bar Graph Chart
final String sectionViewsTitle = "Section Views across Entity Types";
final List<NamedBar> sectionViewsPerEntityType =
_analyticsService.getBarChart(AnalyticsService.DATAHUB_USAGE_EVENT_INDEX, Optional.of(dateRange),
_analyticsService.getBarChart(AnalyticsService.DATAHUB_USAGE_EVENT_INDEX, Optional.of(lastWeekDateRange),
ImmutableList.of("entityType.keyword", "section.keyword"),
ImmutableMap.of("type", ImmutableList.of("EntitySectionViewEvent")), Optional.empty());
charts.add(BarChart.builder().setTitle(title3).setBars(sectionViewsPerEntityType).build());
charts.add(BarChart.builder().setTitle(sectionViewsTitle).setBars(sectionViewsPerEntityType).build());

// Chart 4: Bar Graph Chart
final String title4 = "Actions by Entity Type";
// Chart 5: Bar Graph Chart
final String actionsByTypeTitle = "Actions by Entity Type";
final List<NamedBar> eventsByEventType =
_analyticsService.getBarChart(AnalyticsService.DATAHUB_USAGE_EVENT_INDEX, Optional.of(dateRange),
_analyticsService.getBarChart(AnalyticsService.DATAHUB_USAGE_EVENT_INDEX, Optional.of(lastWeekDateRange),
ImmutableList.of("entityType.keyword", "actionType.keyword"),
ImmutableMap.of("type", ImmutableList.of("EntityActionEvent")), Optional.empty());
charts.add(BarChart.builder().setTitle(title4).setBars(eventsByEventType).build());
charts.add(BarChart.builder().setTitle(actionsByTypeTitle).setBars(eventsByEventType).build());

// Chart 5: Table Chart
final String title5 = "Top Viewed Dataset";
// Chart 6: Table Chart
final String topViewedTitle = "Top Viewed Dataset";
final List<String> columns5 = ImmutableList.of("Dataset", "#Views");

final List<Row> topViewedDatasets =
_analyticsService.getTopNTableChart(AnalyticsService.DATAHUB_USAGE_EVENT_INDEX, Optional.of(dateRange),
_analyticsService.getTopNTableChart(AnalyticsService.DATAHUB_USAGE_EVENT_INDEX, Optional.of(lastWeekDateRange),
"dataset_name.keyword", ImmutableMap.of("type", ImmutableList.of("EntityViewEvent")), Optional.empty(), 10);
charts.add(TableChart.builder().setTitle(title5).setColumns(columns5).setRows(topViewedDatasets).build());
charts.add(TableChart.builder().setTitle(topViewedTitle).setColumns(columns5).setRows(topViewedDatasets).build());

return charts;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something the formatter required?

public class AnalyticsService {

private final Logger _logger = LoggerFactory.getLogger(AnalyticsService.class.getName());
Expand Down