Skip to content

Commit

Permalink
Fix DP-3T#12 and modify mock example to reflect the new at risk test
Browse files Browse the repository at this point in the history
  • Loading branch information
LCBH committed Apr 15, 2020
1 parent 7937bc9 commit 548e8ab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
26 changes: 15 additions & 11 deletions LowCostDP3T.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,27 +224,31 @@ def process_epoch(self):
# Update infected and local risk scoring
########################################

def check_infected(self, inf_SK0, date, now=None):
def check_infected(self, inf_SK0, dateInfectious, datePublished):
''' Checks if our database was exposed to an infected SK starting on date.
NOTE: this implementation uses the date of the SK_t to reduce the
number of comparisons. The backend needs to store <SK, date> tuples.
number of comparisons. The backend needs to store <SK, date,
datePublish> tuples.
Check if we recorded a contact with a given SK0 across in our
database of contact records. This implementation assumes we are
given a date of infection and checks on a per-day basis.
given a date of infection and a date of publication and checks
on a per-day basis.
Arguments
infSK0(b[]): SK_t of infected
date(str): date of SK_t (i.e., the t in the form 2020-04-23).
now(datetime): current date for mock testing.
dateInfectious(str): date of SK_t (i.e., the t in the
form 2020-04-23).
datePublish(datetime): date of publication of SK_t (same
format).
'''
if now is None:
now = datetime.now(timezone.utc)
infect_date = datetime.strptime(date, "%Y-%m-%d")
days_infected = (now-infect_date).days
infectious_date = datetime.strptime(dateInfectious, "%Y-%m-%d")
published_date = datetime.strptime(datePublished, "%Y-%m-%d")
days_infected = (published_date-infectious_date).days
inf_SK = inf_SK0
for day in range(days_infected, -1, -1):
# We do not compute the SK key of the day of the publication
for day in range(days_infected, 0, -1):
# Create infected EphIDs and rotate infected SK
infected_ephIDs = KeyStore.create_ephIDs(inf_SK)
inf_SK = KeyStore.get_SKt1(inf_SK)
Expand All @@ -259,7 +263,7 @@ def check_infected(self, inf_SK0, date, now=None):
if inf_ephID in self.contacts[day]:
duration = self.contacts[day][inf_ephID]
print(
"At risk, observed {} on day -{} for {}".format(inf_ephID.hex(), day, duration))
"At risk, observed {} on day ({})-{} day(s) for {} seconds".format(inf_ephID.hex(), datePublished, day, duration))


# Mock Application that ties contact manager and keystore together
Expand Down
18 changes: 12 additions & 6 deletions example_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
bob.next_day()
isidor.next_day()

print("Isidor is now infectious.")
infectious_date = datetime.utcfromtimestamp(epotime)
infections_SK = isidor.keystore.SKt[0]

print("Day: Bob and Isidor meet for dinner.")
for hour in range(17, 20):
for epoch in range(60//LowCostDP3T.EPOCH_LENGTH):
Expand All @@ -81,16 +85,18 @@
bob.next_epoch()
isidor.next_epoch()

print("Isidor is tested positive.")
infectious_date = datetime.utcfromtimestamp(epotime)
infections_SK = isidor.keystore.SKt[0]

# Tik Tok
epotime += 24*60*60
alice.next_day()
bob.next_day()
isidor.next_day()

print("Isidor is tested positive and publish infectious_SK (from yesterday).")
published_date = datetime.utcfromtimestamp(epotime)

# Tik Tok
epotime += 2*60*60

# Alice receives a replay and should not be positive because of that
now = datetime.utcfromtimestamp(epotime)
bob_ephID = bob.keystore.get_current_ephID(now)
Expand All @@ -106,7 +112,7 @@
print("Check exposure of Alice and Bob.")
print("Alice: (not positive)")
alice.ctmgr.check_infected(infections_SK, infectious_date.strftime(
"%Y-%m-%d"), datetime.utcfromtimestamp(epotime))
"%Y-%m-%d"), published_date.strftime("%Y-%m-%d"))
print("Bob: (at risk)")
bob.ctmgr.check_infected(infections_SK, infectious_date.strftime(
"%Y-%m-%d"), datetime.utcfromtimestamp(epotime))
"%Y-%m-%d"), published_date.strftime("%Y-%m-%d"))

0 comments on commit 548e8ab

Please sign in to comment.