Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,11 @@ private extension AnalyticsHubViewModel {
latestDateToInclude: Date,
forceRefresh: Bool) async throws -> OrderStatsV4 {
try await withCheckedThrowingContinuation { continuation in
// TODO: get unit and quantity from the selected period
let unit: StatsGranularityV4 = .daily
let quantity = 31

let action = StatsActionV4.retrieveCustomStats(siteID: siteID,
unit: unit,
unit: timeRangeSelectionType.granularity,
earliestDateToInclude: earliestDateToInclude,
latestDateToInclude: latestDateToInclude,
quantity: quantity,
quantity: timeRangeSelectionType.intervalSize,
forceRefresh: forceRefresh) { result in
continuation.resume(with: result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,41 @@ extension AnalyticsHubTimeRangeSelection {
}
}

/// The granularity that should be used to request stats from the given SelectedType
///
var granularity: StatsGranularityV4 {
switch self {
case .today, .yesterday:
return .hourly
case .weekToDate, .lastWeek:
return .daily
case .monthToDate, .lastMonth:
return .daily
case .quarterToDate, .lastQuarter:
return .weekly
case .yearToDate, .lastYear:
return .monthly
}
}

/// The response interval size that should be used to request stats from the given SelectedType
/// in order to proper determine the stats charts and changes
///
var intervalSize: Int {
switch self {
case .today, .yesterday:
return 24
case .weekToDate, .lastWeek:
return 7
case .monthToDate, .lastMonth:
return 31
case .quarterToDate, .lastQuarter:
return 13
case .yearToDate, .lastYear:
return 12
}
}

init(_ statsTimeRange: StatsTimeRangeV4) {
switch statsTimeRange {
case .today:
Expand Down