Filtering Lists
Activities, subjects, sessions and subject groups are all listed the same way: list(...) takes the filters you want and returns a sequence you iterate directly.
Every sequence also carries total, the number of matching items, and all(), which collects the rest into an array.
Activities
- Swift
- TypeScript
- Python
let activities = client.activities.list(search: "squat", onlyCompleted: true)
for try await activity in activities {
print(activity.name ?? activity.id, activity.status)
}
const activities = client.activities.list({ search: "squat", onlyCompleted: true });
for await (const activity of activities) {
console.log(activity.name, activity.status);
}
activities = client.activities.list(search="squat", only_completed=True)
for activity in activities:
print(activity.name, activity.status)
Calibration and neutral-pose activities are left out by default. Pass excludeCalibration: false to include them.
| Filter | Selects |
|---|---|
subject | Activities recorded for one subject |
calibrationSession | Activities recorded under one calibration session |
activityType | Activities of one type — see Activity Types |
excludeCalibration | Whether to leave out calibration and neutral-pose activities (default true) |
createdAfter / createdBefore | An inclusive date range |
search | Free-text match against the activity name |
tags | Activities carrying every tag in the list |
createdBy | Activities belonging to one or more account ids |
onlyCompleted | Activities whose recording finished |
excludeAnalysisError | Leaves out activities whose analysis failed |
Subjects
- Swift
- TypeScript
- Python
for try await subject in client.subjects.list(activityComplete: true) {
print(subject.id, subject.name)
}
for await (const subject of client.subjects.list({ activityComplete: true })) {
console.log(subject.id, subject.name);
}
for subject in client.subjects.list(activity_complete=True):
print(subject.id, subject.name)
| Filter | Selects |
|---|---|
search | Free-text match against the subject name |
createdAfter / createdBefore | An inclusive date range |
groups | Subjects belonging to one of these subject groups |
tags | Subjects carrying every tag in the list |
createdBy | Subjects belonging to one or more account ids |
activityType | Subjects with an activity of this type — see Activity Types |
activityComplete | Subjects with at least one completed activity |
session | Subjects recorded in one session |
Sessions
- Swift
- TypeScript
- Python
let sessions = try await client.sessions.list(subject: subject).all()
const sessions = await client.sessions.list({ subject }).all();
sessions = client.sessions.list(subject=subject).all()
Narrowing by subject is the only filter a session list takes. It lists sessions on your own account.
Subject Groups
- Swift
- TypeScript
- Python
for try await group in client.groups.list(search: "study") {
print(group.name, group.subjectCount)
}
for await (const group of client.groups.list({ search: "study" })) {
console.log(group.name, group.subjectCount);
}
for group in client.groups.list(search="study"):
print(group.name, group.subject_count)
Search is the only filter a group list takes.
Activity Types
The types available are the account's own: the ones everybody has, plus any the account or its organisation added. Read them, then filter by one.
- Swift
- TypeScript
- Python
let types = try await client.activityTypes()
let squats = types.first { $0.displayName == "Squat Exercise" }!
for try await activity in client.activities.list(activityType: squats) {
print(activity.name ?? activity.id)
}
const types = await client.activityTypes();
const squats = types.find(t => t.displayName === "Squat Exercise")!;
for await (const activity of client.activities.list({ activityType: squats })) {
console.log(activity.name);
}
types = client.activity_types.list()
squats = next(t for t in types if t.display_name == "Squat Exercise")
for activity in client.activities.list(activity_type=squats):
print(activity.name)
A type carries id, name, slug and displayName, and — when read from this list — description and isCustom.
Match on slug rather than on a name. It is derived from the name once and then stays put, so renaming a type leaves it alone, while name and displayName both follow the rename:
- Swift
- TypeScript
- Python
let squats = try await client.activityTypes().first { $0.slug == "squat_exercise" }!
const squats = (await client.activityTypes()).find(t => t.slug === "squat_exercise")!;
squats = next(t for t in client.activity_types.list() if t.slug == "squat_exercise")
The one already on an activity works as a filter too, so you can narrow to whatever you just saw:
- Swift
- TypeScript
- Python
client.activities.list(activityType: activity.activityType!)
client.activities.list({ activityType: activity.activityType! });
client.activities.list(activity_type=activity.activity_type)
Sorting
Pass orderBy to choose the field, prefixed with - for descending. Swift takes a typed enum instead of a string.
- Swift
- TypeScript
- Python
client.activities.list(orderBy: .createdAtDescending)
client.subjects.list(orderBy: .name)
client.activities.list({ orderBy: "-createdAt" });
client.subjects.list({ orderBy: "name" });
client.activities.list(order_by="-created_at")
client.subjects.list(order_by="name")
| List | Sort by |
|---|---|
| Activities | createdAt, status, createdBy, activityType |
| Subjects | name, createdAt, updatedAt |
| Sessions | name, createdAt |
| Subject groups | name |
A field the list can't sort by is refused straight away, with an error naming the ones it accepts.
Counting Matches
total is the number of items matching the filter, not the number you have read. It is available before you start iterating, and reading it does not consume any items.
- Swift
- TypeScript
- Python
let activities = client.activities.list(tags: ["baseline"])
print("\(try await activities.total) match")
const activities = client.activities.list({ tags: ["baseline"] });
console.log(`${await activities.total} match`);
activities = client.activities.list(tags=["baseline"])
print(f"{activities.total} match")
Collecting Everything
all() returns every remaining match as an array, continuing from wherever iteration stopped. Use limit to cap how many items a sequence yields in total.
- Swift
- TypeScript
- Python
let recent = try await client.activities.list(orderBy: .createdAtDescending, limit: 20).all()
const recent = await client.activities.list({ orderBy: "-createdAt", limit: 20 }).all();
recent = client.activities.list(order_by="-created_at", limit=20).all()
Stopping Early
In TypeScript, call close() on a sequence you stop reading early. Reading one to the end does this for you. Swift and Python need no equivalent.
- Swift
- TypeScript
- Python
for try await activity in client.activities.list() {
if activity.status == "done" { break }
}
const activities = client.activities.list();
for await (const activity of activities) {
if (activity.status === "done") break;
}
activities.close();
for activity in client.activities.list():
if activity.status == "done":
break