Skip to content

Commit 07a2e93

Browse files
authored
feat(specs): predict segments (#1013)
1 parent f8a7722 commit 07a2e93

File tree

13 files changed

+564
-0
lines changed

13 files changed

+564
-0
lines changed

specs/predict/common/parameters.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ userID:
66
type: string
77
description: User ID for authenticated users or cookie ID for non-authenticated repeated users (visitors).
88

9+
segmentID:
10+
name: segmentID
11+
in: path
12+
required: true
13+
schema:
14+
type: string
15+
description: The ID of the Segment to fetch.
16+
17+
type:
18+
name: type
19+
in: query
20+
schema:
21+
$ref: '../responses/Segment.yml#/segmentType'
22+
description: The type of segments to fetch.
23+
924
modelID:
1025
name: modelID
1126
in: path
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
createSegmentParams:
2+
type: object
3+
required:
4+
- name
5+
- conditions
6+
properties:
7+
name:
8+
$ref: '#/name'
9+
conditions:
10+
$ref: '#/conditions'
11+
12+
updateSegmentParams:
13+
oneOf:
14+
- $ref: '#/segmentNameParam'
15+
- $ref: '#/segmentConditionsParam'
16+
- $ref: '#/allUpdateSegmentParams'
17+
18+
allUpdateSegmentParams:
19+
allOf:
20+
- $ref: '#/segmentNameParam'
21+
- $ref: '#/segmentConditionsParam'
22+
23+
segmentNameParam:
24+
type: object
25+
properties:
26+
name:
27+
$ref: '#/name'
28+
29+
segmentConditionsParam:
30+
type: object
31+
properties:
32+
conditions:
33+
$ref: '#/conditions'
34+
35+
name:
36+
type: string
37+
description: The name or description of the segment.
38+
39+
conditions:
40+
type: string
41+
description: The filters that define the segment, defined in the same way as filters for Rules.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
get:
2+
tags:
3+
- segments
4+
operationId: fetchAllSegments
5+
description: Get the list of segments with their configuration.
6+
summary: Get all segments.
7+
parameters:
8+
- $ref: '../../common/parameters.yml#/type'
9+
responses:
10+
'200':
11+
description: OK
12+
content:
13+
application/json:
14+
schema:
15+
$ref: '../../responses/Segment.yml#/fetchAllSegmentsResponse'
16+
'404':
17+
$ref: '../../../common/responses/IndexNotFound.yml'
18+
'422':
19+
$ref: '../../../common/responses/StatusUnprocessableEntity.yml'
20+
'500':
21+
$ref: '../../../common/responses/InternalError.yml'
22+
post:
23+
tags:
24+
- segments
25+
operationId: createSegment
26+
summary: Create a segment.
27+
description: Create a new segment. All segments added by this endpoint will have a computed type. The endpoint receives a filters parameter, with a syntax similar to filters for Rules.
28+
requestBody:
29+
required: true
30+
content:
31+
application/json:
32+
schema:
33+
$ref: '../../common/schemas/SegmentsParams.yml#/createSegmentParams'
34+
responses:
35+
'200':
36+
description: OK
37+
content:
38+
application/json:
39+
schema:
40+
$ref: '../../responses/Segment.yml#/createSegmentResponse'
41+
'400':
42+
$ref: '../../../common/responses/IndexNotFound.yml'
43+
'401':
44+
$ref: '../../../common/responses/Unauthorized.yml'
45+
'422':
46+
$ref: '../../../common/responses/StatusUnprocessableEntity.yml'
47+
'500':
48+
$ref: '../../../common/responses/InternalError.yml'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
post:
2+
tags:
3+
- segments
4+
operationId: getSegmentUsers
5+
summary: Get segment users.
6+
description: Get the profiles of users that belong to a segment.
7+
parameters:
8+
- $ref: '../../common/parameters.yml#/segmentID'
9+
requestBody:
10+
required: true
11+
content:
12+
application/json:
13+
schema:
14+
$ref: '../../common/schemas/Params.yml#/fetchAllUserProfilesParams'
15+
responses:
16+
'200':
17+
description: OK
18+
content:
19+
application/json:
20+
schema:
21+
$ref: '../../responses/Segment.yml#/getSegmentUsersResponse'
22+
'400':
23+
$ref: '../../../common/responses/BadRequest.yml'
24+
'401':
25+
$ref: '../../../common/responses/Unauthorized.yml'
26+
'404':
27+
$ref: '../../../common/responses/IndexNotFound.yml'
28+
'422':
29+
$ref: '../../../common/responses/UnprocessableEntity.yml'
30+
'500':
31+
$ref: '../../../common/responses/InternalError.yml'
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
get:
2+
tags:
3+
- segments
4+
operationId: fetchSegment
5+
description: Get the segment configuration.
6+
summary: Get the segment configuration.
7+
parameters:
8+
- $ref: '../../common/parameters.yml#/segmentID'
9+
responses:
10+
'200':
11+
description: OK
12+
content:
13+
application/json:
14+
schema:
15+
title: fetchSegmentResponse
16+
$ref: '../../responses/Segment.yml#/segment'
17+
'404':
18+
$ref: '../../../common/responses/IndexNotFound.yml'
19+
'422':
20+
$ref: '../../../common/responses/StatusUnprocessableEntity.yml'
21+
'500':
22+
$ref: '../../../common/responses/InternalError.yml'
23+
24+
post:
25+
tags:
26+
- segments
27+
operationId: updateSegment
28+
description: Update a segment’s configuration.
29+
summary: Update segment.
30+
parameters:
31+
- $ref: '../../common/parameters.yml#/segmentID'
32+
requestBody:
33+
required: true
34+
content:
35+
application/json:
36+
schema:
37+
$ref: '../../common/schemas/SegmentsParams.yml#/updateSegmentParams'
38+
responses:
39+
'200':
40+
description: OK
41+
content:
42+
application/json:
43+
schema:
44+
$ref: '../../responses/Segment.yml#/updateSegmentResponse'
45+
'400':
46+
$ref: '../../../common/responses/IndexNotFound.yml'
47+
'401':
48+
$ref: '../../../common/responses/Unauthorized.yml'
49+
'404':
50+
$ref: '../../../common/responses/IndexNotFound.yml'
51+
'422':
52+
$ref: '../../../common/responses/StatusUnprocessableEntity.yml'
53+
'500':
54+
$ref: '../../../common/responses/InternalError.yml'
55+
56+
delete:
57+
tags:
58+
- segments
59+
operationId: deleteSegment
60+
summary: Delete a segment's configuration.
61+
description: |
62+
Delete the segment’s configuration. User intents (predictions) from the segment are not deleted. All segment types (computed or custom) can be deleted.
63+
64+
When the query is successful, the HTTP response is 200 OK and returns the date until which you can safely consider the data as being deleted.
65+
parameters:
66+
- $ref: '../../common/parameters.yml#/segmentID'
67+
responses:
68+
'200':
69+
description: OK
70+
content:
71+
application/json:
72+
schema:
73+
$ref: '../../responses/Segment.yml#/deleteSegmentResponse'
74+
'401':
75+
$ref: '../../../common/responses/Unauthorized.yml'
76+
'404':
77+
$ref: '../../../common/responses/IndexNotFound.yml'
78+
'422':
79+
$ref: '../../../common/responses/StatusUnprocessableEntity.yml'
80+
'500':
81+
$ref: '../../../common/responses/InternalError.yml'

specs/predict/responses/Segment.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
updateSegmentResponse:
2+
title: updateSegmentResponse
3+
type: object
4+
required:
5+
- segmentID
6+
- updatedAt
7+
properties:
8+
segmentID:
9+
$ref: '#/segmentID'
10+
updatedAt:
11+
$ref: '#/updatedAt'
12+
13+
deleteSegmentResponse:
14+
title: deleteSegmentResponse
15+
type: object
16+
required:
17+
- segmentID
18+
- deletedUntil
19+
properties:
20+
segmentID:
21+
$ref: '#/segmentID'
22+
deletedUntil:
23+
$ref: '#/deletedUntil'
24+
25+
getSegmentUsersResponse:
26+
title: getSegmentUsersResponse
27+
type: object
28+
required:
29+
- segmentID
30+
- users
31+
properties:
32+
segmentID:
33+
$ref: '#/segmentID'
34+
users:
35+
type: array
36+
items:
37+
$ref: 'UserProfile.yml#/userProfile'
38+
previousPageToken:
39+
$ref: '../common/schemas/Params.yml#/previousPageToken'
40+
nextPageToken:
41+
$ref: '../common/schemas/Params.yml#/nextPageToken'
42+
43+
fetchSegmentResponse:
44+
title: fetchSegmentResponse
45+
$ref: '#/segment'
46+
47+
fetchAllSegmentsResponse:
48+
title: fetchAllSegmentsResponse
49+
type: array
50+
items:
51+
$ref: '#/segment'
52+
53+
createSegmentResponse:
54+
title: createSegmentResponse
55+
type: object
56+
required:
57+
- segmentID
58+
- updatedAt
59+
properties:
60+
segmentID:
61+
$ref: '#/segmentID'
62+
updatedAt:
63+
$ref: '#/updatedAt'
64+
65+
segment:
66+
type: object
67+
required:
68+
- segmentID
69+
- name
70+
- conditions
71+
- segmentStatus
72+
- type
73+
properties:
74+
segmentID:
75+
$ref: '#/segmentID'
76+
name:
77+
type: string
78+
conditions:
79+
type: string
80+
segmentStatus:
81+
$ref: '#/segmentStatus'
82+
type:
83+
$ref: '#/segmentType'
84+
errorMessage:
85+
type: string
86+
87+
segmentStatus:
88+
type: string
89+
enum:
90+
- active
91+
- pending
92+
- failed
93+
94+
segmentType:
95+
type: string
96+
enum:
97+
- computed
98+
- custom
99+
100+
segmentID:
101+
type: string
102+
description: The ID of the segment.
103+
104+
updatedAt:
105+
type: string
106+
description: The date and time at which the segment was last updated.
107+
108+
deletedUntil:
109+
type: string
110+
description: The date and time at which the segment will be re-ingested.

specs/predict/spec.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,25 @@ tags:
3131
- name: profiles
3232
x-displayName: Profiles
3333
description: Manage users' profiles.
34+
- name: segments
35+
x-displayName: Segments
36+
description: Manage segments.
3437
x-tagGroups:
3538
- name: General
3639
tags:
3740
- profiles
3841
- models
42+
- segments
3943
paths:
4044
# ######################
4145
# ### Custom request ###
4246
# ######################
4347
/1{path}:
4448
$ref: '../common/paths/customRequest.yml'
4549

50+
# ######################
51+
# ### Users request ###
52+
# ######################
4653
/1/users/{userID}/fetch:
4754
$ref: 'paths/users/fetch.yml'
4855

@@ -66,3 +73,15 @@ paths:
6673

6774
/1/predict/models/{modelID}/metrics:
6875
$ref: 'paths/models/getModelMetrics.yml'
76+
77+
# ########################
78+
# ### Segments request ###
79+
# ########################
80+
/1/segments/{segmentID}/users:
81+
$ref: 'paths/segments/segmentUsers.yml'
82+
83+
/1/segments/{segmentID}:
84+
$ref: 'paths/segments/singleSegment.yml'
85+
86+
/1/segments:
87+
$ref: 'paths/segments/allSegments.yml'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"testName": "create segment with required params",
4+
"parameters": {
5+
"name": "segment1",
6+
"conditions": "predictions.order_value.value > 100 AND predictions.funnel_stage.score < 0.9"
7+
},
8+
"request": {
9+
"path": "/1/segments",
10+
"method": "POST",
11+
"body": {
12+
"name": "segment1",
13+
"conditions": "predictions.order_value.value > 100 AND predictions.funnel_stage.score < 0.9"
14+
}
15+
}
16+
}
17+
]

0 commit comments

Comments
 (0)