-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi_data_schemas.py
More file actions
210 lines (155 loc) · 5.9 KB
/
api_data_schemas.py
File metadata and controls
210 lines (155 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
"""
This program is free software: you can redistribute it under the terms
of the GNU General Public License, v. 3.0. If a copy of the GNU General
Public License was not distributed with this file, see <https://www.gnu.org/licenses/>.
"""
from typing import Literal, List, Union
from pydantic import BaseModel, Field
from fastapi import Query
class SummaryDetails(BaseModel):
"""Details of the summary metrics."""
total_signup_users: int
total_signup_users_with_emails: int
total_retained_users: int
total_retained_users_with_emails: int
total_retained_users_with_tokens: int
total_signup_countries: int
total_signups_from_bridges: int
total_retained_countries: int
total_publications: int
total_published_publications: int
total_failed_publications: int
signup_countries: list
retained_countries: list
class SummaryParams(BaseModel):
"""Parameters for filtering and grouping summary metrics."""
start_date: str = Field(description="Start date in 'YYYY-MM-DD' format.")
end_date: str = Field(description="End date in 'YYYY-MM-DD' format.")
country_code: str = Field(
default=None, description="2-character ISO region code.", max_length=2
)
type: str = Field(default=None, decribeption="Identifier type to filter by.")
origin: str = Field(default=None, description="Origin to filter by.")
class SummaryResponse(BaseModel):
"""Response model containing summary metrics."""
summary: SummaryDetails
class MetricsParams(BaseModel):
"""Parameters for filtering and grouping metrics."""
start_date: str = Field(description="Start date in 'YYYY-MM-DD' format.")
end_date: str = Field(description="End date in 'YYYY-MM-DD' format.")
country_code: str = Field(
default=None, description="2-character ISO region code.", max_length=2
)
granularity: Literal["day", "month"] = Field(
default="day", description="Granularity of data."
)
group_by: Literal["country", "date"] = Field(
default="date", description="Criteria to group results."
)
top: int = Field(
default=None,
description="Maximum number of results to return. "
"(cannot be used with 'page' or 'page_size')",
)
page: int = Query(default=1, ge=1, description="Page number for paginated results.")
page_size: int = Query(
default=10, ge=10, le=100, description="Number of records per page."
)
type: Literal["phone_number", "email_address"] = Field(
default=None, decribeption="Identifier type to filter by."
)
origin: Literal["web", "bridge"] = Field(
default=None, description="Origin to filter by."
)
class PaginationDetails(BaseModel):
"""Pagination details for paginated responses."""
page: int
page_size: int
total_pages: int
total_records: int
class CountrySignupData(BaseModel):
"""Signup data grouped by country."""
country_code: str
signup_users: int
class TimeframeSignupData(BaseModel):
"""Signup data grouped by timeframe."""
timeframe: str
signup_users: int
class SignupDetails(BaseModel):
"""Details of the signup metrics."""
total_signup_users: int
total_countries: int
total_signups_from_bridges: int
countries: list
pagination: PaginationDetails
data: List[Union[CountrySignupData, TimeframeSignupData]]
class SignupResponse(BaseModel):
"""Response model containing signup metrics."""
signup: SignupDetails
class CountryRetainedData(BaseModel):
"""Retained data grouped by country."""
country_code: str
retained_users: int
class TimeframeRetainedData(BaseModel):
"""Retained data grouped by timeframe."""
timeframe: str
retained_users: int
class RetainedDetails(BaseModel):
"""Details of the retained metrics."""
total_retained_users: int
total_retained_users_with_tokens: int
total_countries: int
countries: list
pagination: PaginationDetails
data: List[Union[CountryRetainedData, TimeframeRetainedData]]
class RetainedResponse(BaseModel):
"""Response model containing retained metrics."""
retained: RetainedDetails
class PublicationsParams(BaseModel):
"""Parameters for filtering and grouping publication metrics."""
start_date: str = Field(description="Start date in 'YYYY-MM-DD' format.")
end_date: str = Field(description="End date in 'YYYY-MM-DD' format.")
country_code: str = Field(
default=None, description="2-character ISO region code.", max_length=2
)
platform_name: str = Field(
default=None, description="Filter by platform name (e.g., 'Twitter')."
)
source: str = Field(default=None, description="Filter by source of publication.")
status: Literal["published", "failed"] = Field(
default=None, description="Filter by publication status."
)
gateway_client: str = Field(
default=None, description="Filter by the gateway client."
)
top: int = Field(
default=None,
description="Maximum number of results to return. "
"(cannot be used with 'page' or 'page_size')",
)
page: int = Query(default=1, ge=1, description="Page number for paginated results.")
page_size: int = Query(
default=10, ge=10, le=100, description="Number of records per page."
)
class PublicationsDetails(BaseModel):
"""Details of the summary metrics."""
country_code: str
platform_name: str
source: str
status: str
gateway_client: str
date_time: str
id: int
class PublicationsSummary(BaseModel):
"""Summary of total publications."""
total_publications: int
total_published: int
total_failed: int
data: List[PublicationsDetails]
pagination: PaginationDetails
class PublicationsResponse(BaseModel):
"""Response model containing publications metrics."""
publications: PublicationsSummary
class ErrorResponse(BaseModel):
"""Response model for errors."""
error: str