forked from Nathaniel633/WRONG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtbftPredict.md
113 lines (112 loc) · 4.83 KB
/
tbftPredict.md
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
---
toc: true
comments: true
title: TBFT! Predict your Successes!
type: hacks
courses: { compsci: {week: 28} }
permalink: /tbftpredict/
---
<html>
<style>
.bg2 {
color: black;
font-size: large;
width: 100;
height: 100vh;
background: url(https://media.giphy.com/media/xUOxeQaTAqYBXq5j1u/giphy.gif);
background-repeat: no-repeat;
background-size: cover;
background-repeat: no-repeat;
background-blend-mode: hard-light;
font-weight: bold;
text-align: center;
}
.results {
color: limegreen;
font-size: xx-large;
}
.badresults {
color: red;
font-size: xx-large;
}
</style>
<head>
<title>Whats your chance of winning in tbft?</title>
</head>
<body>
<div class="container" class="bg2">
<h1>Will you win?</h1>
<form id="titanicForm" >
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="age">Age:</label>
<input type="number" id="age" name="age"><br><br>
<label for="sex">Sex:</label>
<select id="sex" name="sex">
<option value="male">Male</option>
<option value="female">Female</option>
</select><br><br>
<label for="dhand">Dominant Hand:</label>
<select id="dhand" name="dhand">
<option value="right">Right</option>
<option value="left">Left</option>
</select><br><br>
<label for="fmove">First Move:</label>
<select id="fmove" name="fmove">
<option value="one">1</option>
<option value="two">2</option>
</select><br><br>
<label for="fattack">First Attack:</label>
<input type="text" id="fattack" name="fattack"><br><br>
<button type="submit" class="btn btn-primary">Predict</button>
</form>
<h1 id="result"></h1>
</div>
<script>
// uri variable and options object are obtained from config.js
// import { uri, options } from '{{site.baseurl}}/assets/js/api/config.js';
// Get the modal
document.getElementById('titanicForm').addEventListener('submit', function(event) {
event.preventDefault();
const form = event.target;
var formData = {
'name': document.getElementById('name').value,
'age': parseInt(document.getElementById('age').value),
'sex': document.getElementById('sex').value,
'dominanthand': document.getElementById('dhand').value,
'firstmove': parseInt(document.getElementById('fmove').value),
'firstattack': parseInt(document.getElementById('fattack').value),
};
const url = 'http://127.0.0.1:8086/api/tbftML/predict';
// Change options according to Authentication requirements
const authOptions = {
method: 'POST', // Override the method property
mode: 'cors', // no-cors, *cors, same-origin
cache: 'default', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'include', // include, same-origin, omit
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(formData),
};
fetch(url, authOptions)
.then(response => response.json())
.then(data => {
// Create a text node with the death probability
// var textNode = document.createTextNode("Here's your chance of death: " + data.death_probability);
// // Clear any existing content in the result div
// document.getElementById('result').innerHTML = '';
// // Append the text node to the result div
// document.getElementById('result').appendChild(textNode);
// // Predict and Display Prediction result
var probability = (data.win * 100).toFixed(2) + '%'
// document.getElementById('result').innerHTML = "Here's your chance of death: " + data.death_probability;
document.getElementById('result').innerHTML = 'Your Chance of winning is = '+ probability;
})
.catch(error => {
console.error('Error:', error);
});
});
</script>
</body>
</html>