Skip to content

Commit

Permalink
feat(specs): add estimate path and responses [skip-bc] (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#4057

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Christopher Hawke <69921547+cdhawke@users.noreply.github.com>
Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
  • Loading branch information
3 people committed Nov 7, 2024
1 parent 669fbab commit ec90bd4
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,38 @@ package algoliasearch.abtesting

import org.json4s._

sealed trait Effect
sealed trait EffectMetric

/** Metric for which you want to detect the smallest relative difference.
*/
object Effect {
case object AddToCartRate extends Effect {
object EffectMetric {
case object AddToCartRate extends EffectMetric {
override def toString = "addToCartRate"
}
case object ClickThroughRate extends Effect {
case object ClickThroughRate extends EffectMetric {
override def toString = "clickThroughRate"
}
case object ConversionRate extends Effect {
case object ConversionRate extends EffectMetric {
override def toString = "conversionRate"
}
case object PurchaseRate extends Effect {
case object PurchaseRate extends EffectMetric {
override def toString = "purchaseRate"
}
val values: Seq[Effect] = Seq(AddToCartRate, ClickThroughRate, ConversionRate, PurchaseRate)
val values: Seq[EffectMetric] = Seq(AddToCartRate, ClickThroughRate, ConversionRate, PurchaseRate)

def withName(name: String): Effect = Effect.values
def withName(name: String): EffectMetric = EffectMetric.values
.find(_.toString == name)
.getOrElse(throw new MappingException(s"Unknown Effect value: $name"))
.getOrElse(throw new MappingException(s"Unknown EffectMetric value: $name"))
}

class EffectSerializer
extends CustomSerializer[Effect](_ =>
class EffectMetricSerializer
extends CustomSerializer[EffectMetric](_ =>
(
{
case JString(value) => Effect.withName(value)
case JString(value) => EffectMetric.withName(value)
case JNull => null
},
{ case value: Effect =>
{ case value: EffectMetric =>
JString(value.toString)
}
)
Expand Down
35 changes: 35 additions & 0 deletions src/main/scala/algoliasearch/abtesting/EstimateABTestRequest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/** A/B Testing API The Algolia A/B Testing API lets you manage your Algolia A/B tests to optimize your search
* experience. ## Base URLs The base URLs for requests to the A/B testing API are: - `https://analytics.us.algolia.com`
* \- `https://analytics.de.algolia.com` - `https://analytics.algolia.com` (routes requests to the closest of the above
* servers, based on your geographical location) Use the URL that matches your [analytics
* region](https://dashboard.algolia.com/account/infrastructure/analytics). **All requests must use HTTPS.** ##
* Availability and authentication Access to the A/B testing API is available as part of the [Premium or Elevate
* plans](https://www.algolia.com/pricing). To authenticate your API requests, add these headers: -
* `x-algolia-application-id`. Your Algolia application ID. - `x-algolia-api-key`. An API key with the necessary
* permissions to make the request. The required access control list (ACL) to make a request is listed in each
* endpoint's reference. You can find your application ID and API key in the [Algolia
* dashboard](https://dashboard.algolia.com/account). ## Rate limits You can make up to **100 requests per minute per
* app** to the A/B testing API. The response includes headers with information about the limits. ## Parameters Query
* parameters must be [URL-encoded](https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding). Non-ASCII
* characters must be UTF-8 encoded. Plus characters (`+`) are interpreted as spaces. ## Response status and errors The
* A/B testing API returns JSON responses. Since JSON doesn't guarantee any specific ordering, don't rely on the order
* of attributes in the API response. Successful responses return a `2xx` status. Client errors return a `4xx` status.
* Server errors are indicated by a `5xx` status. Error responses have a `message` property with more information. ##
* Version The current version of the A/B Testing API is version 2, as indicated by the `/2/` in each endpoint's URL.
*
* The version of the OpenAPI document: 2.0.0
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech Do not edit the class manually.
*/
package algoliasearch.abtesting

/** EstimateABTestRequest
*
* @param variants
* A/B test variants.
*/
case class EstimateABTestRequest(
configuration: EstimateConfiguration,
variants: Seq[AddABTestsVariant]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/** A/B Testing API The Algolia A/B Testing API lets you manage your Algolia A/B tests to optimize your search
* experience. ## Base URLs The base URLs for requests to the A/B testing API are: - `https://analytics.us.algolia.com`
* \- `https://analytics.de.algolia.com` - `https://analytics.algolia.com` (routes requests to the closest of the above
* servers, based on your geographical location) Use the URL that matches your [analytics
* region](https://dashboard.algolia.com/account/infrastructure/analytics). **All requests must use HTTPS.** ##
* Availability and authentication Access to the A/B testing API is available as part of the [Premium or Elevate
* plans](https://www.algolia.com/pricing). To authenticate your API requests, add these headers: -
* `x-algolia-application-id`. Your Algolia application ID. - `x-algolia-api-key`. An API key with the necessary
* permissions to make the request. The required access control list (ACL) to make a request is listed in each
* endpoint's reference. You can find your application ID and API key in the [Algolia
* dashboard](https://dashboard.algolia.com/account). ## Rate limits You can make up to **100 requests per minute per
* app** to the A/B testing API. The response includes headers with information about the limits. ## Parameters Query
* parameters must be [URL-encoded](https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding). Non-ASCII
* characters must be UTF-8 encoded. Plus characters (`+`) are interpreted as spaces. ## Response status and errors The
* A/B testing API returns JSON responses. Since JSON doesn't guarantee any specific ordering, don't rely on the order
* of attributes in the API response. Successful responses return a `2xx` status. Client errors return a `4xx` status.
* Server errors are indicated by a `5xx` status. Error responses have a `message` property with more information. ##
* Version The current version of the A/B Testing API is version 2, as indicated by the `/2/` in each endpoint's URL.
*
* The version of the OpenAPI document: 2.0.0
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech Do not edit the class manually.
*/
package algoliasearch.abtesting

/** EstimateABTestResponse
*
* @param durationDays
* Estimated number of days needed to reach the sample sizes required for detecting the configured effect. This value
* is based on historical traffic.
* @param controlSampleSize
* Number of tracked searches needed to be able to detect the configured effect for the control variant.
* @param experimentSampleSize
* Number of tracked searches needed to be able to detect the configured effect for the experiment variant.
*/
case class EstimateABTestResponse(
durationDays: Option[Long] = scala.None,
controlSampleSize: Option[Long] = scala.None,
experimentSampleSize: Option[Long] = scala.None
)
33 changes: 33 additions & 0 deletions src/main/scala/algoliasearch/abtesting/EstimateConfiguration.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/** A/B Testing API The Algolia A/B Testing API lets you manage your Algolia A/B tests to optimize your search
* experience. ## Base URLs The base URLs for requests to the A/B testing API are: - `https://analytics.us.algolia.com`
* \- `https://analytics.de.algolia.com` - `https://analytics.algolia.com` (routes requests to the closest of the above
* servers, based on your geographical location) Use the URL that matches your [analytics
* region](https://dashboard.algolia.com/account/infrastructure/analytics). **All requests must use HTTPS.** ##
* Availability and authentication Access to the A/B testing API is available as part of the [Premium or Elevate
* plans](https://www.algolia.com/pricing). To authenticate your API requests, add these headers: -
* `x-algolia-application-id`. Your Algolia application ID. - `x-algolia-api-key`. An API key with the necessary
* permissions to make the request. The required access control list (ACL) to make a request is listed in each
* endpoint's reference. You can find your application ID and API key in the [Algolia
* dashboard](https://dashboard.algolia.com/account). ## Rate limits You can make up to **100 requests per minute per
* app** to the A/B testing API. The response includes headers with information about the limits. ## Parameters Query
* parameters must be [URL-encoded](https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding). Non-ASCII
* characters must be UTF-8 encoded. Plus characters (`+`) are interpreted as spaces. ## Response status and errors The
* A/B testing API returns JSON responses. Since JSON doesn't guarantee any specific ordering, don't rely on the order
* of attributes in the API response. Successful responses return a `2xx` status. Client errors return a `4xx` status.
* Server errors are indicated by a `5xx` status. Error responses have a `message` property with more information. ##
* Version The current version of the A/B Testing API is version 2, as indicated by the `/2/` in each endpoint's URL.
*
* The version of the OpenAPI document: 2.0.0
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech Do not edit the class manually.
*/
package algoliasearch.abtesting

/** A/B test configuration for estimating the sample size and duration using minimum detectable effect.
*/
case class EstimateConfiguration(
outliers: Option[Outliers] = scala.None,
emptySearch: Option[EmptySearch] = scala.None,
minimumDetectableEffect: MinimumDetectableEffect
)
2 changes: 1 addition & 1 deletion src/main/scala/algoliasearch/abtesting/JsonSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.json4s._

object JsonSupport {
private def enumSerializers: Seq[Serializer[_]] = Seq[Serializer[_]]() :+
new EffectSerializer() :+
new EffectMetricSerializer() :+
new StatusSerializer()

private def oneOfsSerializers: Seq[Serializer[_]] = Seq[Serializer[_]]() :+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
package algoliasearch.abtesting

import algoliasearch.abtesting.Effect._
import algoliasearch.abtesting.EffectMetric._

/** Configuration for the smallest difference between test variants you want to detect.
*
Expand All @@ -33,6 +33,6 @@ import algoliasearch.abtesting.Effect._
* variants, set this value to 0.1.
*/
case class MinimumDetectableEffect(
size: Option[Double] = scala.None,
effect: Option[Effect] = scala.None
size: Double,
metric: EffectMetric
)
25 changes: 25 additions & 0 deletions src/main/scala/algoliasearch/api/AbtestingClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import algoliasearch.abtesting.ABTest
import algoliasearch.abtesting.ABTestResponse
import algoliasearch.abtesting.AddABTestsRequest
import algoliasearch.abtesting.ErrorBase
import algoliasearch.abtesting.EstimateABTestRequest
import algoliasearch.abtesting.EstimateABTestResponse
import algoliasearch.abtesting.ListABTestsResponse
import algoliasearch.abtesting.ScheduleABTestResponse
import algoliasearch.abtesting.ScheduleABTestsRequest
Expand Down Expand Up @@ -209,6 +211,29 @@ class AbtestingClient(
execute[ABTestResponse](request, requestOptions)
}

/** Given the traffic percentage and the expected effect size, this endpoint estimates the sample size and duration of
* an A/B test based on historical traffic.
*
* Required API Key ACLs:
* - analytics
*/
def estimateABTest(estimateABTestRequest: EstimateABTestRequest, requestOptions: Option[RequestOptions] = None)(
implicit ec: ExecutionContext
): Future[EstimateABTestResponse] = Future {
requireNotNull(
estimateABTestRequest,
"Parameter `estimateABTestRequest` is required when calling `estimateABTest`."
)

val request = HttpRequest
.builder()
.withMethod("POST")
.withPath(s"/2/abtests/estimate")
.withBody(estimateABTestRequest)
.build()
execute[EstimateABTestResponse](request, requestOptions)
}

/** Retrieves the details for an A/B test by its ID.
*
* Required API Key ACLs:
Expand Down

0 comments on commit ec90bd4

Please sign in to comment.