ora/src/dashboard/components/Dev.svelte

53 lines
1.2 KiB
Svelte
Raw Normal View History

2020-09-18 21:00:59 +02:00
<script>
2021-11-22 01:36:18 +01:00
import faker from 'faker/dist/faker.js'
2020-09-18 21:00:59 +02:00
import day from 'dayjs'
import { range, random } from 'lodash'
2020-10-11 23:46:06 +02:00
import { insertLog, normalizeTimestamp, DB, clear as clearDB } from '../../shared/db'
2020-09-18 21:00:59 +02:00
let loading = false
async function fill() {
try {
loading = true
2020-10-11 23:46:06 +02:00
const start = day().subtract(2, 'weeks').valueOf()
2020-09-18 21:00:59 +02:00
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
}
}
2021-11-22 01:36:18 +01:00
} catch (e) {
console.error(e)
2020-09-18 21:00:59 +02:00
} finally {
loading = false
}
}
async function clear() {
try {
loading = true
2020-10-11 23:46:06 +02:00
await clearDB()
2020-09-18 21:00:59 +02:00
} finally {
loading = false
}
}
</script>
2021-11-22 01:36:18 +01:00
<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>
2020-09-20 17:28:09 +02:00
<style>
div {
position: absolute;
top: 0;
right: 0;
}
</style>