Skip to content

Commit ff75374

Browse files
committed
commit
1 parent a9f7b60 commit ff75374

File tree

3 files changed

+174
-19
lines changed

3 files changed

+174
-19
lines changed

package-lock.json

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server.js

+96-9
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,36 @@ const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic('neo4j', '
1111

1212
const session = driver.session();
1313

14+
1415
let schema = [
1516
'CREATE INDEX ON :Адрес(name)',
1617
'CREATE INDEX ON :Девелопер(name)',
1718
'CREATE INDEX ON :Застройщик(name)',
1819
'CREATE INDEX ON :Класс(name)',
1920
'CREATE INDEX ON :Конструктив(name)',
2021
'CREATE INDEX ON :Корпус(id)',
22+
'CREATE INDEX ON :Лот(id)',
23+
'CREATE INDEX ON :Лот(price)',
2124
'CREATE INDEX ON :Отделка(name)',
2225
'CREATE INDEX ON :Проект(name)',
2326
'CREATE INDEX ON :Стадия(name)',
2427
'CREATE INDEX ON :`Тип парковки`(name)',
2528
'CREATE INDEX ON :`Тип недвижимости`(name)',
2629
'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)`
2844
]
2945

3046
const promise = session.run(
@@ -36,7 +52,14 @@ const promise = session.run(
3652
promise.then(async result => {
3753
session.close();
3854

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++) {
4063
await session.run(schema[i]);
4164
}
4265

@@ -58,13 +81,13 @@ promise.then(async result => {
5881
await Promise.all(queries);
5982
queries = [];
6083

61-
let part = ids.splice(0, 100);
84+
let part = ids.splice(0, 10);
6285
let i = part.length - 1;
6386

6487

6588
while(i > -1) {
6689

67-
let id = parseInt(part[i]);
90+
let id = part[i];
6891
i--;
6992

7093
let url = `https://api.best-novostroy.ru/api/v1/dombook/building-by-id/${id}?include=lots`;
@@ -155,14 +178,63 @@ promise.then(async result => {
155178
const promise3 = session.run(
156179
`WITH {building} as building
157180
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+
159224
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})
161228
162229
MERGE (l :Лот {id: lot.id})
163230
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}
165232
233+
MERGE (l)-[:\`в составе\`]-(b)
234+
235+
FOREACH(label IN CASE WHEN lot.is_fake = true THEN [0] ELSE [] END |
236+
SET l:Фэйк
237+
)
166238
FOREACH(label IN CASE WHEN lot.is_studio = true THEN [0] ELSE [] END |
167239
SET l:Студия
168240
)
@@ -183,20 +255,35 @@ promise.then(async result => {
183255
SET ph += photo
184256
MERGE (l)-[:имеет]-(ph)
185257
186-
MERGE (l)-[:\`в составе\`]-(b)
187258
188259
`,
189260
{ building }
190261
).catch(err => {
191262
console.log(err);
192263
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+
}); */
194280

195281

196282
queries.push(promise);
197283
queries.push(promise1);
198284
queries.push(promise2);
199285
queries.push(promise3);
286+
//queries.push(promise4);
200287

201288

202289
})

stat.cql

+70-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,38 @@ WITH {rooms: room, is_studio: CASE WHEN room = 'st' THEN true ELSE false END, is
1919
count: analytics['count_' + room], price: { min: analytics['price_min_' + room], max: analytics['price_max_' + room] }, price_square: { min: analytics['price_square_min_' + room], max: analytics['price_square_max_' + room] }, square: { min: analytics['square_min_' + room], max: analytics['square_max_' + room] } } AS stat WHERE analytics['count_' + room] IS NOT NULL
2020
WITH collect(stat) AS statistics
2121
RETURN *
22-
//
22+
///////////////////////////////
23+
WITH 'https://api.best-novostroy.ru/api/v1/dombook/building-by-id/403?include=lots' AS url
24+
CALL apoc.load.jsonParams(url,{Authorization:'Basic ZG9tYm9vazozZDUxMjVjMTYwNDYwNjgxZGEzMDc2MWNjMmVjNDc2NDZmOTllMTNjMDc3ZWQ4MjdhMTM1ZDQyMDczZDE0Yjk4'}, null)
25+
YIELD value as building
26+
//RETURN SIZE(building.lots);
27+
28+
UNWIND CASE WHEN SIZE(building.lots) > 0 THEN [] ELSE [0] END AS m
29+
WITH building, building.analytics AS analytics, ['price', 'square'] AS keys, ['st', 'sp', '1', '2', '3', '4'] AS rooms, ['_min_', '_max_'] AS minmax
30+
31+
UNWIND rooms AS room
32+
WITH {rooms: room,
33+
is_studio: CASE WHEN room = 'st' THEN true ELSE false END,
34+
is_open_plan: CASE WHEN room = 'sp' THEN true ELSE false END,
35+
count: analytics['count_' + room],
36+
price: { min: analytics['price_min_' + room], max: analytics['price_max_' + room] },
37+
price_square: { min: analytics['price_square_min_' + room], max: analytics['price_square_max_' + room] },
38+
square: { min: analytics['square_min_' + room], max: analytics['square_max_' + room] },
39+
finishing: building.finishings[0]
40+
} AS stat
41+
WHERE analytics['count_' + room] IS NOT NULL
42+
WITH collect(stat) AS statistics
43+
UNWIND statistics AS stat
44+
UNWIND ['min', 'max'] AS minmax
45+
WITH statistics, collect(DISTINCT stat {
46+
.rooms, .is_studio, .is_open_plan,
47+
price: stat.price[minmax],
48+
price_square: stat.price_square[minmax],
49+
square: stat.square[minmax],
50+
lot_finishing_type: stat.finishing
51+
}) AS lot
52+
RETURN *
53+
//////////////////////////////////////////
2354
CALL spatial.addPointLayer('geom');
2455
CALL spatial.layers();
2556

@@ -62,6 +93,34 @@ MATCH (d:Девелопер)<-[:проектируется]-(b)-[:строитс
6293
RETURN DISTINCT b.name, COLLECT(DISTINCT d.name) AS d, COLLECT(DISTINCT z.name) AS z, {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
6394
//MULTIPOLYGON( ( (1 1,5 1,5 5,1 5,1 1) ,(2 2, 3 2, 3 3, 2 3,2 2) ), ( (3 3,6 2,6 4,3 3) ) )
6495

96+
CALL spatial.intersects('geom', 'POLYGON((37.43770224731442 55.676943531025884, 37.55855185668943 55.676943531025884, 37.55855185668943 55.63715317690114, 37.43770224731442 55.63715317690114, 37.43770224731442 55.676943531025884))') YIELD node AS address
97+
98+
"[
99+
[
100+
[
101+
[
102+
55.676943531025884,
103+
37.43770224731442
104+
],
105+
[
106+
55.676943531025884,
107+
37.55855185668943
108+
],
109+
[
110+
55.63715317690114,
111+
37.55855185668943
112+
],
113+
[
114+
55.63715317690114,
115+
37.43770224731442
116+
],
117+
[
118+
55.676943531025884,
119+
37.43770224731442
120+
]
121+
]
122+
]
123+
]"
65124
[
66125
56.06757655398861,
67126
37.06399542968747
@@ -81,4 +140,13 @@ RETURN DISTINCT b.name, COLLECT(DISTINCT d.name) AS d, COLLECT(DISTINCT z.name)
81140
[
82141
56.06757655398861,
83142
37.06399542968747
84-
]
143+
]
144+
145+
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
146+
MATCH (address)<-[:расположен]-(b :Корпус)
147+
WITH DISTINCT b AS b SKIP 50 LIMIT 20
148+
MATCH (b)<-[:`в составе`]-(l :Лот)-[:тип]->(nt:`Тип недвижимости`)
149+
WHERE l.price > 5000000 AND l.price < 10000000 //AND nt.name = 'Апартаменты'
150+
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
151+
MATCH (d:Девелопер)<-[:проектируется]-(b)-[:строится]->(z:Застройщик)
152+
RETURN b, d, z, COLLECT(lots)

0 commit comments

Comments
 (0)