Lab 6 -- Location Tags
Adapt from https://pages.github.khoury.northeastern.edu/2500/2024F/lab/lab11.html
The goal of this lab will be to build many functions related to tracking tags.
Given Data Definitions
A PhoneId is a String
Interpretation: a unique identifier for a person's phone
Examples:
PHONE1 = "p1"
PHONE2 = "p2"
Template:
fun phone-id-temp(pi :: String) -> Any:
... pi ...
end
A TagId is a String
Interpretation: a unique identifier for a tracking tag
Examples:
TAG1 = "t1"
TAG2 = "t2"
TAG3 = "t3"
Template:
fun tagid-temp(ti :: String) -> Any:
... ti ...
end
An Owner is a:
data Owner:
| owner(phoneid :: String, tagid :: String)
end
Interpretation: a record of a particular phone owning a tracking tag. There should only ever be one phone per tag, though can be many tags per phone.
Examples:
OWNER1 = owner(PHONE1, TAG1)
OWNER2 = owner(PHONE1, TAG2)
OWNER3 = owner(PHONE2, TAG3)
Template:
fun owner-temp(o :: Owner) -> Any:
... o.phoneid ... o.tagid ...
end
A Time is a Number
Interpretation: a time represented by the number of seconds since Jan 1, 2025.
Examples:
TIME1 = 10
TIME2 = 20
TIME3 = 30
Template:
fun time-temp(t :: Number) -> Any:
... t ...
end
An Encounter is a:
data Posn:
| posn(x :: Number, y :: Number)
end
data Encounter:
| encounter(phoneid :: String, tagid :: String, time :: Number, posn :: Posn)
end
Interpretation: a record of a tag being seen by a given phone at a given time and location. Note that location is represented as X,Y coordinates for simplicity.
Examples:
ENCOUNTER1 = encounter(PHONE1, TAG1, TIME1, posn(0, 0))
ENCOUNTER2 = encounter(PHONE2, TAG1, TIME2, posn(100, 100))
ENCOUNTER3 = encounter(PHONE1, TAG2, TIME3, posn(0, 0))
Template:
fun encounter-temp(e :: Encounter) -> Any:
... e.phoneid ... e.tagid ... e.time ... e.posn ...
end
Problem 1
Design a function tag-activity-count
that takes a TagId, a List<Encounter>
, a start Time, and an end Time, and calculates how many times the tag has been encountered between the two times, including encounters at exactly the start and end times. Assume that the second time is greater than the first.
Problem 2
Design a function tag-encounter-position
that identifies all positions (0-indexed) where a specific TagId appears within a list of Encounters. If the tag id does not occur, the list may be empty.