Skip to content

Commit

Permalink
working deposit simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
tbruyelle committed Dec 3, 2024
1 parent 682a6fc commit aee1d22
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
24 changes: 15 additions & 9 deletions docs/deposit.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
<html>
<head>
<script src="https://go-echarts.github.io/go-echarts-assets/assets/echarts.min.js"></script>
<script src="https://go-echarts.github.io/go-echarts-assets/assets/echarts.min.js"></script>
</head>
NumProposals <input type=number id="numProposals" min=0 value=0 /><br>
Alpha UP <input id="alphaUp" value='0.1' /><br>
Alpha DOWN <input id="alphaDown" value='0.05' /><br>
k <input type=number id="k" value='1' />
<body>
<style> .container {display: flex;justify-content: center;align-items: center;} .item {margin: auto;} </style>
<div class="container">
<div class="item" id="main" style="width:900px;height:700px;"></div>
</div>
<table border=0>
<tr><td>NumProposals</td><td><input type=number id="numProposals" min=0 value=0 /></td></tr>
<tr><td>Alpha UP<td><input id="alphaUp" type=number value='0.01' min=0 max=1 step='0.01' /></td></tr>
<tr><td>Alpha DOWN<td><input id="alphaDown" type=number value='-0.005' min=-1 max=0 step='0.01' /></td></tr>
<tr><td>k</td><td><input type=number id="k" value='1' step='0.01' /></td></tr>
<tr>
<td><button onclick='reset()'>Reset</button></td>
<td><button id='pauseResume' onclick='pauseResume()'>Pause</button></td>
</tr>
</table>
<style> .container {display: flex;justify-content: center;align-items: center;} .item {margin: auto;} </style>
<div class="container">
<div class="item" id="main" style="width:1200px;height:700px;"></div>
</div>

<script src="deposit.js" ></script>
</body>
Expand Down
48 changes: 34 additions & 14 deletions docs/deposit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,43 @@ option = {
}
},
xAxis: {
name: 'Block height',
// type: 'value',
name: 'Block height',
},
yAxis: [
{
name: 'Deposit',
type: 'value',
boundaryGap: [0, '25%'],
// splitLine: {
// show: false
// }
boundaryGap: [0, '25%'],
},
{
name: 'Num proposals',
type: 'value',
Show: false,
min: 0,
max: 6,
// splitLine: {
// show: false
// }
},
],
legend: {
data: ['Num proposals', 'Deposit'],
}
};

function reset() {
deposits = [];
numProposals = [];
document.getElementById('numProposals').value = 0;
}

let paused = false

function pauseResume() {
if (paused) {
paused=false
document.getElementById('pauseResume').innerHTML='Pause'
} else {
document.getElementById('pauseResume').innerHTML='Resume'
paused=true
}
}

function computeDeposit(n) {
let lastDeposit = defaultDeposit
if (deposits.length>0) {
Expand All @@ -64,17 +76,23 @@ function computeDeposit(n) {
beta = -1
}
let k = parseFloat(document.getElementById('k').value);
let v = (n - N + beta) ** (1/k)
let v = (Math.abs(n - N + beta)) ** (1/k)

D = lastDeposit * (1 + alpha * v)
console.log("D="+D)
let D = lastDeposit * (1 + alpha * v)
console.log(`lastDeposit=${lastDeposit} alpha=${alpha} beta=${beta} k=${k} n=${n}`)
console.log(`n - N + beta = ${n - N + beta}`)
console.log(`(Math.abs(n - N + beta)) ** (1/k) = ${v}`)
console.log(`alpha * (Math.abs(n - N + beta)) ** (1/k) = ${alpha * v}`)
if (D < defaultDeposit) {
D = defaultDeposit
}
return D
}

setInterval(function () {
if (paused) {
return
}
nbBlocks++
n = parseInt(document.getElementById('numProposals').value);
// deposits.shift();
Expand All @@ -86,11 +104,13 @@ setInterval(function () {
{
type: 'line',
data: deposits,
symbolSize: 3,
},
{
type: 'line',
data: numProposals,
yAxisIndex: 1,
symbolSize: 3,
}
]
});
Expand Down

0 comments on commit aee1d22

Please sign in to comment.