ora/src/dashboard/components/Dev.svelte

53 lines
1.2 KiB
Svelte

<script>
import faker from 'faker/dist/faker.js'
import day from 'dayjs'
import { range, random } from 'lodash'
import { insertLog, normalizeTimestamp, DB, clear as clearDB } from '../../shared/db'
let loading = false
async function fill() {
try {
loading = true
const start = day().subtract(2, 'weeks').valueOf()
const end = Date.now()
for (const n of range(20)) {
const host = faker.internet.domainName()
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 })
}
}
} catch (e) {
console.error(e)
} finally {
loading = false
}
}
async function clear() {
try {
loading = true
await clearDB()
} finally {
loading = false
}
}
</script>
<div class="p-2">
<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>
</div>
<style>
div {
position: absolute;
top: 0;
right: 0;
}
</style>