Skip to content

Commit

Permalink
add limit param and order by timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
leric7 committed Sep 6, 2023
1 parent 59c750d commit 997519d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ def get_event_day_data_query(param: StatisticsParam):
where: {{
{from_clause}
{to_clause}
}}
}},
orderBy: timestamp,
orderDirection: desc,
{limit_clause}
) {{
...EventDayDataFields
}}
Expand All @@ -90,4 +92,5 @@ def get_event_day_data_query(param: StatisticsParam):
event_day_data_fragment=event_day_data_fragment,
from_clause="timestamp_gte: $from" if param.date_from else "",
to_clause="timestamp_lte: $to" if param.date_to else "",
limit_clause="first: $limit" if param.limit else "first: 1000",
)
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,20 @@ def __init__(
self,
date_from: Optional[datetime.datetime] = None,
date_to: Optional[datetime.datetime] = None,
limit: Optional[int] = None,
):
"""
Initializes a StatisticsParam instance.
Args:
date_from (Optional[datetime.datetime]): Statistical data from date
date_to (Optional[datetime.datetime]): Statistical data to date
limit (Optional[int]): Limit of statistical data
"""

self.date_from = date_from
self.date_to = date_to
self.limit = limit


class StatisticsClient:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,25 @@ export const GET_ESCROW_STATISTICS_QUERY = gql`
`;

export const GET_EVENT_DAY_DATA_QUERY = (params: IStatisticsParams) => {
const { from, to } = params;
const { from, to, limit } = params;
const WHERE_CLAUSE = `
where: {
${from !== undefined ? `timestamp_gte: $from` : ''}
${to !== undefined ? `timestamp_lte: $to` : ''}
}
`;
const LIMIT_CLAUSE = `
first: ${limit ? `$limit` : `1000`}
`;

return gql`
query GetEscrowDayData($from: Int, $to: Int) {
eventDayDatas(${WHERE_CLAUSE}) {
eventDayDatas(
${WHERE_CLAUSE},
orderBy: timestamp,
orderDirection: desc,
${LIMIT_CLAUSE}
) {
...EventDayDataFields
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ export interface IKeyPair {
export interface IStatisticsParams {
from?: Date;
to?: Date;
limit?: number;
}

0 comments on commit 997519d

Please sign in to comment.