-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapp.py
executable file
·131 lines (102 loc) · 5 KB
/
app.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
from flask import Flask, render_template, request, flash
from flask_mail import Message, Mail
import folium
from folium.plugins import FastMarkerCluster
from folium.plugins import Fullscreen
from folium import FeatureGroup, LayerControl, Map, Marker
import datetime
from forms import ContactForm
import numpy as np
import pandas as pd
import geopandas
from shapely.geometry import Point
import requests
import json
import re
import urllib.request
mail = Mail()
app = Flask(__name__)
app.secret_key = '****************'
app.config["MAIL_SERVER"] = "smtp.gmail.com"
app.config["MAIL_PORT"] = 465
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = '[email protected]'
app.config["MAIL_PASSWORD"] = '****************' # password generated in Google Account Settings under 'Security', 'App passwords',
# choose 'other' in the app menu, create a name (here: 'FlaskMail'),
# and generate password. The password has 16 characters.
# Copy/paste it under app.config["MAIL_PASSWORD"].
# It will give you access to your gmail when you have two steps verification.
mail.init_app(app)
@app.context_processor
def inject_today_date():
return {'year': datetime.date.today().year}
@app.route('/')
def home():
return render_template('home.html')
@app.route('/contact', methods=['GET', 'POST'])
def contact():
form = ContactForm()
if request.method == 'POST':
if form.validate() == False:
flash('All fields are required.')
return render_template('contact.html', form=form)
else:
msg = Message(form.subject.data, sender='[email protected]', recipients=['[email protected]'])
msg.body = """
From: %s <%s>
%s
""" % (form.name.data, form.email.data, form.message.data)
mail.send(msg)
return render_template('contact.html', success=True)
elif request.method == 'GET':
return render_template('contact.html', form=form)
@app.route('/map')
def well_map():
url = 'https://npdfactpages.npd.no/downloads/shape/wlbPoint.zip'
# change path to your local directory
urllib.request.urlretrieve(url, 'data/wlbPoint.zip')
# change path to your local directory
wells_explo = geopandas.read_file(
'zip://data/wlbPoint.zip', encoding='utf-8')
wells_explo['wlbEwDesDeg'] = wells_explo['geometry'].x
wells_explo['wlbNsDecDeg'] = wells_explo['geometry'].y
wells_explo_sel = wells_explo.filter(['wbName', 'well_name', 'discovery', 'field', 'prodLicenc', 'well_type', 'drilOperat',
'entryYear', 'cmplYear', 'content', 'main_area', 'totalDepth', 'age_at_TD', 'fmTD',
'discWelbor', 'geometry', 'wlbEwDesDeg', 'wlbNsDecDeg'],
axis=1)
wells_explo_all = wells_explo_sel.loc[wells_explo_sel['well_type'].isin([
'EXPLORATION'])]
map_wells = folium.Map(location=[wells_explo_all['wlbNsDecDeg'].mean(),
wells_explo_all['wlbEwDesDeg'].mean()],
zoom_start=5,
tiles='cartodbpositron'
)
fs = Fullscreen()
# adding an extra map background in the layer menu
tile = folium.TileLayer('OpenStreetMap').add_to(map_wells)
""" defining parameters for our markers and the popups when clicking on single markers """
callback = ('function (row) {'
'var marker = L.marker(new L.LatLng(row[0], row[1]));'
'var icon = L.AwesomeMarkers.icon({'
"icon: 'star',"
"iconColor: 'black',"
"markerColor: 'lightgray',"
'});'
'marker.setIcon(icon);'
"var popup = L.popup({maxWidth: '300'});"
"const display_text = {text: '<b>Name: </b>' + row[2] + '</br>' + '<b> Age at TD: </b>' + row[3]};"
"var mytext = $(`<div id='mytext' class='display_text' style='width: 100.0%; height: 100.0%;'> ${display_text.text}</div>`)[0];"
"popup.setContent(mytext);"
"marker.bindPopup(popup);"
'return marker};')
""" creating clusters with FastMarkerCluster """
fmc = FastMarkerCluster(wells_explo_all[[
'wlbNsDecDeg', 'wlbEwDesDeg', 'wbName', 'age_at_TD']].values.tolist(), callback=callback)
fmc.layer_name = 'Exploration Wells'
map_wells.add_child(fmc) # adding fastmarkerclusters to map
map_wells.add_child(fs) # adding fullscreen button to map
folium.LayerControl().add_to(map_wells) # adding layers to map
return map_wells._repr_html_()
if __name__ == '__main__':
# app.run(debug=True)
app.run("0.0.0.0", port=80, debug=False) # added host parameters for docker container