-
Notifications
You must be signed in to change notification settings - Fork 0
/
facilities.py
67 lines (53 loc) · 2.13 KB
/
facilities.py
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
# Copyright (C) 2016-2018, Dylan Grandmont
import os
import re
import sys
import math
import random
import csv
import numpy as np
from coordinatemapping import uwiToLatLng
from utilities import conformBCOGCLatLon, writeLicenseFile, writeDrillingFile
from constants import UNKNOWN
IONWC_HOME = os.environ["IONWC_HOME"]
def conform_uwi(uwi):
if "/" in uwi:
grid = "NTS"
else:
grid = "DLS"
if grid=="NTS":
uwi = "200" + uwi.replace("/", "").replace("-", "") + "00"
else:
uwi = uwi.split("-")
uwi = "00/" + uwi[0] + '-' + uwi[1] + '-' + uwi[2] + "W6/0"
return uwi
def addBCFacilitiesToDataBase(facilitiesFileAll):
""" Query for all BC facilities, parse them into a common format and add to database (csv) """
bcfacilties = 0
allBCLics = open(IONWC_HOME + "/data/facilities/bc/facilities.csv")
reader = csv.reader(allBCLics)
# Skip header (first row)
next(reader)
for row in reader:
facilityId = row[1]
facilityType = row[2]
objectType = row[3]
activity = row[4]
organization = row[5]
location = row[6] # B-023-E/094-A-14 --> 200B077D094H0300 or 06-06-086-13
approvalDate = row[7]
constructionStartDate = row[8]
pressureTestDate = row[9]
leaveToOpenDate = row[10]
asBuiltDate = row[11]
tenureFileNumber = row[12]
legalSurveyApprovalDate = row[13]
facilityStatus = row[14]
uwi = conform_uwi(location)
lat, lon = uwiToLatLng.convert(uwi)
random.seed(int(re.sub("[^0-9]","", facilityId)))
lat += random.uniform(-0.0005,0.0005)
lon += random.uniform(-0.0005,0.0005)
writeFaciltiesFile(facilitiesFileAll, facilityId, facilityType, organization, lat, lng)
bcfacilties += 1
print "INFO: Found", bcfacilties, " facilities for BC"