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 <[email protected]>
Co-authored-by: Christopher Hawke <[email protected]>
Co-authored-by: Pierre Millot <[email protected]>
  • Loading branch information
3 people committed Nov 7, 2024
1 parent d9c739a commit 3aabb18
Show file tree
Hide file tree
Showing 6 changed files with 387 additions and 7 deletions.
120 changes: 120 additions & 0 deletions algoliasearch/abtesting/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
from algoliasearch.abtesting.models.ab_test import ABTest
from algoliasearch.abtesting.models.ab_test_response import ABTestResponse
from algoliasearch.abtesting.models.add_ab_tests_request import AddABTestsRequest
from algoliasearch.abtesting.models.estimate_ab_test_request import (
EstimateABTestRequest,
)
from algoliasearch.abtesting.models.estimate_ab_test_response import (
EstimateABTestResponse,
)
from algoliasearch.abtesting.models.list_ab_tests_response import ListABTestsResponse
from algoliasearch.abtesting.models.schedule_ab_test_response import (
ScheduleABTestResponse,
Expand Down Expand Up @@ -567,6 +573,63 @@ async def delete_ab_test(
resp = await self.delete_ab_test_with_http_info(id, request_options)
return resp.deserialize(ABTestResponse, resp.raw_data)

async def estimate_ab_test_with_http_info(
self,
estimate_ab_test_request: Union[EstimateABTestRequest, dict[str, Any]],
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> ApiResponse[str]:
"""
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
:param estimate_ab_test_request: (required)
:type estimate_ab_test_request: EstimateABTestRequest
:param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
:return: Returns the raw algoliasearch 'APIResponse' object.
"""

if estimate_ab_test_request is None:
raise ValueError(
"Parameter `estimate_ab_test_request` is required when calling `estimate_ab_test`."
)

_data = {}
if estimate_ab_test_request is not None:
_data = estimate_ab_test_request

return await self._transporter.request(
verb=Verb.POST,
path="/2/abtests/estimate",
request_options=self._request_options.merge(
data=dumps(body_serializer(_data)),
user_request_options=request_options,
),
use_read_transporter=False,
)

async def estimate_ab_test(
self,
estimate_ab_test_request: Union[EstimateABTestRequest, dict[str, Any]],
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> EstimateABTestResponse:
"""
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
:param estimate_ab_test_request: (required)
:type estimate_ab_test_request: EstimateABTestRequest
:param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
:return: Returns the deserialized response in a 'EstimateABTestResponse' result object.
"""
resp = await self.estimate_ab_test_with_http_info(
estimate_ab_test_request, request_options
)
return resp.deserialize(EstimateABTestResponse, resp.raw_data)

async def get_ab_test_with_http_info(
self,
id: Annotated[StrictInt, Field(description="Unique A/B test identifier.")],
Expand Down Expand Up @@ -1347,6 +1410,63 @@ def delete_ab_test(
resp = self.delete_ab_test_with_http_info(id, request_options)
return resp.deserialize(ABTestResponse, resp.raw_data)

def estimate_ab_test_with_http_info(
self,
estimate_ab_test_request: Union[EstimateABTestRequest, dict[str, Any]],
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> ApiResponse[str]:
"""
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
:param estimate_ab_test_request: (required)
:type estimate_ab_test_request: EstimateABTestRequest
:param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
:return: Returns the raw algoliasearch 'APIResponse' object.
"""

if estimate_ab_test_request is None:
raise ValueError(
"Parameter `estimate_ab_test_request` is required when calling `estimate_ab_test`."
)

_data = {}
if estimate_ab_test_request is not None:
_data = estimate_ab_test_request

return self._transporter.request(
verb=Verb.POST,
path="/2/abtests/estimate",
request_options=self._request_options.merge(
data=dumps(body_serializer(_data)),
user_request_options=request_options,
),
use_read_transporter=False,
)

def estimate_ab_test(
self,
estimate_ab_test_request: Union[EstimateABTestRequest, dict[str, Any]],
request_options: Optional[Union[dict, RequestOptions]] = None,
) -> EstimateABTestResponse:
"""
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
:param estimate_ab_test_request: (required)
:type estimate_ab_test_request: EstimateABTestRequest
:param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional)
:return: Returns the deserialized response in a 'EstimateABTestResponse' result object.
"""
resp = self.estimate_ab_test_with_http_info(
estimate_ab_test_request, request_options
)
return resp.deserialize(EstimateABTestResponse, resp.raw_data)

def get_ab_test_with_http_info(
self,
id: Annotated[StrictInt, Field(description="Unique A/B test identifier.")],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing_extensions import Self


class Effect(str, Enum):
class EffectMetric(str, Enum):
"""
Metric for which you want to detect the smallest relative difference.
"""
Expand All @@ -34,5 +34,5 @@ class Effect(str, Enum):

@classmethod
def from_json(cls, json_str: str) -> Self:
"""Create an instance of Effect from a JSON string"""
"""Create an instance of EffectMetric from a JSON string"""
return cls(loads(json_str))
87 changes: 87 additions & 0 deletions algoliasearch/abtesting/models/estimate_ab_test_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# coding: utf-8

"""
Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
"""

from __future__ import annotations

from json import loads
from sys import version_info
from typing import Any, Dict, List, Optional

from pydantic import BaseModel, ConfigDict

if version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self


from algoliasearch.abtesting.models.add_ab_tests_variant import AddABTestsVariant
from algoliasearch.abtesting.models.estimate_configuration import EstimateConfiguration

_ALIASES = {
"configuration": "configuration",
"variants": "variants",
}


def _alias_generator(name: str) -> str:
return _ALIASES.get(name, name)


class EstimateABTestRequest(BaseModel):
"""
EstimateABTestRequest
"""

configuration: EstimateConfiguration
variants: List[AddABTestsVariant]
""" A/B test variants. """

model_config = ConfigDict(
use_enum_values=True,
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
alias_generator=_alias_generator,
)

def to_json(self) -> str:
return self.model_dump_json(by_alias=True, exclude_unset=True)

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of EstimateABTestRequest from a JSON string"""
return cls.from_dict(loads(json_str))

def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias."""
return self.model_dump(
by_alias=True,
exclude_none=True,
exclude_unset=True,
)

@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of EstimateABTestRequest from a dict"""
if obj is None:
return None

if not isinstance(obj, dict):
return cls.model_validate(obj)

obj["configuration"] = (
EstimateConfiguration.from_dict(obj["configuration"])
if obj.get("configuration") is not None
else None
)
obj["variants"] = (
[AddABTestsVariant.from_dict(_item) for _item in obj["variants"]]
if obj.get("variants") is not None
else None
)

return cls.model_validate(obj)
77 changes: 77 additions & 0 deletions algoliasearch/abtesting/models/estimate_ab_test_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# coding: utf-8

"""
Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
"""

from __future__ import annotations

from json import loads
from sys import version_info
from typing import Any, Dict, Optional

from pydantic import BaseModel, ConfigDict

if version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self


_ALIASES = {
"duration_days": "durationDays",
"control_sample_size": "controlSampleSize",
"experiment_sample_size": "experimentSampleSize",
}


def _alias_generator(name: str) -> str:
return _ALIASES.get(name, name)


class EstimateABTestResponse(BaseModel):
"""
EstimateABTestResponse
"""

duration_days: Optional[int] = None
""" Estimated number of days needed to reach the sample sizes required for detecting the configured effect. This value is based on historical traffic. """
control_sample_size: Optional[int] = None
""" Number of tracked searches needed to be able to detect the configured effect for the control variant. """
experiment_sample_size: Optional[int] = None
""" Number of tracked searches needed to be able to detect the configured effect for the experiment variant. """

model_config = ConfigDict(
use_enum_values=True,
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
alias_generator=_alias_generator,
)

def to_json(self) -> str:
return self.model_dump_json(by_alias=True, exclude_unset=True)

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of EstimateABTestResponse from a JSON string"""
return cls.from_dict(loads(json_str))

def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias."""
return self.model_dump(
by_alias=True,
exclude_none=True,
exclude_unset=True,
)

@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of EstimateABTestResponse from a dict"""
if obj is None:
return None

if not isinstance(obj, dict):
return cls.model_validate(obj)

return cls.model_validate(obj)
Loading

0 comments on commit 3aabb18

Please sign in to comment.