-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
216 lines (189 loc) · 6.25 KB
/
main.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import base64
from pathlib import Path
import pandas as pd
import streamlit
import os
from pathlib import Path
import numpy as np
import pydeck as pdk
import random
from send_email import send_message
import streamlit as st
from PIL import Image
file_dir = Path(os.path.dirname(os.path.abspath(__file__)))
DATE_TIME = "date/time"
DATA_URL = file_dir / "data_long.csv"
@st.cache(persist=True)
def load_data(DATA_URL, nrows=None):
data = pd.read_csv(DATA_URL, nrows=nrows)
lowercase = lambda x: str(x).lower()
data.rename(lowercase, axis="columns", inplace=True)
try:
data[DATE_TIME] = pd.to_datetime(data[DATE_TIME])
except KeyError:
pass
return data
extra = load_data(file_dir / "data_long.csv")
extra = extra.dropna()
# CREATING FUNCTION FOR MAPS
def map(data, lat, lon, zoom):
st.write(
pdk.Deck(
map_style="mapbox://styles/mapbox/light-v9",
initial_view_state={
"latitude": float(lat),
"longitude": float(lon),
"zoom": zoom,
"pitch": 50,
},
layers=[
pdk.Layer(
"HexagonLayer",
data=data,
get_position=["lon", "lat"],
radius=500,
elevation_scale=50,
elevation_range=[0, 3000],
pickable=True,
extruded=True,
coverage=1,
),
],
)
)
def main():
img = Image.open(file_dir / "Images" / "logo-print.png")
st.image(img, width=200, use_column_width=200)
img2 = Image.open(file_dir / "Images" / "background.jpeg")
st.image(
img2,
caption="No task is so important that we can’t take the time to do it safely. A safe company is a successful company.",
)
# Title
st.header("Incidents Reporting")
# test_data = pd.concat([data]*20, ignore_index=True)
latitudes = [
"29.07393266320772",
"38.83889745592545",
"67.28150241774922",
"65.76861506352907",
"27.850857403798024",
"31.400790392869073",
"32.14315679366797",
"29.7828109",
"69.5259183676525",
"-38.41968552700519",
]
longitudes = [
"-95.74462745592294",
"-90.07362745592292",
"8.899795546234275",
"7.891749990422023",
"-98.58710217513708",
"-103.5499547076863",
"-102.18566929860735",
"-95.618529",
"-152.13526519858635",
"142.6508871470676",
]
basenames = [
"Sweeny Refinery",
"Wood River Refinery",
"SNE-1 well",
"Warka well",
"Eagle Ford Well",
"Permian Basin Well",
"Midland Well",
"Houston office",
"Alphine well",
"Otway Basin Well",
]
baseIDS = [
"B02512",
"B09768",
"B06567",
"B08798",
"B04673",
"B05767",
"B06376",
"B02783",
"B04237",
"B06788",
]
csv_location = [0, 0, 0]
# Added ,clear_on_submit=True to clear the fields once the submit button hass been pressed
with st.form("my_form", clear_on_submit=True):
st.write("Please Fill Out the Information Below")
# used for date in CSV file
date = st.date_input("Enter Date")
# Used for incidents csv file, DOES NOT PREVENT OR CHECK FOR IDENTICAL NUMBERS YET
incident_number = random.randint(100000, 9999999)
# Used to select incident typer
incident_type = st.selectbox(
"Select Type or Incident",
("Trip/Fall", "Heavy Equipment Violation", "Other"),
)
# Used for
location = st.selectbox(
"Select location, If not available select other and add in description below",
(
"Sweeny Refinery",
"Wood River Refinery",
"SNE-1 well",
"Warka well",
"Eagle Ford Well",
"Permian Basin Well",
"Midland Well",
"Houston office",
),
)
location_index = basenames.index(location)
csv_location[0] = basenames[location_index]
csv_location[1] = longitudes[location_index]
csv_location[2] = latitudes[location_index]
description = st.text_area(
"Enter a brief description, Include time, Number of people Involved and if Medical attention was required."
)
uploaded_file = st.file_uploader("Choose a file")
submitted = st.form_submit_button("Submit")
if submitted:
# Fetch Data from db
st.write("Submitted. Thank you for your dedication to safety.")
# ##### used for the location
base_ID = csv_location[0]
long_ID = csv_location[1]
lat_ID = csv_location[2]
print(description)
send_message(description)
# print(csv_location[0], csv_location[1], csv_location[2])
# used to display the map
with st.form("my_map"):
map_display = st.selectbox(
"View our current Incidents",
("", "All", "Trip/Fall", "Heavy Equipment Violation", "Other"),
)
submitted = st.form_submit_button("Submit")
if submitted:
if map_display == "All":
map(extra[["lat", "lon"]], csv_location[2], csv_location[1], 10)
elif map_display == "Trip/Fall":
# st.write("slider", slider_val, "checkbox", checkbox_val)
# map(data, lat, lon, zoom)
map(
extra.loc[extra["incident type"] == "trip"][["lat", "lon"]],
csv_location[2],
csv_location[1],
10,
)
elif map_display == "Heavy Equipment Violation":
map(
extra.loc[extra["incident type"] == "too close to heavy equipment"][
["lat", "lon"]
],
csv_location[2],
csv_location[1],
10,
)
# st.write("slider", slider_val, "checkbox", checkbox_val)
if __name__ == "__main__":
main()