Skip to main content

How to find all container sites that are full

  1. Login
  2. Query all container sites for their max weight and their current weight
  3. For all containers, calculate percentage fullness and based on a certain threshold, filter for all container sites that are over that threshold

Login

mutation Login($email: String!, $password: String!) {
login(email: $email, password: $password) {
jwt
}
}

variables = {"email": "YOUR-EMAIL-HERE", "password": "YOUR-PASSWORD-HERE"}

After logging in, take the JWT returned and include it as a header in all future requests to the GraphQL API in the form of {"Authorization": "Bearer <jwt>"}


Find the max weight and current weight for all container sites

query weightData($unit: WeightUnit!) {
currentUser {
account {
containerSites {
lastWeight {
weight(unit: $unit)
}
maxWeight(unit: $unit)
id
# You could also query for any other field included in container site to identify them
}
}
}
}

variables = {"unit": "KILOGRAM"}
tip

Queryimg for the service location that the container site is inside of may also be useful to find all service locatinos that would need to be picked up


For all containers, calculate percentage fullness and based on a certain threshold, filter for all container sites that are over that threshold

// In this example, we are finding all container sites that are more than 80% full
const desired_percent = 0.8;

const filtered_containers =
response.data.currentUser.account.containerSites.filter((containersite) => {
// Find the current percent full by dividing the last reported weight by the maximum weight
const percent_full = containersite.lastWeight / containersite.maxWeight;

// Filter for all the containers where it's percent fullness is more than 80%
return percent_full > desired_percent;
});

console.log(filtered_containers);

Workflows is a work in progress. If you would like to see an example for a particular task or have a recommendation on how we could improve our documentation, contact us!