mirror of
https://github.com/cupcakearmy/ora.git
synced 2024-12-22 08:06:28 +00:00
show progress on limits
This commit is contained in:
parent
2e4ec02aa7
commit
08984480b1
@ -1,10 +1,43 @@
|
|||||||
<script>
|
<script>
|
||||||
import dj from 'dayjs'
|
import dj from 'dayjs'
|
||||||
import { Logs } from '../../shared/db.js'
|
import { sum } from 'lodash'
|
||||||
|
|
||||||
|
import { Logs } from '../../shared/db.js'
|
||||||
|
import { getLogsBetweenDates } from '../lib.js'
|
||||||
|
|
||||||
|
export let host = ''
|
||||||
export let rules = []
|
export let rules = []
|
||||||
|
|
||||||
|
$: percentages = rules.map(async ({ every }) => {
|
||||||
|
const durationAsSeconds = dj.duration(...every).asSeconds()
|
||||||
|
const start = dj().subtract(durationAsSeconds, 's').toDate()
|
||||||
|
console.log(start)
|
||||||
|
const logs = await getLogsBetweenDates({
|
||||||
|
start,
|
||||||
|
end: new Date(),
|
||||||
|
host,
|
||||||
|
})
|
||||||
|
console.log(logs)
|
||||||
|
|
||||||
|
const consumed = sum(logs.map((log) => log.seconds))
|
||||||
|
return (consumed / durationAsSeconds) * 100
|
||||||
|
console.log(total, dj.duration(total, 's').humanize())
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#each rules as rule}
|
{#each rules as rule, i}
|
||||||
<div>{dj.duration(...rule.limit).humanize()} / {dj.duration(...rule.every).humanize()}</div>
|
<div>{dj.duration(...rule.limit).humanize()} / {dj.duration(...rule.every).humanize()}</div>
|
||||||
|
{#await percentages[i]}
|
||||||
|
loading
|
||||||
|
{:then percentage}
|
||||||
|
<div class="bar bar-sm mb-2">
|
||||||
|
<div
|
||||||
|
class="bar-item"
|
||||||
|
role="progressbar"
|
||||||
|
style={`width:${percentage}%;`}
|
||||||
|
aria-valuenow={percentage}
|
||||||
|
aria-valuemin="0"
|
||||||
|
aria-valuemax="100" />
|
||||||
|
</div>
|
||||||
|
{/await}
|
||||||
{/each}
|
{/each}
|
||||||
|
@ -46,15 +46,15 @@
|
|||||||
{#if Array.isArray(limits)}
|
{#if Array.isArray(limits)}
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Host</th>
|
<th class="w-32">Host</th>
|
||||||
<th>Rules</th>
|
<th>Rules</th>
|
||||||
<th class="text-right">Actions</th>
|
<th class="text-right w-32">Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
{#each limits as { host, rules, _id }}
|
{#each limits as { host, rules, _id }}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{host}</td>
|
<td>{host}</td>
|
||||||
<td>
|
<td>
|
||||||
<Rules {rules} />
|
<Rules {rules} {host} />
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
|
Loading…
Reference in New Issue
Block a user