Skip to content

Commit

Permalink
fix(cache_service & cache): out of index & constructor
Browse files Browse the repository at this point in the history
Fixed condition to prevent out of index error in get_second_top_region_*
methods
Fixed constructor in cache model to update time, year, and
month.

Signed-off-by: Connor <connor@mcmillan.website>
  • Loading branch information
mibs510 committed Aug 2, 2023
1 parent 6aa85a1 commit 6876464
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions apps/alpr/models/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def get_top_second_region(self, year, month) -> str:
return "N/A"

length = len(list(cache.month[month - 1]['regions']))
return str(list(cache.month[month - 1]['regions'].keys())[1]) if length >= 1 else "N/A"
return str(list(cache.month[month - 1]['regions'].keys())[1]) if length > 1 else "N/A"

def get_top_region_count(self, year: int, month: int) -> int:
cache = self.filter_by_year(year)
Expand All @@ -490,7 +490,7 @@ def get_top_second_region_count(self, year: int, month: int) -> int:
return 0

length = len(list(cache.month[month - 1]['regions']))
return int(list(cache.month[month - 1]['regions'].values())[1]) if length >= 1 else 0
return int(list(cache.month[month - 1]['regions'].values())[1]) if length > 1 else 0

def init(self):
try:
Expand Down
7 changes: 5 additions & 2 deletions apps/api/service/cache_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

from rq import Retry
import json
import logging
from datetime import datetime
Expand Down Expand Up @@ -55,6 +53,11 @@ def __init__(self, request_json: json, alpr_group_id: int):
if not self.cache:
self.cache = Cache()

# Update time
self.now = datetime.now()
self.this_year = self.now.year
self.this_month = self.now.month - 1

def update(self):
try:
data_type = DataType(self.request['data_type'])
Expand Down

0 comments on commit 6876464

Please sign in to comment.