-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_data_schemas.py
128 lines (85 loc) · 3.26 KB
/
api_data_schemas.py
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
"""
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_retained_users: int
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
)
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."
)
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
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
pagination: PaginationDetails
data: List[Union[CountryRetainedData, TimeframeRetainedData]]
class RetainedResponse(BaseModel):
"""Response model containing retained metrics."""
retained: RetainedDetails
class ErrorResponse(BaseModel):
"""Response model for errors."""
error: str