Skip to content

Commit

Permalink
fix(status): guild chart always empty
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 11, 2022
1 parent 1f53441 commit 76bee6f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/orm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ export namespace Eval {
}

export interface BooleanExpr<T = any, A = never> extends UniveralExpr<T, boolean> {
$eq?: [Number<T, A>, Number<T, A>]
$ne?: [Number<T, A>, Number<T, A>]
$eq?: [Number<T, A>, Number<T, A>] | [String<T, A>, String<T, A>] | [Boolean<T, A>, Boolean<T, A>]
$ne?: [Number<T, A>, Number<T, A>] | [String<T, A>, String<T, A>] | [Boolean<T, A>, Boolean<T, A>]
$gt?: [Number<T, A>, Number<T, A>]
$gte?: [Number<T, A>, Number<T, A>]
$lt?: [Number<T, A>, Number<T, A>]
Expand Down
4 changes: 3 additions & 1 deletion plugins/frontend/status/client/charts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export function createChart({ title, fields, options }: ChartOptions) {
return Card.create(() => {
const option = options(store)
if (!option) return
return h(resolveComponent('k-card'), { class: 'frameless', title }, h(VChart, { option, autoresize: true }))
return h(resolveComponent('k-card'), { class: 'frameless', title }, () => {
return h(VChart, { option, autoresize: true })
})
}, fields)
}

Expand Down
15 changes: 10 additions & 5 deletions plugins/frontend/status/src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ class StatisticsProvider extends DataService<StatisticsProvider.Payload> {
private extendGuilds: StatisticsProvider.Extension = async (payload, data) => {
const groupSet = new Set<string>()
payload.guilds = []
const groupMap = Object.fromEntries(data.guilds.map(g => [g.id, g]))
const groupMap = Object.fromEntries(data.guilds.map(g => [`${g.platform}:${g.id}`, g]))
const messageMap = average(data.daily.map(data => data.group))
const updateList: Pick<Channel, 'id' | 'platform' | 'name'>[] = []

async function getGroupInfo(bot: Bot) {
async function getGuildInfo(bot: Bot) {
const { platform } = bot
const guilds = await bot.getGuildList()
for (const { guildId, guildName: name } of guilds) {
Expand All @@ -261,7 +261,10 @@ class StatisticsProvider extends DataService<StatisticsProvider.Payload> {
}
}

await Promise.all(this.ctx.bots.map(bot => getGroupInfo(bot).catch(noop)))
await Promise.all(this.ctx.bots.map(async (bot) => {
if (bot.status !== 'online') return
await getGuildInfo(bot).catch(logger.warn)
}))

for (const key in messageMap) {
if (!groupSet.has(key) && groupMap[key]) {
Expand All @@ -286,7 +289,9 @@ class StatisticsProvider extends DataService<StatisticsProvider.Payload> {
this.ctx.database.get('stats_daily', { time }, { sort, limit: RECENT_LENGTH }),
this.ctx.database.get('stats_hourly', { time }, { sort, limit: 24 * RECENT_LENGTH }),
this.ctx.database.get('stats_longterm', { time }, { sort }),
this.ctx.database.get('channel', {}, ['platform', 'id', 'name', 'assignee']),
this.ctx.database.get('channel', {
$expr: { $eq: [{ $: 'id' }, { $: 'guildId' }] },
}, ['platform', 'id', 'name', 'assignee']),
])
const data = { daily, hourly, longterm, guilds }
const payload = {} as StatisticsProvider.Payload
Expand Down Expand Up @@ -323,7 +328,7 @@ namespace StatisticsProvider {

export interface Data {
extension?: StatisticsProvider.Payload
guilds: Pick<Channel, 'id' | 'name' | 'assignee'>[]
guilds: Pick<Channel, 'id' | 'platform' | 'name' | 'assignee'>[]
daily: Record<DailyField, Dict<number>>[]
hourly: ({ time: Date } & Record<HourlyField, number>)[]
longterm: ({ time: Date } & Record<LongtermField, number>)[]
Expand Down

0 comments on commit 76bee6f

Please sign in to comment.