-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
226 lines (182 loc) · 6.54 KB
/
index.html
File metadata and controls
226 lines (182 loc) · 6.54 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Eigentrust WASM implementation</title>
<style>
@font-face {
font-family: 'DMSans';
src: url('https://fonts.gstatic.com/s/dmsans/v15/rP2Yp2ywxg089UriI5-g4vlH9VoD8Cmcqbu0-K4.woff2') format('woff2');
font-weight: normal;
font-style: normal;
}
h1,
h2 {
padding 0;
margin: 0;
}
#calculate,
#alphaValueInput {
padding: 10px;
text-transform: uppercase;
border-radius: 5px;
background-color: yellow;
color: black;
cursor: pointer;
}
body {
font-family: 'DMSans', sans-serif;
margin: auto;
padding: 0;
background-color: rgb(242, 243, 246);
}
.disabled {
cursor: wait !important;
background-color: rgb(242, 243, 246) !important;
}
.pad {
padding: 20px;
}
.line {
width: 100%;
height: 1px;
border-bottom: 1px solid #ccc;
}
.container {
display: flex;
width: 100%;
height: 100%;
}
.container2 {
background-color: white;
width: 100%;
margin: auto;
max-width: 1000px;
height: 100%;
padding: 0px;
border: 1px solid #ccc;
border-radius: 5px;
margin-top: 20px;
}
.upload-section {
flex: 1;
padding: 20px;
box-sizing: border-box;
border-right: 1px solid #ccc;
overflow-y: auto;
max-height: 400px;
min-height: 400px;
}
.upload-section:last-child {
border-right: none;
}
h1 {
font-size: 20px;
}
a {
color: black;
}
pre {
background-color: #f4f4f4;
padding: 10px;
overflow-x: auto;
white-space: pre-wrap;
border: 1px solid #ddd;
}
</style>
</head>
<body>
<div class="container2">
<div class="pad">
<h1>WASM Rust <a target="_blank" href="https://nlp.stanford.edu/pubs/eigentrust.pdf">EigenTrust</a></h1>
</div>
<div class="line"></div>
<div class="container">
<div class="upload-section" id="localTrustSection">
<h1>Local Trust</h1><br />
<input type="file" id="localTrustInput" accept=".csv">
<pre id="localTrustContent">Upload Local Trust CSV</pre>
</div>
<div class="upload-section" id="preTrustSection">
<h1>Seed Trust</h1><br />
<input type="file" id="preTrustInput" accept=".csv">
<br />
<pre id="preTrustContent">Upload Seed Trust CSV</pre>
</div>
</div>
<div class="line"></div>
<div class="pad">
<button id="calculate">Run Job</button>
<input type="number" id="alphaValueInput" placeholder="Alpha = 0.5" step="0.01" defaul="0.5">
<pre><span id="result"></span>[]</pre>
</div>
</div>
<script type="module">
let localtrustBytes = `alice,bob,2\nbob,charlie,2\nalice,charlie,1\ncharlie,bob,1\n`
let pretrustBytes = 'alice,1\n'
document.getElementById('localTrustContent').textContent = localtrustBytes
document.getElementById('preTrustContent').textContent = pretrustBytes;
localtrustBytes = new TextEncoder().encode(localtrustBytes)
pretrustBytes = new TextEncoder().encode(pretrustBytes)
document.getElementById('localTrustInput').addEventListener('change', async function (event) {
const file = event.target.files[0]
if (!file) return
const reader = new FileReader()
reader.onload = function (e) {
const csvText = e.target.result
if (csvText.length < 100000) {
document.getElementById('localTrustContent').textContent = csvText
} else {
document.getElementById('localTrustContent').textContent = '' + csvText.split('\n').length + ' lines loaded'
}
localtrustBytes = new TextEncoder().encode(csvText)
}
reader.readAsText(file)
})
document.getElementById('preTrustInput').addEventListener('change', async function (event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader()
reader.onload = function (e) {
const csvText = e.target.result
if (csvText.length < 100000) {
document.getElementById('preTrustContent').textContent = csvText
} else {
document.getElementById('preTrustContent').textContent = '' + csvText.split('\n').length + ' lines loaded'
}
pretrustBytes = new TextEncoder().encode(csvText)
};
reader.readAsText(file);
});
const worker = new Worker('worker.js');
worker.onmessage = function (e) {
document.getElementById('result').innerHTML = e.data
document.getElementById('calculate').classList.remove("disabled")
};
async function main() {
document.getElementById('calculate').addEventListener('click', () => {
if (!localtrustBytes || !pretrustBytes) {
alert('add localtrust and pretrust')
return
}
const alphaStr = document.getElementById('alphaValueInput').value
let alpha
if (!alphaStr) {
alpha = 0.5
} else {
alpha = parseFloat(alphaStr)
}
if (isNaN(alpha) || alpha > 1 || alpha < 0) {
alert('Please enter a valid alpha value', alpha)
return;
}
document.getElementById('calculate').classList.add("disabled")
document.getElementById('result').innerHTML = 'Running...'
worker.postMessage({ localtrustBytes, pretrustBytes, alpha });
})
}
main()
</script>
</body>
</html>