Skip to content

Commit 32b24af

Browse files
Robin BuschmannRobin Buschmann
authored andcommitted
clustering added for more than 400 charging locations
1 parent d328a63 commit 32b24af

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

interfaces/models/ILocationCluster.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
interface ILocationCluster {
33

4-
id: number;
4+
id?: number;
55
longitude: number;
66
latitude: number;
77
epsilon: number;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "intercharge-backend",
3-
"version": "0.0.0",
3+
"version": "1.0.1",
44
"description": "Description for server-proto",
55
"scripts": {
66
"docs": "apidoc -i api/ -o documentation/",

services/ChargingLocationService.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export class ChargingLocationService {
8080
if (isOpen24Hours !== void 0) {
8181
evseWhere = {};
8282
evseWhere.isOpen24Hours = isOpen24Hours;
83+
8384
evseWhereStr += `AND e.isOpen24Hours = :isOpen24Hours`;
8485
replacements.isOpen24Hours = isOpen24Hours;
8586
}
@@ -112,6 +113,7 @@ export class ChargingLocationService {
112113
through: {attributes: []}, // removes EVSEChargingFacility property from status,
113114
where: {id: {$in: chargingFacilityIds}}
114115
});
116+
115117
evseChargingFacilityJoin = `
116118
INNER JOIN EVSEChargingFacility ecf ON ecf.evseId = e.id
117119
AND ecf.chargingFacilityId IN (:chargingFacilityIds)
@@ -126,6 +128,7 @@ export class ChargingLocationService {
126128
through: {attributes: []}, // removes EVSEPlug property from status
127129
where: {id: {$in: plugIds}}
128130
});
131+
129132
evsePlugJoin = `
130133
INNER JOIN EVSEPlug ep ON ep.evseId = e.id
131134
AND ep.plugId IN (:plugIds)
@@ -140,6 +143,15 @@ export class ChargingLocationService {
140143
include: chargingLocationInclude,
141144
where
142145
})
146+
.then(chargingLocations => {
147+
148+
if(chargingLocations.length > 400) {
149+
150+
return <any>this.geoService.getLocationClusters(chargingLocations, epsilon);
151+
}
152+
153+
return chargingLocations;
154+
})
143155
;
144156
}
145157

services/GeoService.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class GeoService {
1010
* If one cluster consists of one coordinate, this coordinate
1111
* will be returned as it is
1212
*/
13-
getLocationClusters(chargingLocations: IChargingLocation[], epsilon: number, idObject: {id: number}): Promise<ILocationCluster[]> {
13+
getLocationClusters(chargingLocations: IChargingLocation[], epsilon: number, idObject?: {id: number}): Promise<ILocationCluster[]> {
1414

1515
return new Promise<ILocationCluster[]>((resolve, reject) => {
1616

@@ -34,6 +34,14 @@ export class GeoService {
3434
getEpsilonByZoom(zoom: number) {
3535

3636
switch (zoom) {
37+
case 15:
38+
return 0.002;
39+
case 14:
40+
return 0.003;
41+
case 13:
42+
return 0.006;
43+
case 12:
44+
return 0.0089;
3745
case 11:
3846
return 0.01;
3947
case 10:
@@ -90,9 +98,9 @@ export class GeoService {
9098
* coordinates, if list contains only one element,
9199
* this element will be returned
92100
*/
93-
private getLocationCluster(chargingLocations: IChargingLocation[], epsilon: number, idObject: {id:number}): ILocationCluster {
101+
private getLocationCluster(chargingLocations: IChargingLocation[], epsilon: number, idObject?: {id:number}): ILocationCluster {
94102

95-
const id = idObject.id++;
103+
const id = idObject ? idObject.id++ : null;
96104

97105
if (chargingLocations.length == 1) {
98106

0 commit comments

Comments
 (0)