generated from nighthawkcoders/Nighthawk-Pages
-
Notifications
You must be signed in to change notification settings - Fork 2
/
titanic.html
281 lines (257 loc) · 8.59 KB
/
titanic.html
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
---
layout: base
title: Titanic
permalink: /titanic
---
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Titanic Survival Detection</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-image: url("enter");
background-position: 50% 0;
background-size: cover;
background-attachment: fixed;
background-repeat: no-repeat;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
color: #3f51b5;
font-size: 36px;
margin-bottom: 20px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}
form {
max-width: 600px;
margin: 0 auto;
}
p {
color: #555;
font-size: 16px;
line-height: 1.5;
}
label {
font-weight: bold;
display: block;
margin-bottom: 5px;
color: #333;
}
input,
select {
width: calc(100% - 22px);
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
font-size: 16px;
}
button {
background-color: #3f51b5;
color: #fff;
border: none;
border-radius: 5px;
padding: 12px 24px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #303f9f;
}
#result {
margin-top: 20px;
}
#result p {
color: #333;
font-size: 16px;
}
/* Home button style */
#homeButton {
position: fixed;
top: 20px;
left: 20px;
font-size: 16px;
text-decoration: none;
color: #333;
padding: 5px 10px;
border: 1px solid #ccc;
border-radius: 4px;
background-color: #f2f2f2;
}
</style>
<!-- Home button linking to index.html -->
<a id="homeButton" href="index">Home</a>
<div class="container">
<h1>Titanic Survival Prediction</h1>
<form id="titanicForm">
<div>
<form>
<p><label>
Name:
<input type="text" name="name" id="name" required>
</label></p>
<p><label>
Passenger Class:
<select name="pclass" id="pclass" required>
<option value=""> </option>
<!-- Blank value -->
<option value="1">1st Class</option>
<option value="2">2nd Class</option>
<option value="3">3rd Class</option>
</select>
<br>
<br>
Sex:
<select name="sex" id="sex" required>
<option value=""> </option>
<!-- Blank value -->
<option value="male">Male</option>
<option value="female">Female</option>
</select>
<br>
<br>
Age:
<input type="text" name="age" id="age" required>
</label></p>
<p><label>
Number of Siblings/ Spouses:
<input type="text" name="sibsp" id="sibsp" required>
</label></p>
<p><label>
Number of Parents or Children on Board:
<input type="text" name="parch" id="parch" required>
</label></p>
<p><label>
Fare:
<input type="text" name="fare" id="fare" required>
</label></p>
<p><label>
Embarked From:
<select name="embarked" id="embarked" required>
<option value=""> </option>
<!-- Blank value -->
<option value="S">Southampton</option>
<option value="C">Cherbourg</option>
<option value="Q">Queenstown</option>
</select>
</label></p>
Alone?:
<select name="alone" id="alone" required>
<option value=""> </option>
<!-- Blank value -->
<option value="True">Yes</option>
<option value="False">No</option>
</select>
<br>
<br>
</form>
<button type="button" onclick="create_user()">Submit</button>
</div>
</form>
</div>
<div id="probabilities">
<p>Survival Probability: <span id="survivalProbability"></span></p>
<p>Death Probability: <span id="deathProbability"></span></p>
</div>
<!-- Table -->
<h2>Titanic Records</h2>
<table id="userTable">
<tr>
<th>Name</th>
<th>Pclass</th>
<!-- passanger class -->
<th>Sex</th>
<th>Age</th>
<th>Sibsp</th>
<!-- siblings/spouses on board -->
<th>Parch</th>
<!-- parent/children on board -->
<th>Fare</th>
<th>Embarked</th>
<!-- coming from ex: Southampton -->
<th>Alone?</th>
<th>Survival Chance</th>
<th>Death Chance</th>
</tr>
</table>
<script>
// User creation
function create_user() {
const name = document.getElementById('name').value;
const pclass = document.getElementById('pclass').value;
const sex = document.getElementById('sex').value;
const age = document.getElementById('age').value;
const sibsp = document.getElementById('sibsp').value;
const parch = document.getElementById('parch').value;
const fare = document.getElementById('fare').value;
const embarked = document.getElementById('embarked').value;
const alone = document.getElementById('alone').value;
const formData = {
"name": name,
"pclass": pclass,
"sex": sex,
"age": age,
"sibsp": sibsp,
"parch": parch,
"fare": fare,
"embarked": embarked,
"alone": alone
};
fetch('http://127.0.0.1:8432/api/titanic/create', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
})
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error('User creation failed');
}
})
//pulls data of probability of surviving and dying
.then(data => {
const survivalProbability = data.alive_proba;
const deathProbability = data.dead_proba;
const survivalProbabilityNumeric = parseFloat(survivalProbability);
const deathProbabilityNumeric = parseFloat(deathProbability);
console.log("Survival Probability:", survivalProbabilityNumeric);
console.log("Death Probability:", deathProbabilityNumeric);
document.getElementById('survivalProbability').textContent = survivalProbabilityNumeric.toFixed(2);
document.getElementById('deathProbability').textContent = deathProbabilityNumeric.toFixed(2);
addRowToTable(formData, survivalProbabilityNumeric, deathProbabilityNumeric);
})
.catch(error => {
console.error('Error:', error);
alert("User Creation failed. Try again.");
});
}
//adds data to table
function addRowToTable(data, survivalProbability, deathProbability) {
const table = document.getElementById('userTable');
const row = table.insertRow(-1); // Insert a new row at the end of the table
const cells = ['name', 'pclass', 'sex', 'age', 'sibsp', 'parch', 'fare', 'embarked', 'alone'];
cells.forEach(cell => {
const newCell = row.insertCell(-1);
newCell.textContent = data[cell];
});
const survivalCell = row.insertCell(-1);
survivalCell.textContent = survivalProbability.toFixed(2);
const deathCell = row.insertCell(-1);
deathCell.textContent = deathProbability.toFixed(2);
}
</script>