@@ -6,58 +6,43 @@ const Promise = require('bluebird');
6
6
const exec = require ( 'executive' ) ;
7
7
8
8
const router = express . Router ( ) ;
9
-
9
+ //Only admin can req this endpoint
10
10
router . get ( "/" , ( req , res ) => {
11
- // https://www.openstreetmap.org/way/448220597#map=19/-8.11742/-79.01687&layers=D
12
- // https://www.openstreetmap.org/way/90564392#map=17/-8.10327/-79.01803&layers=D
13
- var way = {
14
- id : 90564392 ,
15
- nodes : [ 4452550921 ,
16
- 4452550922 ,
17
- 1098601537 ,
18
- 1051000245 ,
19
- 5483345195 ,
20
- 1098620120 ,
21
- 1088227476 ,
22
- 1098585235 ,
23
- 1098641105 ,
24
- 1098641400 ,
25
- 1088227388 ,
26
- 1098647854 ,
27
- 1098635414 ,
28
- 1098584127 ,
29
- 1098639238 ,
30
- 1098633083 ,
31
- 1098622426 ,
32
- 5478475745 ,
33
- 5476546741 ,
34
- 2573525834
35
- ]
36
- } ;
37
- ignoreSegment ( way , './data' , function ( error , res ) {
11
+ const ways = getWays ( req ) ;
12
+ ignoreSegment ( ways , './data' , function ( error , resp ) {
38
13
if ( error ) return res . json ( {
39
14
error : 'error processing the data'
40
15
} ) ;
41
- return res . json ( way ) ;
16
+ return res . json ( {
17
+ resp,
18
+ ways
19
+ } ) ;
42
20
} ) ;
43
21
} ) ;
44
22
45
23
46
- function createSpeedProfile ( speedProfileFile , way ) {
24
+ function createSpeedProfile ( speedProfileFile , ways ) {
47
25
return new Promise ( ( resolve , reject ) => {
48
26
const file = fs . createWriteStream ( speedProfileFile ) ;
49
27
file
50
28
. on ( 'open' , ( ) => {
51
29
// Compute traffic profile.
52
30
// https://github.com/Project-OSRM/osrm-backend/wiki/Traffic
53
- for ( let i = 0 ; i < way . nodes . length - 2 ; i ++ ) {
54
- if ( i !== 0 ) {
31
+ for ( var k = 0 ; k < ways . length ; k ++ ) {
32
+ let way = ways [ k ]
33
+ if ( k !== 0 ) {
55
34
file . write ( '\n' ) ;
56
35
}
57
- const node = way . nodes [ i ] ;
58
- const nextNode = way . nodes [ i + 1 ] ;
59
- file . write ( `${ node } ,${ nextNode } ,0\n` ) ;
60
- file . write ( `${ nextNode } ,${ node } ,0` ) ;
36
+ for ( let i = 0 ; i < way . nodes . length - 2 ; i ++ ) {
37
+ const node = way . nodes [ i ] ;
38
+ const nextNode = way . nodes [ i + 1 ] ;
39
+ file . write ( `${ node } ,${ nextNode } ,0\n` ) ;
40
+ if ( i + 3 === way . nodes . length ) {
41
+ file . write ( `${ nextNode } ,${ node } ,0` ) ;
42
+ } else {
43
+ file . write ( `${ nextNode } ,${ node } ,0\n` ) ;
44
+ }
45
+ }
61
46
}
62
47
file . end ( ) ;
63
48
} )
@@ -66,15 +51,15 @@ function createSpeedProfile(speedProfileFile, way) {
66
51
} ) ;
67
52
}
68
53
69
- function ignoreSegment ( way , osrmFolder , cb ) {
70
- const identifier = way . id ;
71
- const speedProfileFile = `data/speed- ${ identifier } .csv` ;
54
+ function ignoreSegment ( ways , osrmFolder , cb ) {
55
+ const identifier = ways . id ;
56
+ const speedProfileFile = `data/speed.csv` ;
72
57
const rootPath = path . resolve ( __dirname , '../../' ) ;
73
58
// The dockerVolMount depends on whether we're running this from another docker
74
59
const dockerVolMount = rootPath ;
75
60
// Paths for the files depending from where this is being run.
76
61
const pathSpeedProf = speedProfileFile ;
77
- createSpeedProfile ( speedProfileFile , way )
62
+ createSpeedProfile ( speedProfileFile , ways )
78
63
. then ( function ( ) {
79
64
const command = [
80
65
'docker' ,
@@ -85,7 +70,9 @@ function ignoreSegment(way, osrmFolder, cb) {
85
70
`${ dockerVolMount } /data:/data` ,
86
71
'osrm/osrm-backend:v5.16.4' ,
87
72
'osrm-contract' ,
88
- '--segment-speed-file' , '/' + pathSpeedProf ,
73
+ '--segment-speed-file' ,
74
+ '/data/speed.csv' ,
75
+ '--core 0.8' ,
89
76
`/data/tr.osrm`
90
77
] ;
91
78
console . log ( command . join ( ' ' ) ) ;
@@ -101,4 +88,88 @@ function ignoreSegment(way, osrmFolder, cb) {
101
88
} ) ;
102
89
}
103
90
91
+
92
+ function getWays ( req ) {
93
+ // https://www.openstreetmap.org/way/448220597#map=19/-8.11742/-79.01687&layers=D
94
+ // https://www.openstreetmap.org/way/90564392#map=17/-8.10327/-79.01803&layers=D
95
+ var way1 = {
96
+ id : 90564392 ,
97
+ nodes : [ 4452550921 ,
98
+ 4452550922 ,
99
+ 1098601537 ,
100
+ 1051000245 ,
101
+ 5483345195 ,
102
+ 1098620120 ,
103
+ 1088227476 ,
104
+ 1098585235 ,
105
+ 1098641105 ,
106
+ 1098641400 ,
107
+ 1088227388 ,
108
+ 1098647854 ,
109
+ 1098635414 ,
110
+ 1098584127 ,
111
+ 1098639238 ,
112
+ 1098633083 ,
113
+ 1098622426 ,
114
+ 5478475745 ,
115
+ 5476546741 ,
116
+ 2573525834
117
+ ]
118
+ } ;
119
+
120
+ var way2 = {
121
+ id : 448220597 ,
122
+ nodes : [
123
+ 4452550922 ,
124
+ 4452550920 ,
125
+ 1051000208 ,
126
+ 1026647093 ,
127
+ 316265136 ,
128
+ 4706097947 ,
129
+ 316265135 ,
130
+ 316265134 ,
131
+ 316265133 ,
132
+ 316265132 ,
133
+ 5086618919 ,
134
+ 1026647572 ,
135
+ 316265131 ,
136
+ 316265129 ,
137
+ 1026647527 ,
138
+ 316265126 ,
139
+ 316265124 ,
140
+ 1098627620 ,
141
+ 316265122 ,
142
+ 1088227255 ,
143
+ 1098594792 ,
144
+ 1098634071 ,
145
+ 1026647227 ,
146
+ 1026646809 ,
147
+ 316265120 ,
148
+ 1088227326 ,
149
+ 1098633802 ,
150
+ 316265119 ,
151
+ 316265118 ,
152
+ 1015347808 ,
153
+ 1015292423 ,
154
+ 1098595328 ,
155
+ 316488151 ,
156
+ 316265117 ,
157
+ 1098617316 ,
158
+ 316265116 ,
159
+ 1098612124 ,
160
+ 1098632182 ,
161
+ 2604839551 ,
162
+ 1098589459 ,
163
+ 320114996 ,
164
+ 1098613378 ,
165
+ 1098594789 ,
166
+ 3670684735 ,
167
+ 1088227350 ,
168
+ 3670684731
169
+ ]
170
+ } ;
171
+
172
+ return [ way1 , way2 ] ;
173
+ }
174
+
104
175
module . exports = router ;
0 commit comments