-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.py
181 lines (159 loc) · 8.03 KB
/
utilities.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Copyright (C) 2016-2018, Dylan Grandmont
import locale
import math
def get_substance_code(substance):
substance = substance.lower()
if 'oil' in substance:
substanceCode = '0'
elif 'gas' in substance:
substanceCode = '1'
elif 'methane' in substance:
substanceCode = '1'
elif 'bitum' in substance:
substanceCode = '2'
elif 'water' in substance:
substanceCode = '3'
else:
substanceCode = '4'
return substanceCode
def conform_substance(substance):
if substance == "0":
substance = "Unknown"
elif 'gas' in substance.lower():
substance = "Gas"
elif 'oil' in substance.lower():
substance = "Crude Oil"
return substance
def conformBCOGCLatLon(latitude, longitude):
latitude = latitude.strip().split()
longitude = longitude.strip().split()
latitude = float(latitude[0]) + float(latitude[1]) / 60.0 + float(latitude[2]) / 3600.0
longitude = -1.0 * (float(longitude[0]) + float(longitude[1]) / 60.0 + float(longitude[2]) / 3600.0)
return latitude, longitude
def reformat_dollars(dollar_string):
dollar_string = dollar_string.replace('$', '')
dollar_string = dollar_string.replace(',', '')
locale.setlocale(locale.LC_ALL, '')
try:
dollar_string = locale.currency(float(dollar_string), grouping = True)
except ValueError:
print "Unable to reformat amount as dollars"
return dollar_string
def km_per_degree_lat_lng(lat):
""" determine distance between degrees of latitude (const), using spheroid paramters """
e2 = 0.00669437999014
a = 6378.1370
pi = math.pi
km_per_degree_lat = pi * a * (1 - e2) / (180.0 * (1.0 - e2 * (math.sin(lat * pi / 180.0)**2)**(3.0/2.0)))
km_per_degree_lon = (pi * a * math.cos((lat * pi)/180.0)) / (180.0 * (1.0 - e2 * (math.sin(lat * pi / 180.0)**2))**0.5 )
return km_per_degree_lat, km_per_degree_lon
def writeLicenseFile(licenseFile, licensee, wellname, licnum, uwi, year, month, day, field, zone,
direct, sub, subcode, lat, lon, province):
licenseFile.write(licensee.replace(',','').title().strip() + ","
+ wellname.replace(',','').upper().strip() + ","
+ licnum.replace(',','').strip() + ","
+ uwi.replace(',','').strip() + ","
+ year + "." + month + "." + day + ","
+ year + "/" + month + ","
+ field.replace(',','').title().strip() + ","
+ zone.replace(',','').title().strip() + ","
+ direct.replace(',','').title().strip() + ","
+ sub.replace(',','').title().strip() + ","
+ subcode + ","
+ str(lat) + ","
+ str(lon) + ","
+ province + "\n")
def writeDrillingFile(drillingFile, licensee, wellname, licnum, uwi, year, month, day,
driller, rig, lat, lon, province):
drillingFile.write(licensee.title().strip() + ","
+ wellname.strip() + ","
+ licnum.strip() + ","
+ uwi.strip() + ","
+ year + "." + month + "." + day + ","
+ year + "/" + month + ","
+ driller.title().strip() + ","
+ rig.strip() + ","
+ str(lat) + ","
+ str(lon) + ","
+ province + "\n")
def writeAugmentedLicenceFile(augmentedLicencesFile, licensee, wellname, licnum, uwi, drilldate, drilldatemonth,
contract, rig, licdate, field, zone, orient, sub, subcode, lat, lng, province):
augmentedLicencesFile.write(licensee + ","
+ wellname + ","
+ licnum + ","
+ uwi + ","
+ drilldate + ","
+ drilldatemonth + ","
+ contract + ","
+ rig + ","
+ licdate + ","
+ field + ","
+ zone + ","
+ orient + ","
+ sub + ","
+ subcode + ","
+ str(lat) + ","
+ str(lng) + ","
+ province + "\n")
def writePostingOfferingDataBaseFile(outKmlFile, saleDate, contractType, contractNo, hectares, tractNo, uwi,
topQualifiedZone, baseQualifiedZone, topAge, baseAge, kmlPolygon, province):
outKmlFile.write(saleDate + ':'
+ contractType + ':'
+ str(contractNo) + ':'
+ str(hectares) + ':'
+ str(tractNo) + ':'
+ uwi + ':'
+ topQualifiedZone +':'
+ baseQualifiedZone + ':'
+ str(topAge) + ':'
+ str(baseAge) + ':'
+ kmlPolygon + ':'
+ province + '\n')
def writePostingOfferingAggregateDataBaseFile(ponAggregateDataBaseFile, saleDate, contractType, contractNo, hectares,
aggregateLatitude, aggregateLongitude, province):
ponAggregateDataBaseFile.write(saleDate + ':'
+ contractType + ':'
+ str(contractNo) + ':'
+ str(hectares) + ':'
+ str(aggregateLatitude) + ':'
+ str(aggregateLongitude) + ':'
+ province + '\n')
def writePostingResultDataBaseFile(psrDataBaseFile, saleDate, status, bonus, dollarPerHectare, clientDescription,
contractType, contractNumber, hectares, tractNo, uwi, topZone, baseZone, topAge,
baseAge, geometry, province):
psrDataBaseFile.write(saleDate + ':'
+ status + ':'
+ reformat_dollars(bonus) + ':'
+ reformat_dollars(dollarPerHectare) + ':'
+ clientDescription.title() + ':'
+ contractType + ':'
+ str(contractNumber) + ':'
+ str(hectares) + ':'
+ str(tractNo) + ':'
+ uwi + ':'
+ topZone + ':'
+ baseZone + ':'
+ str(topAge) + ':'
+ str(baseAge) + ':'
+ geometry + ':'
+ province + '\n')
def writePostingResultAggregateDataBaseFile(psrAggregateDataBaseFile, saleDate, status, bonus, dollarPerHectare, clientDescription,
contractType, contractNumber, hectares, aggregateLatitude, aggregateLongitude, province):
psrAggregateDataBaseFile.write(saleDate + ':'
+ status + ':'
+ reformat_dollars(bonus) + ':'
+ reformat_dollars(dollarPerHectare) + ':'
+ clientDescription.title() + ':'
+ contractType + ':'
+ contractNumber + ':'
+ str(hectares) + ':'
+ str(aggregateLatitude) + ':'
+ str(aggregateLongitude) + ':'
+ province + '\n')
def writeFaciltiesFile(facilitiesFileAll, facilityId, facilityType, organization, lat, lng):
facilitiesFileAll.write(facilitiesFileAll + ':'
+ facilityId + ':'
+ facilityType + ':'
+ organization + ':'
+ lat + ':'
+ lng + '\n')