-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalyticsImport.cql
More file actions
123 lines (104 loc) · 3.72 KB
/
AnalyticsImport.cql
File metadata and controls
123 lines (104 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// ----------------------------------------------
// Well head identifier
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM 'file:///WellListLocationsWGS84.csv' AS line // with line limit 100
// create uuid
CALL apoc.create.uuids(1) YIELD uuid as wuuid
MERGE (c:Well { Uwi: line.UWI })
ON CREATE set
c.Uuid = wuuid,
c.LSD = (substring(line.UWI,3,14)),
c.Keylist = line.Keylist,
c.Name= line.Name,
c.TotalDepth= line.TotalDep,
c.WellStat= line.WellStat,
c.StatDate= line.StatDate,
c.FDDate= line.FDDate,
c.LicenseeId=left(line.Licensee,length(line.Licensee)-1),
c.License=line.License,
c.Latitude= toFloat(line.Y),
c.Longitude= toFloat(line.X)
ON MATCH set
c.Uuid = wuuid,
c.LSD = (substring(line.UWI,3,14)),
c.Keylist = line.Keylist,
c.Name= line.Name,
c.TotalDepth= line.TotalDep,
c.WellStat= line.WellStat,
c.StatDate= line.StatDate,
c.FDDate= line.FDDate,
c.LicenseeId=left(line.Licensee,length(line.Licensee)-1),
c.License=line.License,
c.Latitude= toFloat(line.Y),
c.Longitude= toFloat(line.X);
// Well WellLicensedTo Licensee
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM 'file:///WellListLocationsWGS84.csv' AS line //with line limit 100
MATCH(w:Well {Uwi:line.UWI})
MATCH(l:Licensee {Code: left(line.Licensee,length(line.Licensee)-1)})
MERGE (w)-[:LICENSEE_OF]->(l);
// match wells to licensee in memory using Code
MATCH (w:Well) where not ((w)-[:Licensee]-()) and not exists(w.CodeProcessed)
WITH w limit 5000
MATCH(l:Licensee {Code:w.LicenseeId})
MERGE (w)-[:LICENSEE_OF]->(l)
set w.CodeProcessed=true;
call apoc.periodic.commit("
MATCH (w:Well) where not exists(w.CodeProcessed)
WITH w limit {limit}
MATCH(l:Licensee {Code:w.LicenseeId})
MERGE (w)-[:Licensee]->(l)
set w.CodeProcessed=true
RETURN count(*)
",{limit:10000})
// Facility
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM 'file:///ActiveFacility.csv' AS line //with line limit 100
CALL apoc.create.uuids(1) YIELD uuid as fuuid
MERGE (f:Facility {Code: line.FacilityID})
ON CREATE set
f.Uuid= fuuid,
f.Name= line.FacilityName,
f.LSD= line.LSD,
f.Status= line.OperationalStatus,
f.OperatorCode=line.OperatorCode,
f.OperatorName = line.OperatorName,
f.LicenseeId=line.LicenseeCode;
// OPERATOR_OF
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM 'file:///ActiveFacility.csv' AS line
WITH line
where line.OperatorCode <> ''
// Facility OPERATOR_OF Licenseee
WITH line
MATCH(li:Licensee {Code:line.OperatorCode})
MATCH(f:Facility {Code:line.FacilityID})
MERGE (f)-[:OPERATOR_OF]->(o);
// Facility LICENSEE_OF Licenseee
WITH line
MATCH(li:Licensee {Code:line.OperatorCode})
MATCH(f:Facility {Code:line.FacilityID})
MERGE (f)-[:OPERATOR_OF]->(o);
// Import substance released records from edmonton open data portal
WITH 'yUEgWneqrRgNzGUIRQb7yW90M' as token, 70000 as pagesTotal
WITH token, RANGE(1,pagesTotal,1000) as fromNumber, "https://data.edmonton.ca/resource/xir8-nx6p.json?$limit=1000&$offset=number&$order=:id" as baseUrl
// loop through results by range step (1000 records is max)
UNWIND fromNumber as from
WITH token, from, REPLACE(baseUrl,'number',toString(from)) as Url
// sleep to prevent hitting throttling threshold
CALL apoc.util.sleep(1)
CALL apoc.load.jsonParams(Url,
{`X-App-Token`:token}, null
)
yield value as data
// generate spill node
WITH data as record //limit 5 - for testing
CALL apoc.create.uuids(1) YIELD uuid as Uuid
WITH record, Uuid, record.location_1 as locations // this statement pulls the locations out
MERGE (s:Spill {Code: record.incident_number})
ON MATCH
set
s.SubstanceReleased = record.substance_released,
s.VolumeRecovered = toFloat(record.volume_recovered),
s.VolumeReleased = toFloat(record.volume_released),
s.Units = record.volume_units