Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Commit

Permalink
Ensure that, in the edge case where all freezer boxes for a study are…
Browse files Browse the repository at this point in the history
… full, the next empty box is not the same as the "current" box being recommended (instead make the next empty box the _next_ next empty box)
  • Loading branch information
aaronstephenson committed Apr 29, 2020
1 parent 4899b81 commit 4524450
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion code.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "liliservices",
"organization": "U.S. Geological Survey",
"description": "Web services for LILI (LIDE (Laboratory for Infectious Disease and the Environment) Information Management System)",
"version": "v1.2.2",
"version": "v1.2.3",
"status": "Production",

"permissions": {
Expand Down
22 changes: 14 additions & 8 deletions liliapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def get_first_empty_box(self):
cur_rack += 1

# get the next box with no occupied spots after a specified spot
def get_next_empty_box(self, last_spot):
def get_next_empty_box(self, last_spot, get_second_empty_box=False):
# start building the next empty box object
next_empty_box = {'freezer': last_spot.freezer.id}

Expand All @@ -514,13 +514,19 @@ def get_next_empty_box(self, last_spot):
# check if this box exists (meaning the actual physical box is empty)
cur_box_occupied = self.filter(freezer=last_spot.freezer.id, rack=cur_rack, box=cur_box)
if not cur_box_occupied:
# if this box is empty (does not exit), return it, otherwise continue to the next box
next_empty_box['rack'] = cur_rack
next_empty_box['box'] = cur_box
next_empty_box['row'] = 1
next_empty_box['spot'] = 1
next_empty_box['available_spots_in_box'] = spots_in_box
return next_empty_box
# if this box is empty (does not exit),
# and we are not looking for the second empty box (the 'next' empty box after the next empty box),
# return it, otherwise continue to the next box
if get_second_empty_box:
cur_box += 1
get_second_empty_box = False
else:
next_empty_box['rack'] = cur_rack
next_empty_box['box'] = cur_box
next_empty_box['row'] = 1
next_empty_box['spot'] = 1
next_empty_box['available_spots_in_box'] = spots_in_box
return next_empty_box
else:
cur_box += 1
cur_rack += 1
Expand Down
11 changes: 10 additions & 1 deletion liliapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,16 @@ def get_next_available(self, request):
if next_spot is not None:
# start building the full response object
resp = next_spot
next_empty_box = FreezerLocation.objects.get_next_empty_box(last_spot)

# determine maximum available spots in a box in this freezer (for an empty box)
rows_in_box = last_spot.freezer.rows
spots_in_row = last_spot.freezer.spots
spots_in_box = rows_in_box * spots_in_row

# ensure next spot and next empty box are not the same
get_second_empty_box = True if next_spot['available_spots_in_box'] == spots_in_box else False
next_empty_box = FreezerLocation.objects.get_next_empty_box(last_spot, get_second_empty_box)

# then add the next empty box to the response object
resp.update({"next_empty_box": next_empty_box})
# no next spot was found
Expand Down

0 comments on commit 4524450

Please sign in to comment.