Analyzing distances between clusters of orders
up vote
0
down vote
favorite
I wrote the python class below which does what I want it to do but the data structure is a mess. Was wondering if there was a better structure I could use to get the same results but also have the code be much more readable.
idea here is we retrieve a dataset from SQL(constructor), cluster the dataset into distinct keys(constructor), iterate through the keys and isolate the matching criteria in the dataset(organizer), pass those data chunks to map_loc_to_lat_long which will find all possible combinations of rows in the chunk and find the straight line distance between all the combination Lat Longs
class OrderProximityModel:
def __init__(self, date):
self.date = str(date)
self.order_data = OrderProxDao().Load_Order_Lat_Long_Date_Zone_Data(self.date)
self.distinct = set([str(row.Requirements) + ' ' + str(row.Route_Date) for row in self.order_data])
def organizer(self):
container =
for date_zone in self.distinct:
latlng = list(filter(lambda x: str(x.Requirements) + ' ' + str(x.Route_Date) == date_zone, self.order_data))
for i in self.map_loc_to_lat_long(latlng):
container.append((i[0][0][0], i[0][0][1], i[0][0][2], i[0][0][4], i[0][0][5], i[0][0][6]))
InsertHelpers(container).chunk_maker(100)
return True
def map_loc_to_lat_long(self, grouped_zone):
converted = {}
for row in grouped_zone:
converted[row.LocationKey] = [row.Latitude, row.Longitude, row.DA, row.Route_Date, row.Requirements, row.DA]
grouped_combos = self.combo_creator(converted.keys())
return map(lambda combo: ([converted[combo[0]][2:] + [combo[0]] + [combo[1]] +
[StraightLineDistance().dist_cal(converted[combo[0]][0],
converted[combo[0]][1],
converted[combo[1]][0],
converted[combo[1]][1])]],
), grouped_combos)
@staticmethod
def combo_creator(inputs):
out =
for index, value in enumerate(inputs):
for nex_value in inputs[index + 1:]:
out.append((value, nex_value))
return out
python python-2.x clustering geospatial
New contributor
add a comment |
up vote
0
down vote
favorite
I wrote the python class below which does what I want it to do but the data structure is a mess. Was wondering if there was a better structure I could use to get the same results but also have the code be much more readable.
idea here is we retrieve a dataset from SQL(constructor), cluster the dataset into distinct keys(constructor), iterate through the keys and isolate the matching criteria in the dataset(organizer), pass those data chunks to map_loc_to_lat_long which will find all possible combinations of rows in the chunk and find the straight line distance between all the combination Lat Longs
class OrderProximityModel:
def __init__(self, date):
self.date = str(date)
self.order_data = OrderProxDao().Load_Order_Lat_Long_Date_Zone_Data(self.date)
self.distinct = set([str(row.Requirements) + ' ' + str(row.Route_Date) for row in self.order_data])
def organizer(self):
container =
for date_zone in self.distinct:
latlng = list(filter(lambda x: str(x.Requirements) + ' ' + str(x.Route_Date) == date_zone, self.order_data))
for i in self.map_loc_to_lat_long(latlng):
container.append((i[0][0][0], i[0][0][1], i[0][0][2], i[0][0][4], i[0][0][5], i[0][0][6]))
InsertHelpers(container).chunk_maker(100)
return True
def map_loc_to_lat_long(self, grouped_zone):
converted = {}
for row in grouped_zone:
converted[row.LocationKey] = [row.Latitude, row.Longitude, row.DA, row.Route_Date, row.Requirements, row.DA]
grouped_combos = self.combo_creator(converted.keys())
return map(lambda combo: ([converted[combo[0]][2:] + [combo[0]] + [combo[1]] +
[StraightLineDistance().dist_cal(converted[combo[0]][0],
converted[combo[0]][1],
converted[combo[1]][0],
converted[combo[1]][1])]],
), grouped_combos)
@staticmethod
def combo_creator(inputs):
out =
for index, value in enumerate(inputs):
for nex_value in inputs[index + 1:]:
out.append((value, nex_value))
return out
python python-2.x clustering geospatial
New contributor
It "does what I want it to do" — would you care to tell us what that is, exactly? See How to Ask.
– 200_success
7 hours ago
Sure, idea here is we retrieve a dataset from SQL(constructor), cluster the dataset into distinct keys(constructor), iterate through the keys and isolate the matching criteria in the dataset(organizer), pass those data chunks to map_loc_to_lat_long which will find all possible combinations of rows in the chunk and find the straight line distance between all the combination Lat Longs
– Mike Sivalls
7 hours ago
Absolutely, thanks
– Mike Sivalls
1 hour ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I wrote the python class below which does what I want it to do but the data structure is a mess. Was wondering if there was a better structure I could use to get the same results but also have the code be much more readable.
idea here is we retrieve a dataset from SQL(constructor), cluster the dataset into distinct keys(constructor), iterate through the keys and isolate the matching criteria in the dataset(organizer), pass those data chunks to map_loc_to_lat_long which will find all possible combinations of rows in the chunk and find the straight line distance between all the combination Lat Longs
class OrderProximityModel:
def __init__(self, date):
self.date = str(date)
self.order_data = OrderProxDao().Load_Order_Lat_Long_Date_Zone_Data(self.date)
self.distinct = set([str(row.Requirements) + ' ' + str(row.Route_Date) for row in self.order_data])
def organizer(self):
container =
for date_zone in self.distinct:
latlng = list(filter(lambda x: str(x.Requirements) + ' ' + str(x.Route_Date) == date_zone, self.order_data))
for i in self.map_loc_to_lat_long(latlng):
container.append((i[0][0][0], i[0][0][1], i[0][0][2], i[0][0][4], i[0][0][5], i[0][0][6]))
InsertHelpers(container).chunk_maker(100)
return True
def map_loc_to_lat_long(self, grouped_zone):
converted = {}
for row in grouped_zone:
converted[row.LocationKey] = [row.Latitude, row.Longitude, row.DA, row.Route_Date, row.Requirements, row.DA]
grouped_combos = self.combo_creator(converted.keys())
return map(lambda combo: ([converted[combo[0]][2:] + [combo[0]] + [combo[1]] +
[StraightLineDistance().dist_cal(converted[combo[0]][0],
converted[combo[0]][1],
converted[combo[1]][0],
converted[combo[1]][1])]],
), grouped_combos)
@staticmethod
def combo_creator(inputs):
out =
for index, value in enumerate(inputs):
for nex_value in inputs[index + 1:]:
out.append((value, nex_value))
return out
python python-2.x clustering geospatial
New contributor
I wrote the python class below which does what I want it to do but the data structure is a mess. Was wondering if there was a better structure I could use to get the same results but also have the code be much more readable.
idea here is we retrieve a dataset from SQL(constructor), cluster the dataset into distinct keys(constructor), iterate through the keys and isolate the matching criteria in the dataset(organizer), pass those data chunks to map_loc_to_lat_long which will find all possible combinations of rows in the chunk and find the straight line distance between all the combination Lat Longs
class OrderProximityModel:
def __init__(self, date):
self.date = str(date)
self.order_data = OrderProxDao().Load_Order_Lat_Long_Date_Zone_Data(self.date)
self.distinct = set([str(row.Requirements) + ' ' + str(row.Route_Date) for row in self.order_data])
def organizer(self):
container =
for date_zone in self.distinct:
latlng = list(filter(lambda x: str(x.Requirements) + ' ' + str(x.Route_Date) == date_zone, self.order_data))
for i in self.map_loc_to_lat_long(latlng):
container.append((i[0][0][0], i[0][0][1], i[0][0][2], i[0][0][4], i[0][0][5], i[0][0][6]))
InsertHelpers(container).chunk_maker(100)
return True
def map_loc_to_lat_long(self, grouped_zone):
converted = {}
for row in grouped_zone:
converted[row.LocationKey] = [row.Latitude, row.Longitude, row.DA, row.Route_Date, row.Requirements, row.DA]
grouped_combos = self.combo_creator(converted.keys())
return map(lambda combo: ([converted[combo[0]][2:] + [combo[0]] + [combo[1]] +
[StraightLineDistance().dist_cal(converted[combo[0]][0],
converted[combo[0]][1],
converted[combo[1]][0],
converted[combo[1]][1])]],
), grouped_combos)
@staticmethod
def combo_creator(inputs):
out =
for index, value in enumerate(inputs):
for nex_value in inputs[index + 1:]:
out.append((value, nex_value))
return out
python python-2.x clustering geospatial
python python-2.x clustering geospatial
New contributor
New contributor
edited 5 mins ago
200_success
127k15148411
127k15148411
New contributor
asked 8 hours ago
Mike Sivalls
61
61
New contributor
New contributor
It "does what I want it to do" — would you care to tell us what that is, exactly? See How to Ask.
– 200_success
7 hours ago
Sure, idea here is we retrieve a dataset from SQL(constructor), cluster the dataset into distinct keys(constructor), iterate through the keys and isolate the matching criteria in the dataset(organizer), pass those data chunks to map_loc_to_lat_long which will find all possible combinations of rows in the chunk and find the straight line distance between all the combination Lat Longs
– Mike Sivalls
7 hours ago
Absolutely, thanks
– Mike Sivalls
1 hour ago
add a comment |
It "does what I want it to do" — would you care to tell us what that is, exactly? See How to Ask.
– 200_success
7 hours ago
Sure, idea here is we retrieve a dataset from SQL(constructor), cluster the dataset into distinct keys(constructor), iterate through the keys and isolate the matching criteria in the dataset(organizer), pass those data chunks to map_loc_to_lat_long which will find all possible combinations of rows in the chunk and find the straight line distance between all the combination Lat Longs
– Mike Sivalls
7 hours ago
Absolutely, thanks
– Mike Sivalls
1 hour ago
It "does what I want it to do" — would you care to tell us what that is, exactly? See How to Ask.
– 200_success
7 hours ago
It "does what I want it to do" — would you care to tell us what that is, exactly? See How to Ask.
– 200_success
7 hours ago
Sure, idea here is we retrieve a dataset from SQL(constructor), cluster the dataset into distinct keys(constructor), iterate through the keys and isolate the matching criteria in the dataset(organizer), pass those data chunks to map_loc_to_lat_long which will find all possible combinations of rows in the chunk and find the straight line distance between all the combination Lat Longs
– Mike Sivalls
7 hours ago
Sure, idea here is we retrieve a dataset from SQL(constructor), cluster the dataset into distinct keys(constructor), iterate through the keys and isolate the matching criteria in the dataset(organizer), pass those data chunks to map_loc_to_lat_long which will find all possible combinations of rows in the chunk and find the straight line distance between all the combination Lat Longs
– Mike Sivalls
7 hours ago
Absolutely, thanks
– Mike Sivalls
1 hour ago
Absolutely, thanks
– Mike Sivalls
1 hour ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Mike Sivalls is a new contributor. Be nice, and check out our Code of Conduct.
Mike Sivalls is a new contributor. Be nice, and check out our Code of Conduct.
Mike Sivalls is a new contributor. Be nice, and check out our Code of Conduct.
Mike Sivalls is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208247%2fanalyzing-distances-between-clusters-of-orders%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It "does what I want it to do" — would you care to tell us what that is, exactly? See How to Ask.
– 200_success
7 hours ago
Sure, idea here is we retrieve a dataset from SQL(constructor), cluster the dataset into distinct keys(constructor), iterate through the keys and isolate the matching criteria in the dataset(organizer), pass those data chunks to map_loc_to_lat_long which will find all possible combinations of rows in the chunk and find the straight line distance between all the combination Lat Longs
– Mike Sivalls
7 hours ago
Absolutely, thanks
– Mike Sivalls
1 hour ago