Skip to content

Commit 6073cad

Browse files
algolia-botcdhawkemillotp
committed
feat(specs): add estimate path and responses [skip-bc] (generated)
algolia/api-clients-automation#4057 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Christopher Hawke <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent a95ae47 commit 6073cad

File tree

6 files changed

+213
-12
lines changed

6 files changed

+213
-12
lines changed

Sources/Abtesting/AbtestingClient.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,53 @@ open class AbtestingClient {
384384
)
385385
}
386386

387+
/// - parameter estimateABTestRequest: (body)
388+
/// - returns: EstimateABTestResponse
389+
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
390+
open func estimateABTest(
391+
estimateABTestRequest: EstimateABTestRequest,
392+
requestOptions: RequestOptions? = nil
393+
) async throws -> EstimateABTestResponse {
394+
let response: Response<EstimateABTestResponse> = try await estimateABTestWithHTTPInfo(
395+
estimateABTestRequest: estimateABTestRequest,
396+
requestOptions: requestOptions
397+
)
398+
399+
guard let body = response.body else {
400+
throw AlgoliaError.missingData
401+
}
402+
403+
return body
404+
}
405+
406+
// Given the traffic percentage and the expected effect size, this endpoint estimates the sample size and duration
407+
// of an A/B test based on historical traffic.
408+
// Required API Key ACLs:
409+
// - analytics
410+
//
411+
// - parameter estimateABTestRequest: (body)
412+
// - returns: RequestBuilder<EstimateABTestResponse>
413+
414+
open func estimateABTestWithHTTPInfo(
415+
estimateABTestRequest: EstimateABTestRequest,
416+
requestOptions userRequestOptions: RequestOptions? = nil
417+
) async throws -> Response<EstimateABTestResponse> {
418+
let resourcePath = "/2/abtests/estimate"
419+
let body = estimateABTestRequest
420+
let queryParameters: [String: Any?]? = nil
421+
422+
let nillableHeaders: [String: Any?]? = nil
423+
424+
let headers = APIHelper.rejectNilHeaders(nillableHeaders)
425+
426+
return try await self.transporter.send(
427+
method: "POST",
428+
path: resourcePath,
429+
data: body,
430+
requestOptions: RequestOptions(headers: headers, queryParameters: queryParameters) + userRequestOptions
431+
)
432+
}
433+
387434
/// - parameter id: (path) Unique A/B test identifier.
388435
/// - returns: ABTest
389436
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)

Sources/Abtesting/Models/Effect.swift renamed to Sources/Abtesting/Models/EffectMetric.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import Foundation
77
#endif
88

99
/// Metric for which you want to detect the smallest relative difference.
10-
public enum Effect: String, Codable, CaseIterable {
10+
public enum EffectMetric: String, Codable, CaseIterable {
1111
case addToCartRate
1212
case clickThroughRate
1313
case conversionRate
1414
case purchaseRate
1515
}
1616

17-
extension Effect: Hashable {}
17+
extension EffectMetric: Hashable {}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on
2+
// https://github.com/algolia/api-clients-automation. DO NOT EDIT.
3+
4+
import Foundation
5+
#if canImport(Core)
6+
import Core
7+
#endif
8+
9+
public struct EstimateABTestRequest: Codable, JSONEncodable {
10+
public var configuration: EstimateConfiguration
11+
/// A/B test variants.
12+
public var variants: [AddABTestsVariant]
13+
14+
public init(configuration: EstimateConfiguration, variants: [AddABTestsVariant]) {
15+
self.configuration = configuration
16+
self.variants = variants
17+
}
18+
19+
public enum CodingKeys: String, CodingKey, CaseIterable {
20+
case configuration
21+
case variants
22+
}
23+
24+
// Encodable protocol methods
25+
26+
public func encode(to encoder: Encoder) throws {
27+
var container = encoder.container(keyedBy: CodingKeys.self)
28+
try container.encode(self.configuration, forKey: .configuration)
29+
try container.encode(self.variants, forKey: .variants)
30+
}
31+
}
32+
33+
extension EstimateABTestRequest: Equatable {
34+
public static func ==(lhs: EstimateABTestRequest, rhs: EstimateABTestRequest) -> Bool {
35+
lhs.configuration == rhs.configuration &&
36+
lhs.variants == rhs.variants
37+
}
38+
}
39+
40+
extension EstimateABTestRequest: Hashable {
41+
public func hash(into hasher: inout Hasher) {
42+
hasher.combine(self.configuration.hashValue)
43+
hasher.combine(self.variants.hashValue)
44+
}
45+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on
2+
// https://github.com/algolia/api-clients-automation. DO NOT EDIT.
3+
4+
import Foundation
5+
#if canImport(Core)
6+
import Core
7+
#endif
8+
9+
public struct EstimateABTestResponse: Codable, JSONEncodable {
10+
/// Estimated number of days needed to reach the sample sizes required for detecting the configured effect. This
11+
/// value is based on historical traffic.
12+
public var durationDays: Int64?
13+
/// Number of tracked searches needed to be able to detect the configured effect for the control variant.
14+
public var controlSampleSize: Int64?
15+
/// Number of tracked searches needed to be able to detect the configured effect for the experiment variant.
16+
public var experimentSampleSize: Int64?
17+
18+
public init(durationDays: Int64? = nil, controlSampleSize: Int64? = nil, experimentSampleSize: Int64? = nil) {
19+
self.durationDays = durationDays
20+
self.controlSampleSize = controlSampleSize
21+
self.experimentSampleSize = experimentSampleSize
22+
}
23+
24+
public enum CodingKeys: String, CodingKey, CaseIterable {
25+
case durationDays
26+
case controlSampleSize
27+
case experimentSampleSize
28+
}
29+
30+
// Encodable protocol methods
31+
32+
public func encode(to encoder: Encoder) throws {
33+
var container = encoder.container(keyedBy: CodingKeys.self)
34+
try container.encodeIfPresent(self.durationDays, forKey: .durationDays)
35+
try container.encodeIfPresent(self.controlSampleSize, forKey: .controlSampleSize)
36+
try container.encodeIfPresent(self.experimentSampleSize, forKey: .experimentSampleSize)
37+
}
38+
}
39+
40+
extension EstimateABTestResponse: Equatable {
41+
public static func ==(lhs: EstimateABTestResponse, rhs: EstimateABTestResponse) -> Bool {
42+
lhs.durationDays == rhs.durationDays &&
43+
lhs.controlSampleSize == rhs.controlSampleSize &&
44+
lhs.experimentSampleSize == rhs.experimentSampleSize
45+
}
46+
}
47+
48+
extension EstimateABTestResponse: Hashable {
49+
public func hash(into hasher: inout Hasher) {
50+
hasher.combine(self.durationDays?.hashValue)
51+
hasher.combine(self.controlSampleSize?.hashValue)
52+
hasher.combine(self.experimentSampleSize?.hashValue)
53+
}
54+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on
2+
// https://github.com/algolia/api-clients-automation. DO NOT EDIT.
3+
4+
import Foundation
5+
#if canImport(Core)
6+
import Core
7+
#endif
8+
9+
/// A/B test configuration for estimating the sample size and duration using minimum detectable effect.
10+
public struct EstimateConfiguration: Codable, JSONEncodable {
11+
public var outliers: Outliers?
12+
public var emptySearch: EmptySearch?
13+
public var minimumDetectableEffect: MinimumDetectableEffect
14+
15+
public init(
16+
outliers: Outliers? = nil,
17+
emptySearch: EmptySearch? = nil,
18+
minimumDetectableEffect: MinimumDetectableEffect
19+
) {
20+
self.outliers = outliers
21+
self.emptySearch = emptySearch
22+
self.minimumDetectableEffect = minimumDetectableEffect
23+
}
24+
25+
public enum CodingKeys: String, CodingKey, CaseIterable {
26+
case outliers
27+
case emptySearch
28+
case minimumDetectableEffect
29+
}
30+
31+
// Encodable protocol methods
32+
33+
public func encode(to encoder: Encoder) throws {
34+
var container = encoder.container(keyedBy: CodingKeys.self)
35+
try container.encodeIfPresent(self.outliers, forKey: .outliers)
36+
try container.encodeIfPresent(self.emptySearch, forKey: .emptySearch)
37+
try container.encode(self.minimumDetectableEffect, forKey: .minimumDetectableEffect)
38+
}
39+
}
40+
41+
extension EstimateConfiguration: Equatable {
42+
public static func ==(lhs: EstimateConfiguration, rhs: EstimateConfiguration) -> Bool {
43+
lhs.outliers == rhs.outliers &&
44+
lhs.emptySearch == rhs.emptySearch &&
45+
lhs.minimumDetectableEffect == rhs.minimumDetectableEffect
46+
}
47+
}
48+
49+
extension EstimateConfiguration: Hashable {
50+
public func hash(into hasher: inout Hasher) {
51+
hasher.combine(self.outliers?.hashValue)
52+
hasher.combine(self.emptySearch?.hashValue)
53+
hasher.combine(self.minimumDetectableEffect.hashValue)
54+
}
55+
}

Sources/Abtesting/Models/MinimumDetectableEffect.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,38 @@ import Foundation
1010
public struct MinimumDetectableEffect: Codable, JSONEncodable {
1111
/// Smallest difference in an observable metric between variants. For example, to detect a 10% difference between
1212
/// variants, set this value to 0.1.
13-
public var size: Double?
14-
public var effect: Effect?
13+
public var size: Double
14+
public var metric: EffectMetric
1515

16-
public init(size: Double? = nil, effect: Effect? = nil) {
16+
public init(size: Double, metric: EffectMetric) {
1717
self.size = size
18-
self.effect = effect
18+
self.metric = metric
1919
}
2020

2121
public enum CodingKeys: String, CodingKey, CaseIterable {
2222
case size
23-
case effect
23+
case metric
2424
}
2525

2626
// Encodable protocol methods
2727

2828
public func encode(to encoder: Encoder) throws {
2929
var container = encoder.container(keyedBy: CodingKeys.self)
30-
try container.encodeIfPresent(self.size, forKey: .size)
31-
try container.encodeIfPresent(self.effect, forKey: .effect)
30+
try container.encode(self.size, forKey: .size)
31+
try container.encode(self.metric, forKey: .metric)
3232
}
3333
}
3434

3535
extension MinimumDetectableEffect: Equatable {
3636
public static func ==(lhs: MinimumDetectableEffect, rhs: MinimumDetectableEffect) -> Bool {
3737
lhs.size == rhs.size &&
38-
lhs.effect == rhs.effect
38+
lhs.metric == rhs.metric
3939
}
4040
}
4141

4242
extension MinimumDetectableEffect: Hashable {
4343
public func hash(into hasher: inout Hasher) {
44-
hasher.combine(self.size?.hashValue)
45-
hasher.combine(self.effect?.hashValue)
44+
hasher.combine(self.size.hashValue)
45+
hasher.combine(self.metric.hashValue)
4646
}
4747
}

0 commit comments

Comments
 (0)