Commit 4ebd6230 authored by Alexander Lercher's avatar Alexander Lercher

working clustering on individual locations

parent 76a41124
......@@ -14,7 +14,7 @@ basePath: "/api"
paths:
/debug:
post:
operationId: "debug.echo"
operationId: "rest.debug.echo"
tags:
- "Echo"
summary: "Echo function for debugging purposes"
......@@ -70,7 +70,7 @@ paths:
200:
description: "Successful operation"
schema:
$ref: "#/definitions/Cluster"
$ref: "#/definitions/ClusterValue"
/cluster/cluster.png:
get:
......@@ -97,7 +97,7 @@ paths:
200:
description: "Successful operation"
schema:
$ref: "#/definitions/Cluster"
$ref: "#/definitions/ClusterValue"
/agi/cluster/cluster.png:
get:
......@@ -127,10 +127,20 @@ definitions:
type: "number"
timestamp:
type: "number"
Cluster:
ClusterValue:
type: "object"
properties:
id:
type: string
format: uuid
cluster_label:
type: number
latitude:
type: number
longitude:
type: number
timestamp:
type: number
username:
type: string
\ No newline at end of file
......@@ -12,15 +12,12 @@ class AgiRepository:
travels = [t for t in travels if t['status'] >= 2]
for travel in travels:
locations.append(self.location(travel["id"], travel['startPlace.latitude'], travel['startPlace.longitude'], 0, ''))
continue # todo work on locations
# todo number of complete travels with startlocation and user data
num_complete_travels = min(len(travel['startedBy']), len(travel['users']))
for i in range(num_complete_travels):
cur_location = travel['startedBy'][i]
cur_user = travel['users'][i]
locations.append(
self.location(f'{travel["id"]}-{cur_location["moment"]}',
cur_location['coordinate']['latitude'],
......
......@@ -17,7 +17,7 @@ class Clusterer:
labels = self.create_labels(locations)
return self._draw_locations(
locations = np.asarray([(l['latitude'], l['longitude']) for l in locations]),
locations = self.extract_location_data(locations),
partition_info = labels
)
......@@ -47,7 +47,7 @@ class Clusterer:
if locations is None or len(locations) == 0:
return locations # trash in trash out
locations = np.asarray([(l['latitude'], l['longitude']) for l in locations])
locations = self.extract_location_data(locations)
dbsc = DBSCAN(eps = self.epsilon, min_samples = self.min_points)
dbsc = dbsc.fit(locations)
......@@ -78,3 +78,6 @@ class Clusterer:
clusters[label] = [l for l in locations if l['cluster_label'] == label]
return clusters
def extract_location_data(self, locations: List[dict]) -> np.ndarray:
return np.asarray([(float(l['latitude']), float(l['longitude'])) for l in locations])
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment