-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add aggregation example #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bjornrydahl
merged 8 commits into
main
from
backlog/support-for-aggregations-in-api/documentation
Oct 20, 2023
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0eb4927
add aggregation example
rorsini a97689d
Update group by docs.
bjornrydahl efb8134
Update read the docs build.
bjornrydahl e9d428e
Update build.
bjornrydahl 0d09027
Update requirements.
bjornrydahl 6944259
Merge branch 'main' into backlog/support-for-aggregations-in-api/docu…
bjornrydahl 1159d0d
Update docs.
bjornrydahl 7a12efe
Merge branch 'backlog/support-for-aggregations-in-api/documentation' …
bjornrydahl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
.. | ||
:copyright: Copyright (c) 2015 ftrack | ||
|
||
.. _example/aggregations: | ||
|
||
****************** | ||
Using aggregations | ||
****************** | ||
|
||
The following aggregation methods are available for summarizing data in a grouped results | ||
set: | ||
|
||
:sum(): | ||
|
||
Adds together all the values in a particular column. | ||
|
||
:avg(): | ||
|
||
Calculates the average of a group of selected values. | ||
|
||
:min(): | ||
|
||
Determines the minimum numeric values in each group. | ||
|
||
:max(): | ||
|
||
Determines the maximum numeric values in each group. | ||
|
||
:count(): | ||
|
||
Returns the total number of rows in each group. | ||
|
||
To use these methods you must configure API's “strict api” mode when | ||
generating the session object. Do this by setting :func:`strict_api=True` when | ||
configuring the session: :: | ||
|
||
session = ftrack_api.Session( | ||
server_url='https://YOUR-SITE-URL', | ||
api_key='YOUR-API-KEY', | ||
api_user='YOUR-API-USER', | ||
strict_api=True | ||
) | ||
|
||
Aggregation functions also require “group by” clause that specifies | ||
the attributes that will be used to distinguish how the aggregate results are | ||
grouped, such as:: | ||
|
||
select count(id) from Task group by status_id | ||
|
||
.. note:: | ||
|
||
Queries that include aggregations have to use the operations syntax (see: | ||
https://help.ftrack.com/en/articles/1040498-operations) and be passed to the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. old docs. |
||
:func:`session.call()` method versus the :func:`session.query()` method. | ||
|
||
|
||
Summarize task totals | ||
===================== | ||
|
||
Select the total number of Tasks grouped by Status and Project:: | ||
|
||
status_lookup = {} | ||
for i in session.query('select id, name from Status'): | ||
status_lookup[i['id']] = i['name'] | ||
|
||
project_lookup = {} | ||
for i in session.query('select id, name from Project'): | ||
project_lookup[i['id']] = i['name'] | ||
|
||
res = session.call( | ||
[ | ||
{ | ||
'action': 'query', | ||
'expression': 'select count(id) from Task group by project_id, status_id' | ||
} | ||
] | ||
) | ||
status_count = res[0]['data'] | ||
|
||
for count in status_count: | ||
print('{} Tasks are "{}" in project {}'.format( | ||
count['count_id'], | ||
status_lookup[count['status_id']], | ||
project_lookup[count['project_id']] | ||
) | ||
) | ||
|
||
Sample output:: | ||
|
||
2 Tasks are "Not started" in project sync | ||
4 Tasks are "In progress" in project sync | ||
16 Tasks are "Approved" in project sync | ||
2 Tasks are "Not started" in project napo | ||
3 Tasks are "In progress" in project napo | ||
13 Tasks are "Approved" in project napo | ||
4 Tasks are "Client approved" in project napo | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,4 +51,5 @@ already constructed a :class:`Session`:: | |
sync_ldap_users | ||
invite_user | ||
workflow_schema | ||
aggregations | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2023