Question
can you please please help me with this!! Each visit by a person to a location results in the following data being generated when they
can you please please help me with this!!
Each visit by a person to a location results in the following data being generated when they scan a QR code with their phone:
- an ID associated with that person
- an ID associated with the location
- an integer value corresponding to the day (note that this is not a calendar date, but rather increments from "day zero" of the outbreak)
- a pair ofintegervalues, corresponding to the time (hours and minutes, in 24 hour time) that the person arrived at the location
- a pair ofintegervalues corresponding to the time (hours and minutes, in 24 hour time) that the person departed from the location
In this project, we will represent this data in a 7-tuple. For example, thetuple:
("Irene","Skylabs",3,9,15,13,45)
tells us that Irene visited Skylabs on day 3 of the outbreak, arriving at 9:15am and departing at 1:45pm (ie, 13:45 in 24 hour time).
In this project, you may always assume that these 7-tuplesare correctly formatted; that is, they will consist of twostringsfollowed by five non-negativeintegers. The two values corresponding to hours (indices 3 and 5) will be in the range [0, 23], and the two values corresponding to minutes (indices 4 and 6) will be in the range [0, 59]. Please note: 2am is recorded as 2 rather than 02, and 5 minutes is recorded as 5 rather than 05.
You may assume that all visits are syntactically valid and that no visits for a single person are overlapping in time, although a successive visits may end and start at the same time.
Write a functionpotential_contacts(person_a,person_b)that identifies all of the potential contacts between two people, given data on their movement over multiple days.
The function takes the following arguments,
- person_a
- person_b,
which are each lists of visits by the two people, with each visit formatted as a 7-tupleas described above.
The function should return atupleconsisting of:
- asetof potential contact locations and times for these two people, each in the form of a 6-tuple(see below; note that the order of the items in thissetdoes not matter, as asetdoes not store order); and
- a 2-tuplecontaining a pair ofintegervalues (hours and minutes) corresponding to the total duration of potential contact between these two people.
Note that each the potential contact locations and time in the returnedsetis a 6-tuplerather than a 7-tuplebecause it will not include the ID of an individual. It also differs from the 7-tupledescribed above in that the times referred to, are not the time at which a person arrived at and departed from a location, but rather the time at which the two people started being at the same location (ie, when the second person arrive) and the time at which the two people stopped being at the same location (ie, when the first person left).
For example, if the original visit 7-tupleswere:
("Natalya","Nutrity",2,10,10,11,45)
and:
("Chihiro","Nutrity",2,9,45,11,30)
then the 6-tuplecorresponding to the potential contact between Natalya and Chihiro would be:
("Nutrity",2,10,10,11,30)
indicating that they were both located at Nutrity on the second day of the outbreak between 10:10am and 11:30am.
Assumptions:
- You can assume that the input arguments are syntactically correct given the definitions and assumptions on this slide and on previous slides.
- Any invalid visits should be ignored. Contact locations and times should only be generated for pairs of valid visits.
Here are some example calls to your function:
>>> potential_contacts([('Russel', 'Foodigm', 2, 9, 0, 10, 0), ('Russel', 'Afforage', 2, 10, 0, 11, 30), ('Russel', 'Nutrity', 2, 11, 45, 12, 0), ('Russel', 'Liberry', 3, 13, 0, 14, 15)], [('Natalya', 'Afforage', 2, 8, 15, 10, 0), ('Natalya', 'Nutrity', 4, 10, 10, 11, 45)])
(set(), (0, 0))
>>> potential_contacts([('Russel', 'Foodigm', 2, 9, 0, 10, 0), ('Russel', 'Afforage', 2, 10, 0, 11, 30), ('Russel', 'Nutrity', 2, 11, 45, 12, 0), ('Russel', 'Liberry', 3, 13, 0, 14, 15)], [('Chihiro', 'Foodigm', 2, 9, 15, 9, 30), ('Chihiro', 'Nutrity', 4, 9, 45, 11, 30), ('Chihiro', 'Liberry', 3, 12, 15, 13, 25)])
({('Foodigm', 2, 9, 15, 9, 30), ('Liberry', 3, 13, 0, 13, 25)}, (0, 40))
>>> potential_contacts([('Natalya', 'Afforage', 2, 8, 15, 10, 0), ('Natalya', 'Nutrity', 4, 10, 10, 11, 45)], [('Chihiro', 'Foodigm', 2, 9, 15, 9, 30), ('Chihiro', 'Nutrity', 4, 9, 45, 11, 30), ('Chihiro', 'Liberry', 3, 12, 15, 13, 25)])
({('Nutrity', 4, 10, 10, 11, 30)}, (1, 20))
>>> potential_contacts([('Russel', 'Foodigm', 2, 9, 0, 10, 0), ('Russel', 'Afforage', 2, 10, 0, 11, 30), ('Russel', 'Nutrity', 2, 11, 45, 12, 0), ('Russel', 'Liberry', 3, 13, 0, 14, 15)], [])# person with no visits
(set(), (0, 0))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started