ora/src/dashboard/components/Dev.svelte

52 lines
1.2 KiB
Svelte
Raw Normal View History

2020-09-18 21:00:59 +02:00
<script>
import faker from 'faker'
import day from 'dayjs'
import { range, random } from 'lodash'
import { insertLog, normalizeTimestamp, DB } from '../../shared/db'
2020-09-18 21:00:59 +02:00
let loading = false
async function fill() {
try {
loading = true
const start = day().subtract('7', 'days').valueOf()
const end = Date.now()
2020-09-19 01:16:43 +02:00
for (const n of range(20)) {
2020-09-18 21:00:59 +02:00
const host = faker.internet.domainName()
2020-09-19 01:16:43 +02:00
for (const m of range(random(20))) {
const date = new Date(random(start, end))
const timestamp = normalizeTimestamp(date)
const seconds = random(15 * 60)
await insertLog({ host, timestamp, seconds })
2020-09-18 21:00:59 +02:00
}
}
} finally {
loading = false
}
}
async function clear() {
try {
loading = true
await DB.limits.clear()
await DB.logs.clear()
2020-09-18 21:00:59 +02:00
} finally {
loading = false
}
}
</script>
2020-09-20 17:28:09 +02:00
<style>
div {
position: absolute;
top: 0;
right: 0;
}
</style>
2020-09-18 21:00:59 +02:00
<div class="p-2">
2020-09-20 17:28:09 +02:00
<button class="btn btn-sm" class:loading disabled={loading} on:click={fill}>Add Random Data</button>
<button class="btn btn-sm btn-error" class:loading disabled={loading} on:click={clear}>Delete data</button>
2020-09-18 21:00:59 +02:00
</div>