Code cleanup

This commit is contained in:
Austin Chen 2021-12-01 00:43:30 -08:00
parent 3d5f7906ab
commit d49f785cee

View File

@ -6,7 +6,7 @@
type="range" type="range"
v-model.number="steps" v-model.number="steps"
min="1" min="1"
:max="entries.length" :max="allEntries.length"
/> />
<!-- Two-column layout (on large screen sizes) --> <!-- Two-column layout (on large screen sizes) -->
<div class="grid grid-cols-1 lg:grid-cols-2"> <div class="grid grid-cols-1 lg:grid-cols-2">
@ -27,23 +27,23 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr v-for="(entry, i) in truncatedEntries"> <tr v-for="(entry, i) in entries">
<th>{{ i + 1 }}</th> <th>{{ i + 1 }}</th>
<template v-if="entry.yesBid"> <template v-if="entry.yesBid">
<td><div class="badge badge-success">YES</div></td> <td><div class="badge badge-success">YES</div></td>
<td>{{ entry.yesBid }}</td> <td>{{ entry.yesBid }}</td>
<td>{{ entry.yesWeight.toFixed(2) || '' }}</td> <td>{{ entry.yesWeight.toFixed(2) }}</td>
<td>{{ entry.prob.toFixed(2) || '' }}</td> <td>{{ entry.prob.toFixed(2) }}</td>
<td>{{ entry.yesPayout.value.toFixed(2) || '' }}</td> <td>{{ entry.yesPayout.value.toFixed(2) }}</td>
<td>{{ (entry.yesReturn.value * 100).toFixed(2) || '' }}%</td> <td>{{ (entry.yesReturn.value * 100).toFixed(2) }}%</td>
</template> </template>
<template v-else> <template v-else>
<td><div class="badge badge-error">NO</div></td> <td><div class="badge badge-error">NO</div></td>
<td>{{ entry.noBid }}</td> <td>{{ entry.noBid }}</td>
<td>{{ entry.noWeight.toFixed(2) || '' }}</td> <td>{{ entry.noWeight.toFixed(2) }}</td>
<td>{{ entry.prob.toFixed(2) || '' }}</td> <td>{{ entry.prob.toFixed(2) }}</td>
<td>{{ entry.noPayout.value.toFixed(2) || '' }}</td> <td>{{ entry.noPayout.value.toFixed(2) }}</td>
<td>{{ (entry.noReturn.value * 100).toFixed(2) || '' }}%</td> <td>{{ (entry.noReturn.value * 100).toFixed(2) }}%</td>
</template> </template>
</tr> </tr>
</tbody> </tbody>
@ -59,7 +59,7 @@ import { bids } from './orders'
import { ref, computed } from '@vue/reactivity' import { ref, computed } from '@vue/reactivity'
import { onMounted, watch } from '@vue/runtime-core' import { onMounted, watch } from '@vue/runtime-core'
const entries = [] as any const allEntries = [] as any
// Constants. TODO: Pull these from the orders instead of hardcoding. // Constants. TODO: Pull these from the orders instead of hardcoding.
const YES_SEED = 1 const YES_SEED = 1
const NO_SEED = 9 const NO_SEED = 9
@ -70,18 +70,18 @@ let noPot = 0
const steps = ref(10) const steps = ref(10)
// Computed variables: stop the simulation at the appropriate number of steps // Computed variables: stop the simulation at the appropriate number of steps
const truncatedEntries = computed(() => entries.slice(0, steps.value)) const entries = computed(() => allEntries.slice(0, steps.value))
const yesPotC = computed(() => const yesPotC = computed(() =>
truncatedEntries.value.reduce((acc, entry) => acc + entry.yesBid, 0) entries.value.reduce((acc, entry) => acc + entry.yesBid, 0)
) )
const noPotC = computed(() => const noPotC = computed(() =>
truncatedEntries.value.reduce((acc, entry) => acc + entry.noBid, 0) entries.value.reduce((acc, entry) => acc + entry.noBid, 0)
) )
const yesWeightsC = computed(() => const yesWeightsC = computed(() =>
truncatedEntries.value.reduce((acc, entry) => acc + entry.yesWeight, 0) entries.value.reduce((acc, entry) => acc + entry.yesWeight, 0)
) )
const noWeightsC = computed(() => const noWeightsC = computed(() =>
truncatedEntries.value.reduce((acc, entry) => acc + entry.noWeight, 0) entries.value.reduce((acc, entry) => acc + entry.noWeight, 0)
) )
// Calculations: // Calculations:
@ -107,13 +107,13 @@ for (const bid of bids) {
const yesReturn = computed(() => (yesPayout.value - yesBid) / yesBid) const yesReturn = computed(() => (yesPayout.value - yesBid) / yesBid)
const noReturn = computed(() => (noPayout.value - noBid) / noBid) const noReturn = computed(() => (noPayout.value - noBid) / noBid)
entries.push({ allEntries.push({
yesBid, yesBid,
noBid, noBid,
// Show two decimal places // Show two decimal places
yesWeight: yesWeight, yesWeight,
noWeight: noWeight, noWeight,
prob: prob, prob,
yesPayout, yesPayout,
noPayout, noPayout,
yesReturn, yesReturn,
@ -122,7 +122,7 @@ for (const bid of bids) {
} }
// Graph the probabilities over time // Graph the probabilities over time
const probs = computed(() => truncatedEntries.value.map((entry) => entry.prob)) const probs = computed(() => entries.value.map((entry) => entry.prob))
onMounted(initChart) onMounted(initChart)
watch(steps, renderChart) watch(steps, renderChart)