Skip to content

Commit 1e47297

Browse files
Robin BuschmannRobin Buschmann
authored andcommitted
clustering intergrated to import
1 parent 76bc43e commit 1e47297

10 files changed

+366
-158
lines changed

app.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,20 @@ http.createServer(app).listen(
126126
app.get('port'),
127127
() => logger.info('Server listening on port ' + app.get('port'))
128128
);
129+
130+
131+
import {Injector} from 'di-ts';
132+
import {SoapService} from "./services/SoapService";
133+
import {DataImporter} from "./services/DataImporter";
134+
135+
if (process.env['INITIAL_IMPORT']) {
136+
137+
let injector = new Injector();
138+
const soapService = injector.get(SoapService);
139+
const dataImporter = injector.get(DataImporter);
140+
141+
soapService.eRoamingPullEvseData()
142+
.then(data => dataImporter.execute(data))
143+
.catch(err => console.log(err))
144+
;
145+
}

interfaces/models/ILocationCluster.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
interface ILocationCluster {
3+
4+
id: number;
5+
longitude: number;
6+
latitude: number;
7+
epsilon: number;
8+
chargingLocations: IChargingLocation[];
9+
groupCount?: number;
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
interface ILocationClusterChargingLocation {
3+
4+
locationClusterId: number;
5+
chargingLocationId: number;
6+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
var dbm;
4+
var type;
5+
var seed;
6+
7+
/**
8+
* We receive the dbmigrate dependency from dbmigrate initially.
9+
* This enables us to not have to rely on NODE_PATH.
10+
*/
11+
exports.setup = function(options, seedLink) {
12+
dbm = options.dbmigrate;
13+
type = dbm.dataType;
14+
seed = seedLink;
15+
};
16+
17+
exports.up = function(db) {
18+
19+
return db.runSql(`
20+
CREATE TABLE \`LocationCluster\` (
21+
\`id\` int(11) NOT NULL AUTO_INCREMENT,
22+
\`longitude\` decimal(9,6) NOT NULL,
23+
\`latitude\` decimal(9,6) NOT NULL,
24+
\`epsilon\` decimal(9,6) NOT NULL,
25+
PRIMARY KEY (\`id\`),
26+
KEY \`epsilon\` (\`epsilon\`)
27+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
28+
`);
29+
};
30+
31+
exports.down = function(db) {
32+
return db.runSql(`
33+
DROP TABLE IF EXISTS LocationCluster;
34+
`);
35+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
var dbm;
4+
var type;
5+
var seed;
6+
7+
/**
8+
* We receive the dbmigrate dependency from dbmigrate initially.
9+
* This enables us to not have to rely on NODE_PATH.
10+
*/
11+
exports.setup = function(options, seedLink) {
12+
dbm = options.dbmigrate;
13+
type = dbm.dataType;
14+
seed = seedLink;
15+
};
16+
17+
exports.up = function(db) {
18+
19+
return db.runSql(`
20+
CREATE TABLE \`LocationClusterChargingLocation\` (
21+
\`locationClusterId\` int(11) NOT NULL,
22+
\`chargingLocationId\` int(11) NOT NULL,
23+
PRIMARY KEY (\`locationClusterId\`,\`chargingLocationId\`),
24+
KEY \`chargingLocationId\` (\`chargingLocationId\`),
25+
CONSTRAINT \`locationclustercharginglocation_ibfk_1\` FOREIGN KEY (\`locationClusterId\`) REFERENCES \`LocationCluster\` (\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION,
26+
CONSTRAINT \`locationclustercharginglocation_ibfk_2\` FOREIGN KEY (\`chargingLocationId\`) REFERENCES \`ChargingLocation\` (\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION
27+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
28+
`);
29+
};
30+
31+
exports.down = function(db) {
32+
return db.runSql(`
33+
DROP TABLE IF EXISTS LocationClusterChargingLocation;
34+
`);
35+
};

models/LocationCluster.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import {Table} from "../orm/annotations/Table";
2+
import {Column} from "../orm/annotations/Column";
3+
import {Model} from "../orm/models/Model";
4+
import {PrimaryKey} from "../orm/annotations/PrimaryKey";
5+
import {DataType} from "../orm/models/DataType";
6+
import {EVSE} from "./EVSE";
7+
import {HasMany} from "../orm/annotations/HasMany";
8+
import {BelongsTo} from "../orm/annotations/BelongsTo";
9+
import {ChargingLocation} from "./ChargingLocation";
10+
import {ForeignKey} from "../orm/annotations/ForeignKey";
11+
import {BelongsToMany} from "../orm/annotations/BelongsToMany";
12+
import {LocationClusterChargingLocation} from "./LocationClusterChargingLocation";
13+
14+
@Table
15+
export class LocationCluster extends Model<LocationCluster> implements ILocationCluster {
16+
17+
@Column
18+
@PrimaryKey
19+
id: number;
20+
21+
@Column({
22+
type: DataType.DECIMAL
23+
})
24+
longitude: number;
25+
26+
@Column({
27+
type: DataType.DECIMAL
28+
})
29+
latitude: number;
30+
31+
@Column({
32+
type: DataType.VIRTUAL
33+
})
34+
groupCount: number;
35+
36+
@Column
37+
epsilon: number;
38+
39+
@BelongsToMany(() => ChargingLocation, () => LocationClusterChargingLocation)
40+
chargingLocations: ChargingLocation[];
41+
42+
@Column({
43+
type: DataType.VIRTUAL,
44+
get() {
45+
const chargingLocations = this.getDataValue('chargingLocations');
46+
const groupCount = chargingLocations.length;
47+
let evses;
48+
49+
if (chargingLocations && groupCount === 1) {
50+
51+
this.setDataValue('id', chargingLocations[0].id);
52+
delete this.dataValues.groupCount;
53+
54+
evses = chargingLocations[0].evses;
55+
} else {
56+
this.setDataValue('groupCount', groupCount);
57+
}
58+
59+
delete this.dataValues.chargingLocations;
60+
61+
return evses;
62+
}
63+
})
64+
evses: EVSE[];
65+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {Table} from "../orm/annotations/Table";
2+
import {Column} from "../orm/annotations/Column";
3+
import {Model} from "../orm/models/Model";
4+
import {PrimaryKey} from "../orm/annotations/PrimaryKey";
5+
import {DataType} from "../orm/models/DataType";
6+
import {EVSE} from "./EVSE";
7+
import {HasMany} from "../orm/annotations/HasMany";
8+
import {BelongsTo} from "../orm/annotations/BelongsTo";
9+
import {ChargingLocation} from "./ChargingLocation";
10+
import {ForeignKey} from "../orm/annotations/ForeignKey";
11+
import {LocationCluster} from "./LocationCluster";
12+
13+
@Table
14+
export class LocationClusterChargingLocation extends Model<LocationClusterChargingLocation> implements ILocationClusterChargingLocation {
15+
16+
@Column
17+
@PrimaryKey
18+
@ForeignKey(() => LocationCluster)
19+
locationClusterId: number;
20+
21+
@Column
22+
@PrimaryKey
23+
@ForeignKey(() => ChargingLocation)
24+
chargingLocationId: number;
25+
}

0 commit comments

Comments
 (0)