Skip to content

Commit 3aabb18

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 d9c739a commit 3aabb18

File tree

6 files changed

+387
-7
lines changed

6 files changed

+387
-7
lines changed

algoliasearch/abtesting/client.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
from algoliasearch.abtesting.models.ab_test import ABTest
2424
from algoliasearch.abtesting.models.ab_test_response import ABTestResponse
2525
from algoliasearch.abtesting.models.add_ab_tests_request import AddABTestsRequest
26+
from algoliasearch.abtesting.models.estimate_ab_test_request import (
27+
EstimateABTestRequest,
28+
)
29+
from algoliasearch.abtesting.models.estimate_ab_test_response import (
30+
EstimateABTestResponse,
31+
)
2632
from algoliasearch.abtesting.models.list_ab_tests_response import ListABTestsResponse
2733
from algoliasearch.abtesting.models.schedule_ab_test_response import (
2834
ScheduleABTestResponse,
@@ -567,6 +573,63 @@ async def delete_ab_test(
567573
resp = await self.delete_ab_test_with_http_info(id, request_options)
568574
return resp.deserialize(ABTestResponse, resp.raw_data)
569575

576+
async def estimate_ab_test_with_http_info(
577+
self,
578+
estimate_ab_test_request: Union[EstimateABTestRequest, dict[str, Any]],
579+
request_options: Optional[Union[dict, RequestOptions]] = None,
580+
) -> ApiResponse[str]:
581+
"""
582+
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.
583+
584+
Required API Key ACLs:
585+
- analytics
586+
587+
:param estimate_ab_test_request: (required)
588+
:type estimate_ab_test_request: EstimateABTestRequest
589+
: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)
590+
:return: Returns the raw algoliasearch 'APIResponse' object.
591+
"""
592+
593+
if estimate_ab_test_request is None:
594+
raise ValueError(
595+
"Parameter `estimate_ab_test_request` is required when calling `estimate_ab_test`."
596+
)
597+
598+
_data = {}
599+
if estimate_ab_test_request is not None:
600+
_data = estimate_ab_test_request
601+
602+
return await self._transporter.request(
603+
verb=Verb.POST,
604+
path="/2/abtests/estimate",
605+
request_options=self._request_options.merge(
606+
data=dumps(body_serializer(_data)),
607+
user_request_options=request_options,
608+
),
609+
use_read_transporter=False,
610+
)
611+
612+
async def estimate_ab_test(
613+
self,
614+
estimate_ab_test_request: Union[EstimateABTestRequest, dict[str, Any]],
615+
request_options: Optional[Union[dict, RequestOptions]] = None,
616+
) -> EstimateABTestResponse:
617+
"""
618+
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.
619+
620+
Required API Key ACLs:
621+
- analytics
622+
623+
:param estimate_ab_test_request: (required)
624+
:type estimate_ab_test_request: EstimateABTestRequest
625+
: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)
626+
:return: Returns the deserialized response in a 'EstimateABTestResponse' result object.
627+
"""
628+
resp = await self.estimate_ab_test_with_http_info(
629+
estimate_ab_test_request, request_options
630+
)
631+
return resp.deserialize(EstimateABTestResponse, resp.raw_data)
632+
570633
async def get_ab_test_with_http_info(
571634
self,
572635
id: Annotated[StrictInt, Field(description="Unique A/B test identifier.")],
@@ -1347,6 +1410,63 @@ def delete_ab_test(
13471410
resp = self.delete_ab_test_with_http_info(id, request_options)
13481411
return resp.deserialize(ABTestResponse, resp.raw_data)
13491412

1413+
def estimate_ab_test_with_http_info(
1414+
self,
1415+
estimate_ab_test_request: Union[EstimateABTestRequest, dict[str, Any]],
1416+
request_options: Optional[Union[dict, RequestOptions]] = None,
1417+
) -> ApiResponse[str]:
1418+
"""
1419+
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.
1420+
1421+
Required API Key ACLs:
1422+
- analytics
1423+
1424+
:param estimate_ab_test_request: (required)
1425+
:type estimate_ab_test_request: EstimateABTestRequest
1426+
: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)
1427+
:return: Returns the raw algoliasearch 'APIResponse' object.
1428+
"""
1429+
1430+
if estimate_ab_test_request is None:
1431+
raise ValueError(
1432+
"Parameter `estimate_ab_test_request` is required when calling `estimate_ab_test`."
1433+
)
1434+
1435+
_data = {}
1436+
if estimate_ab_test_request is not None:
1437+
_data = estimate_ab_test_request
1438+
1439+
return self._transporter.request(
1440+
verb=Verb.POST,
1441+
path="/2/abtests/estimate",
1442+
request_options=self._request_options.merge(
1443+
data=dumps(body_serializer(_data)),
1444+
user_request_options=request_options,
1445+
),
1446+
use_read_transporter=False,
1447+
)
1448+
1449+
def estimate_ab_test(
1450+
self,
1451+
estimate_ab_test_request: Union[EstimateABTestRequest, dict[str, Any]],
1452+
request_options: Optional[Union[dict, RequestOptions]] = None,
1453+
) -> EstimateABTestResponse:
1454+
"""
1455+
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.
1456+
1457+
Required API Key ACLs:
1458+
- analytics
1459+
1460+
:param estimate_ab_test_request: (required)
1461+
:type estimate_ab_test_request: EstimateABTestRequest
1462+
: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)
1463+
:return: Returns the deserialized response in a 'EstimateABTestResponse' result object.
1464+
"""
1465+
resp = self.estimate_ab_test_with_http_info(
1466+
estimate_ab_test_request, request_options
1467+
)
1468+
return resp.deserialize(EstimateABTestResponse, resp.raw_data)
1469+
13501470
def get_ab_test_with_http_info(
13511471
self,
13521472
id: Annotated[StrictInt, Field(description="Unique A/B test identifier.")],

algoliasearch/abtesting/models/effect.py renamed to algoliasearch/abtesting/models/effect_metric.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from typing_extensions import Self
1717

1818

19-
class Effect(str, Enum):
19+
class EffectMetric(str, Enum):
2020
"""
2121
Metric for which you want to detect the smallest relative difference.
2222
"""
@@ -34,5 +34,5 @@ class Effect(str, Enum):
3434

3535
@classmethod
3636
def from_json(cls, json_str: str) -> Self:
37-
"""Create an instance of Effect from a JSON string"""
37+
"""Create an instance of EffectMetric from a JSON string"""
3838
return cls(loads(json_str))
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# coding: utf-8
2+
3+
"""
4+
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.
5+
"""
6+
7+
from __future__ import annotations
8+
9+
from json import loads
10+
from sys import version_info
11+
from typing import Any, Dict, List, Optional
12+
13+
from pydantic import BaseModel, ConfigDict
14+
15+
if version_info >= (3, 11):
16+
from typing import Self
17+
else:
18+
from typing_extensions import Self
19+
20+
21+
from algoliasearch.abtesting.models.add_ab_tests_variant import AddABTestsVariant
22+
from algoliasearch.abtesting.models.estimate_configuration import EstimateConfiguration
23+
24+
_ALIASES = {
25+
"configuration": "configuration",
26+
"variants": "variants",
27+
}
28+
29+
30+
def _alias_generator(name: str) -> str:
31+
return _ALIASES.get(name, name)
32+
33+
34+
class EstimateABTestRequest(BaseModel):
35+
"""
36+
EstimateABTestRequest
37+
"""
38+
39+
configuration: EstimateConfiguration
40+
variants: List[AddABTestsVariant]
41+
""" A/B test variants. """
42+
43+
model_config = ConfigDict(
44+
use_enum_values=True,
45+
populate_by_name=True,
46+
validate_assignment=True,
47+
protected_namespaces=(),
48+
alias_generator=_alias_generator,
49+
)
50+
51+
def to_json(self) -> str:
52+
return self.model_dump_json(by_alias=True, exclude_unset=True)
53+
54+
@classmethod
55+
def from_json(cls, json_str: str) -> Optional[Self]:
56+
"""Create an instance of EstimateABTestRequest from a JSON string"""
57+
return cls.from_dict(loads(json_str))
58+
59+
def to_dict(self) -> Dict[str, Any]:
60+
"""Return the dictionary representation of the model using alias."""
61+
return self.model_dump(
62+
by_alias=True,
63+
exclude_none=True,
64+
exclude_unset=True,
65+
)
66+
67+
@classmethod
68+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
69+
"""Create an instance of EstimateABTestRequest from a dict"""
70+
if obj is None:
71+
return None
72+
73+
if not isinstance(obj, dict):
74+
return cls.model_validate(obj)
75+
76+
obj["configuration"] = (
77+
EstimateConfiguration.from_dict(obj["configuration"])
78+
if obj.get("configuration") is not None
79+
else None
80+
)
81+
obj["variants"] = (
82+
[AddABTestsVariant.from_dict(_item) for _item in obj["variants"]]
83+
if obj.get("variants") is not None
84+
else None
85+
)
86+
87+
return cls.model_validate(obj)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# coding: utf-8
2+
3+
"""
4+
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.
5+
"""
6+
7+
from __future__ import annotations
8+
9+
from json import loads
10+
from sys import version_info
11+
from typing import Any, Dict, Optional
12+
13+
from pydantic import BaseModel, ConfigDict
14+
15+
if version_info >= (3, 11):
16+
from typing import Self
17+
else:
18+
from typing_extensions import Self
19+
20+
21+
_ALIASES = {
22+
"duration_days": "durationDays",
23+
"control_sample_size": "controlSampleSize",
24+
"experiment_sample_size": "experimentSampleSize",
25+
}
26+
27+
28+
def _alias_generator(name: str) -> str:
29+
return _ALIASES.get(name, name)
30+
31+
32+
class EstimateABTestResponse(BaseModel):
33+
"""
34+
EstimateABTestResponse
35+
"""
36+
37+
duration_days: Optional[int] = None
38+
""" Estimated number of days needed to reach the sample sizes required for detecting the configured effect. This value is based on historical traffic. """
39+
control_sample_size: Optional[int] = None
40+
""" Number of tracked searches needed to be able to detect the configured effect for the control variant. """
41+
experiment_sample_size: Optional[int] = None
42+
""" Number of tracked searches needed to be able to detect the configured effect for the experiment variant. """
43+
44+
model_config = ConfigDict(
45+
use_enum_values=True,
46+
populate_by_name=True,
47+
validate_assignment=True,
48+
protected_namespaces=(),
49+
alias_generator=_alias_generator,
50+
)
51+
52+
def to_json(self) -> str:
53+
return self.model_dump_json(by_alias=True, exclude_unset=True)
54+
55+
@classmethod
56+
def from_json(cls, json_str: str) -> Optional[Self]:
57+
"""Create an instance of EstimateABTestResponse from a JSON string"""
58+
return cls.from_dict(loads(json_str))
59+
60+
def to_dict(self) -> Dict[str, Any]:
61+
"""Return the dictionary representation of the model using alias."""
62+
return self.model_dump(
63+
by_alias=True,
64+
exclude_none=True,
65+
exclude_unset=True,
66+
)
67+
68+
@classmethod
69+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
70+
"""Create an instance of EstimateABTestResponse from a dict"""
71+
if obj is None:
72+
return None
73+
74+
if not isinstance(obj, dict):
75+
return cls.model_validate(obj)
76+
77+
return cls.model_validate(obj)

0 commit comments

Comments
 (0)