Skip to content

Commit

Permalink
Merge pull request #22 from tommycbird/patch-0.1
Browse files Browse the repository at this point in the history
Added clean_dict and fixed bug causing missing items in API request
  • Loading branch information
r4m-juan authored Jun 2, 2023
2 parents 71b7a41 + 6df334c commit 2dd22c6
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 11 deletions.
47 changes: 36 additions & 11 deletions route4me/advanced_constraint.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
# -*- coding: utf-8 -*-

from .utils import clean_dict

class AdvancedConstraint(object):

max_cargo_volume = None
max_capacity = None
members_count = 10
available_time_windows = []
tags = []
route4me_members_id = []
depot_address = []
location_sequence_pattern = []
class AdvancedConstraint(object):

def __init__(self):
pass
self.max_cargo_weight = None
self.max_cargo_volume = None
self.max_capacity = None
self.members_count = 10
self.vehicles_id = []
self.available_time_windows = []
self.tags = []
self.route4me_members_id = []
self.depot_address = {
"alias": None,
"address": None,
"lat": None,
"lng": None,
}
self.location_sequence_pattern = [
"",
{
"alias": None,
"address": None,
"lat": None,
"lng": None,
}
]
self.location_sequence_pattern = [
"",
{
"alias": None,
"address": None,
"lat": None,
"lng": None,
}
]
self.group = None

def to_dict(self):
return self.__dict__
return clean_dict(self.__dict__)
27 changes: 27 additions & 0 deletions route4me/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,30 @@ def json2obj(data):
:return: object
"""
return json.loads(data, object_hook=_json_object_hook)


def clean_dict(data):
"""
Clean dictionary values
:param data: input dictionary
:return: cleaned dictionary
"""
if isinstance(data, list):
cleaned_list = []
for i in data:
cleaned_item = clean_dict(i)
# Append non-None items
if cleaned_item not in [None, ""]:
cleaned_list.append(cleaned_item)
return cleaned_list if cleaned_list else None
elif isinstance(data, dict):
cleaned_dict = {}
for k, v in data.items():
cleaned_v = clean_dict(v)
# Append non-None key-value pairs
if cleaned_v not in [None, ""]:
cleaned_dict[k] = cleaned_v
return cleaned_dict if cleaned_dict else None
else:
# For non-container type, return as is
return data

0 comments on commit 2dd22c6

Please sign in to comment.