Travel eSIM plans are sold in very different shapes: fixed bundles
(10 GB for 30 days), unlimited-but-throttled day passes, and plain
pay-as-you-go balances. The headline price hides two things that
matter: the real price per GB, and how much of a bundle you will
throw away when the trip ends.
This library works both out. Plans are terms:
- bundle(Name, GB, Price)
- A fixed allowance. If you need more than GB you buy another copy.
- payg(Name, PricePerGB)
- Pay as you go, charged for what you use.
- payg(Name, PricePerGB, StepGB)
- Pay as you go, but topped up in StepGB blocks (for example 1 GB).
Prices are plain numbers in whatever currency you like. GB values may
be integers or floats. Costs are rounded to cents.
- per_gb(+Price, +GB, -PricePerGB) is det
- Price of one GB, rounded to cents.
per_gb(18, 10, X) gives X = 1.8.
- trip_need_gb(+Days, +Usage, -GB) is det
- Rough data need for a trip. Usage is one of:
- light 150 MB a day: maps, messaging, email, no video
- standard 500 MB a day: the above plus social apps and some photos
- heavy 1500 MB a day: video calls, streaming or a laptop hotspot
mb_per_day(MB) your own figure, for example from last month's usage
Uses 1 GB = 1024 MB, which is how most phones report usage.
The result is rounded up to one decimal place so you never plan
for slightly less than you need.
- plan_cost(+NeedGB, +Plan, -Cost, -WastedGB) is det
- What Plan costs to cover NeedGB, and how many GB you pay for
but do not use.
- compare_plans(+NeedGB, +Plans, -Rows) is det
- Rows is a list of
row(Name, Cost, EffectivePerGB, WastedGB),
cheapest first. EffectivePerGB is Cost divided by the GB you
actually use, so leftover data counts against a plan. Ties on
cost are broken by less waste.
- cheapest_plan(+NeedGB, +Plans, -Row) is semidet
- The first row of compare_plans/3. Fails on an empty plan list.
- break_even_gb(+Bundle, +Payg, -GB) is det
- Usage, in GB, at which a single copy of Bundle becomes cheaper
than paying as you go. Below this, pay as you go wins. If the
bundle is never cheaper within its own allowance, GB is never.