@@ -11,20 +11,36 @@ const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic('neo4j', '
11
11
12
12
const session = driver . session ( ) ;
13
13
14
+
14
15
let schema = [
15
16
'CREATE INDEX ON :Адрес(name)' ,
16
17
'CREATE INDEX ON :Девелопер(name)' ,
17
18
'CREATE INDEX ON :Застройщик(name)' ,
18
19
'CREATE INDEX ON :Класс(name)' ,
19
20
'CREATE INDEX ON :Конструктив(name)' ,
20
21
'CREATE INDEX ON :Корпус(id)' ,
22
+ 'CREATE INDEX ON :Лот(id)' ,
23
+ 'CREATE INDEX ON :Лот(price)' ,
21
24
'CREATE INDEX ON :Отделка(name)' ,
22
25
'CREATE INDEX ON :Проект(name)' ,
23
26
'CREATE INDEX ON :Стадия(name)' ,
24
27
'CREATE INDEX ON :`Тип парковки`(name)' ,
25
28
'CREATE INDEX ON :`Тип недвижимости`(name)' ,
26
29
'CREATE INDEX ON :`Тип фото`(name)' ,
27
- 'CREATE INDEX ON :Фото(name)'
30
+ 'CREATE INDEX ON :Фото(url)' ,
31
+ //'CALL spatial.removeLayer("geom")',
32
+ 'CALL spatial.addPointLayer("geom")'
33
+ ]
34
+
35
+ let after = [
36
+ `CALL spatial.intersects('geom', 'MULTIPOLYGON(((37.06399542968747 56.06757655398861, 38.173614570312466 56.06757655398861, 38.173614570312466 55.432467441048146, 37.06399542968747 55.432467441048146, 37.06399542968747 56.06757655398861)), ((37.06399542968747 56.06757655398861, 38.173614570312466 56.06757655398861, 38.173614570312466 55.432467441048146, 37.06399542968747 55.432467441048146, 37.06399542968747 56.06757655398861)))') YIELD node AS address
37
+ MATCH (address)<-[:расположен]-(b :Корпус)<-[:\`в составе\`]-(l :Лот)-[:тип]->(nt:\`Тип недвижимости\`)
38
+ WHERE l.price > 5000000 AND l.price < 10000000 AND nt.name = 'Апартаменты'
39
+ WITH b, {type: nt.name, rooms: l.rooms, count: COUNT(l), price: { min: MIN(l.price), max: MAX(l.price) }, square: { min: MIN(l.square), max: MAX(l.square) } } AS lots
40
+ WITH DISTINCT b, lots
41
+ //UNWIND db AS b
42
+ MATCH (d:Девелопер)<-[:проектируется]-(b)-[:строится]->(z:Застройщик)
43
+ RETURN b, d, z, COLLECT(lots)`
28
44
]
29
45
30
46
const promise = session . run (
@@ -36,7 +52,14 @@ const promise = session.run(
36
52
promise . then ( async result => {
37
53
session . close ( ) ;
38
54
39
- for ( let i = 0 ; i < schema . length - 1 ; i ++ ) {
55
+ for ( let i = 0 ; i < after . length ; i ++ ) {
56
+ console . time ( 'find' ) ;
57
+ let res = await session . run ( after [ i ] ) ;
58
+ console . timeEnd ( 'find' ) ;
59
+ console . log ( res ) ;
60
+ }
61
+
62
+ for ( let i = 0 ; i < schema . length ; i ++ ) {
40
63
await session . run ( schema [ i ] ) ;
41
64
}
42
65
@@ -58,13 +81,13 @@ promise.then(async result => {
58
81
await Promise . all ( queries ) ;
59
82
queries = [ ] ;
60
83
61
- let part = ids . splice ( 0 , 100 ) ;
84
+ let part = ids . splice ( 0 , 10 ) ;
62
85
let i = part . length - 1 ;
63
86
64
87
65
88
while ( i > - 1 ) {
66
89
67
- let id = parseInt ( part [ i ] ) ;
90
+ let id = part [ i ] ;
68
91
i -- ;
69
92
70
93
let url = `https://api.best-novostroy.ru/api/v1/dombook/building-by-id/${ id } ?include=lots` ;
@@ -155,14 +178,63 @@ promise.then(async result => {
155
178
const promise3 = session . run (
156
179
`WITH {building} as building
157
180
158
- MATCH (b :Корпус {id: building.id})
181
+ UNWIND CASE WHEN SIZE(building.lots) > 0 THEN [] ELSE [0] END AS m
182
+ WITH building, building.analytics AS analytics, ['st', 'sp', '1', '2', '3', '4'] AS rooms
183
+
184
+ UNWIND rooms AS room
185
+ WITH {
186
+ name: toString(building.id) + '_' + room,
187
+ building_id: building.id,
188
+ rooms: room,
189
+ is_studio: CASE WHEN room = 'st' THEN true ELSE false END,
190
+ is_open_plan: CASE WHEN room = 'sp' THEN true ELSE false END,
191
+ count: analytics['count_' + room],
192
+ price_min: analytics['price_min_' + room],
193
+ price_max: analytics['price_max_' + room],
194
+ price_square_min: analytics['price_square_min_' + room],
195
+ price_square_max: analytics['price_square_max_' + room],
196
+ square_min: analytics['square_min_' + room],
197
+ square_max: analytics['square_max_' + room],
198
+ finishing: building.finishings[0]
199
+ } AS stat
200
+ WHERE analytics['count_' + room] IS NOT NULL
201
+
202
+ WITH stat, {building} as building
203
+ MATCH (b :Корпус {id: building.id})
204
+ MERGE (s :Статистика {name: stat.name})
205
+ SET s += stat {.*, finishing: null}
206
+
207
+ MERGE (s)<-[:имеет]-(b)
208
+ WITH s AS stat
209
+
210
+ UNWIND ['_min', '_max'] AS minmax
211
+ WITH collect(DISTINCT {
212
+ is_fake: true,
213
+ rooms: stat.rooms,
214
+ is_studio: stat.is_studio,
215
+ is_open_plan: stat.is_open_plan,
216
+ price: stat['price' + minmax],
217
+ price_square: stat['price_square' + minmax],
218
+ square: stat['square' + minmax],
219
+ lot_finishing_type: stat.finishing,
220
+ id: stat.name + minmax,
221
+ stat_name: stat.name
222
+ }) AS lots
223
+
159
224
160
- UNWIND building.lots AS lot
225
+ UNWIND CASE WHEN SIZE(lots) = 0 THEN {building}.lots ELSE lots END AS lot
226
+ WITH lot, {building} AS building
227
+ MATCH (b :Корпус {id: building.id})
161
228
162
229
MERGE (l :Лот {id: lot.id})
163
230
SET l += lot {.identifier, .rooms, .created_at, .section, .price_square, .is_open_plan, .finishing, .number, .square,
164
- .is_studio, .updated_at, .price, .floor, .ceiling_height}
231
+ .is_studio, .updated_at, .price, .price_square, . floor, .ceiling_height, building_id: b.id }
165
232
233
+ MERGE (l)-[:\`в составе\`]-(b)
234
+
235
+ FOREACH(label IN CASE WHEN lot.is_fake = true THEN [0] ELSE [] END |
236
+ SET l:Фэйк
237
+ )
166
238
FOREACH(label IN CASE WHEN lot.is_studio = true THEN [0] ELSE [] END |
167
239
SET l:Студия
168
240
)
@@ -183,20 +255,35 @@ promise.then(async result => {
183
255
SET ph += photo
184
256
MERGE (l)-[:имеет]-(ph)
185
257
186
- MERGE (l)-[:\`в составе\`]-(b)
187
258
188
259
` ,
189
260
{ building }
190
261
) . catch ( err => {
191
262
console . log ( err ) ;
192
263
ids . push ( building . id ) ;
193
- } ) ; ;
264
+ } ) ;
265
+
266
+ /* const promise4 = session.run(
267
+ `
268
+
269
+ MATCH (n:Адрес) WHERE EXISTS(n.latitude) AND EXISTS(n.longitude)
270
+ WITH n
271
+ CALL spatial.addNode('geom',n) YIELD node
272
+ RETURN node;
273
+
274
+ `,
275
+ { building }
276
+ ).catch(err => {
277
+ console.log(err);
278
+ ids.push(building.id);
279
+ }); */
194
280
195
281
196
282
queries . push ( promise ) ;
197
283
queries . push ( promise1 ) ;
198
284
queries . push ( promise2 ) ;
199
285
queries . push ( promise3 ) ;
286
+ //queries.push(promise4);
200
287
201
288
202
289
} )
0 commit comments