Skip to contents

Decides which of the trips a PDS token returns are this country's. It does no network or cloud work, so you can run it on a downloaded trip table to see what a config change would do before making it.

Usage

select_country_trips(
  trips,
  devices,
  customers = NULL,
  exclude_customers = NULL,
  select_by = c("device", "community")
)

Arguments

trips

Trip table from get_trips(), fetched with deviceInfo = TRUE. Without that there is no IMEI or Community column.

devices

The devices table from the assets snapshot. Needs imei, customer_name, and community for the community rule.

customers

Allowlist of customer_name values.

exclude_customers

Denylist of customer_name values. character(0) means "exclude nothing", which is different from leaving it unset.

select_by

"device" (who owns it now) or "community" (where the trip happened). Applies to customers only.

Value

trips, filtered. Keeping nothing is an error, because an empty parquet becomes the latest version and empties the portal.

The three rules

  • select_by = "device" with customers — keep trips whose device is under those customers now. The default, and lossy: a tracker sold on or shipped abroad takes its whole trip history with it.

  • exclude_customers — keep everything except devices under those customers. Redeployed hardware keeps its history, but nothing here can reject another country's trips, so use it only on a country-scoped token.

  • select_by = "community" with customers — keep trips that happened at one of those customers' communities. Recommended: a trip's community does not change when the hardware is reassigned.

Measure before switching a country to "community"

Communities come from current device records, so a landing site with no device left on it drops out and takes its trips with it. Run both rules over one trip table and compare the counts before changing a config.