From 15066a67066f1b9ab9be80ef118a865211fa722e Mon Sep 17 00:00:00 2001 From: shy Date: Thu, 16 Nov 2023 13:11:03 +0800 Subject: [PATCH] add stats --- base/web/dream.go | 17 +++++++++++++- base/web/stats.go | 57 ++++++++++++++++++++++++++++++++++++++++++++++ core/mall/goods.go | 11 ++++++++- core/team/asset.go | 11 ++++++++- core/team/task.go | 10 +++++++- meta.go | 5 ++++ misc/git/repos.go | 2 +- 7 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 base/web/stats.go diff --git a/base/web/dream.go b/base/web/dream.go index 397fce1a..e136f277 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -251,7 +251,22 @@ func init() { DREAM_TABLES: {Hand: func(m *ice.Message, arg ...string) { kit.Switch(m.Option(mdb.TYPE), []string{WORKER, SERVER}, func() { m.PushButton(OPEN, ice.MAIN) }) }}, - }, aaa.RoleAction(), DreamAction(), mdb.ImportantHashAction(ctx.TOOLS, "web.space,web.route,web.code.git.search", mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,icon,repos,binary,template")), Hand: func(m *ice.Message, arg ...string) { + STATS_TABLES: {Hand: func(m *ice.Message, arg ...string) { + if msg := mdb.HashSelects(m.Spawn()); msg.Length() > 0 { + stats := map[string]int{} + list := m.CmdMap(SPACE, mdb.NAME) + msg.Table(func(value ice.Maps) { + if _, ok := list[value[mdb.NAME]]; ok { + stats[cli.START]++ + } + }) + m.Push(mdb.NAME, kit.Keys(m.CommandKey(), cli.START)).Push(mdb.VALUE, stats[cli.START]) + m.Push(mdb.NAME, kit.Keys(m.CommandKey(), mdb.TOTAL)).Push(mdb.VALUE, msg.Length()) + m.Push("units", "") + m.Push("units", "") + } + }}, + }, aaa.RoleAction(), StatsAction(), DreamAction(), mdb.ImportantHashAction(ctx.TOOLS, "web.space,web.route,web.code.git.search", mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,icon,repos,binary,template")), Hand: func(m *ice.Message, arg ...string) { if ice.Info.NodeType == WORKER { return } diff --git a/base/web/stats.go b/base/web/stats.go new file mode 100644 index 00000000..2ff6a909 --- /dev/null +++ b/base/web/stats.go @@ -0,0 +1,57 @@ +package web + +import ( + ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/aaa" + "shylinux.com/x/icebergs/base/ctx" + "shylinux.com/x/icebergs/base/gdb" + "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/web/html" + kit "shylinux.com/x/toolkits" +) + +const ( + STATS_TABLES = "stats.tables" +) +const STATS = "stats" + +func init() { + Index.MergeCommands(ice.Commands{ + STATS: {Name: "stats name auto", Help: "汇总量", Meta: kit.Dict( + ice.CTX_TRANS, kit.Dict(html.INPUT, kit.Dict( + "repos.total", "代码库总数", + "dream.total", "空间总数", + "dream.start", "已启动空间", + "asset.amount", "资产总额", + "asset.count", "资产数量", + "goods.amount", "商品总额", + "goods.count", "商品数量", + "user.total", "用户总数", + "sess.total", "会话总数", + "task.total", "任务总数", + "disk.total", "磁盘总量", + "disk.used", "磁盘用量", + "mem.total", "内存总量", + "mem.used", "内存用量", + )), + ), Hand: func(m *ice.Message, arg ...string) { + m.Push(mdb.NAME, kit.Keys(aaa.SESS, mdb.TOTAL)).Push(mdb.VALUE, m.Cmd(aaa.SESS).Length()) + m.Push(mdb.NAME, kit.Keys(aaa.USER, mdb.TOTAL)).Push(mdb.VALUE, m.Cmd(aaa.USER).Length()) + m.Push("units", "") + m.Push("units", "") + ctx.DisplayStory(m, "stats.js") + gdb.Event(m, STATS_TABLES) + PushPodCmd(m, "", arg...) + }}, + }) +} +func StatsAction() ice.Actions { + return ice.MergeActions(ice.Actions{ + STATS_TABLES: {Hand: func(m *ice.Message, arg ...string) { + if msg := mdb.HashSelects(m.Spawn()); msg.Length() > 0 { + m.Push(mdb.NAME, kit.Keys(m.CommandKey(), mdb.TOTAL)).Push(mdb.VALUE, msg.Length()) + m.Push("units", "") + } + }}, + }, gdb.EventsAction(STATS_TABLES)) +} diff --git a/core/mall/goods.go b/core/mall/goods.go index 08f8a776..c613c324 100644 --- a/core/mall/goods.go +++ b/core/mall/goods.go @@ -30,7 +30,16 @@ func init() { m.Push(arg[0], kit.Split(nfs.TemplateText(m, arg[0]))) } }}, - }, aaa.RoleAction(), web.ExportCacheAction(nfs.IMAGE), mdb.ExportHashAction(ctx.TOOLS, kit.Fields(Prefix(CART), Prefix(ORDER)), mdb.FIELD, "time,hash,zone,name,text,price,count,units,image")), Hand: func(m *ice.Message, arg ...string) { + web.STATS_TABLES: {Hand: func(m *ice.Message, arg ...string) { + if msg := mdb.HashSelects(m.Spawn()); msg.Length() > 0 { + amount := msg.TableAmount(func(value ice.Maps) float64 { return kit.Float(value[mdb.COUNT]) * kit.Float(value[PRICE]) }) + m.Push(mdb.NAME, kit.Keys(m.CommandKey(), AMOUNT)).Push(mdb.VALUE, amount) + m.Push("units", "元") + m.Push(mdb.NAME, kit.Keys(m.CommandKey(), mdb.COUNT)).Push(mdb.VALUE, msg.Length()) + m.Push("units", "") + } + }}, + }, aaa.RoleAction(), web.StatsAction(), web.ExportCacheAction(nfs.IMAGE), mdb.ExportHashAction(ctx.TOOLS, kit.Fields(Prefix(CART), Prefix(ORDER)), mdb.FIELD, "time,hash,zone,name,text,price,count,units,image")), Hand: func(m *ice.Message, arg ...string) { kit.If(len(arg) == 0 && m.IsMobileUA(), func() { m.OptionDefault(ice.MSG_FIELDS, "zone,name,price,count,units,text,hash,time,image") }) mdb.HashSelect(m, arg...).PushAction(ORDER).Action("filter:text") web.PushPodCmd(m, "", arg...).Sort("zone,name") diff --git a/core/team/asset.go b/core/team/asset.go index 47b4db14..e3058e73 100644 --- a/core/team/asset.go +++ b/core/team/asset.go @@ -98,7 +98,16 @@ func init() { _asset_check(m, m.Option(ACCOUNT)) } }}, - }, mdb.ExportZoneAction(mdb.SHORT, ACCOUNT, mdb.FIELD, "time,account,type,amount,count", mdb.FIELDS, "time,id,type,amount,name,text")), Hand: func(m *ice.Message, arg ...string) { + web.STATS_TABLES: {Hand: func(m *ice.Message, arg ...string) { + if msg := mdb.HashSelects(m.Spawn()); msg.Length() > 0 { + amount := msg.TableAmount(func(value ice.Maps) float64 { return kit.Float(value[AMOUNT]) }) + m.Push(mdb.NAME, kit.Keys(m.CommandKey(), AMOUNT)).Push(mdb.VALUE, amount) + m.Push("units", "元") + m.Push(mdb.NAME, kit.Keys(m.CommandKey(), mdb.COUNT)).Push(mdb.VALUE, msg.Length()) + m.Push("units", "") + } + }}, + }, web.StatsAction(), mdb.ExportZoneAction(mdb.SHORT, ACCOUNT, mdb.FIELD, "time,account,type,amount,count", mdb.FIELDS, "time,id,type,amount,name,text")), Hand: func(m *ice.Message, arg ...string) { mdb.ZoneSelect(m, arg...) web.PushPodCmd(m, "", arg...) if m.SortIntR(AMOUNT); len(arg) == 0 { diff --git a/core/team/task.go b/core/team/task.go index 61e022d5..ceaaa280 100644 --- a/core/team/task.go +++ b/core/team/task.go @@ -97,7 +97,15 @@ func init() { CANCEL: {Hand: func(m *ice.Message, arg ...string) { _task_modify(m, STATUS, CANCEL) }}, BEGIN: {Hand: func(m *ice.Message, arg ...string) { _task_modify(m, STATUS, PROCESS) }}, END: {Hand: func(m *ice.Message, arg ...string) { _task_modify(m, STATUS, FINISH) }}, - }, mdb.ExportZoneAction(mdb.FIELDS, "begin_time,end_time,id,status,level,score,type,name,text")), Hand: func(m *ice.Message, arg ...string) { + web.STATS_TABLES: {Hand: func(m *ice.Message, arg ...string) { + if msg := mdb.HashSelects(m.Spawn()); msg.Length() > 0 { + count := 0 + msg.Table(func(value ice.Maps) { count += kit.Int(value[mdb.COUNT]) }) + m.Push(mdb.NAME, kit.Keys(m.CommandKey(), mdb.TOTAL)).Push(mdb.VALUE, count) + m.Push("units", "") + } + }}, + }, web.StatsAction(), mdb.ExportZoneAction(mdb.FIELD, "time,zone,count", mdb.FIELDS, "begin_time,end_time,id,status,level,score,type,name,text")), Hand: func(m *ice.Message, arg ...string) { if mdb.ZoneSelect(m, arg...); len(arg) > 0 && arg[0] != "" { status := map[string]int{} m.Table(func(value ice.Maps) { m.PushButton(_task_action(m, value[STATUS])) }) diff --git a/meta.go b/meta.go index 5a953eff..5f704c70 100644 --- a/meta.go +++ b/meta.go @@ -164,6 +164,11 @@ func (m *Message) Stats(arg ...string) (res []string) { kit.For(arg, func(k string) { res = append(res, k, kit.Format("%0.2f", stats[k])) }) return } +func (m *Message) TableAmount(cb func(Maps) float64) float64 { + var amount float64 + m.Table(func(value Maps) { amount += cb(value) }) + return amount +} func (m *Message) Table(cb Any) *Message { n := m.Length() if n == 0 { diff --git a/misc/git/repos.go b/misc/git/repos.go index ea061276..be1135d9 100644 --- a/misc/git/repos.go +++ b/misc/git/repos.go @@ -595,7 +595,7 @@ func init() { web.DREAM_TRASH: {Hand: func(m *ice.Message, arg ...string) { m.Cmd("", mdb.REMOVE, kit.Dict(REPOS, m.Option(mdb.NAME))) }}, - }, aaa.RoleAction(REMOTE), web.DreamAction(), mdb.HashAction(mdb.SHORT, REPOS, mdb.FIELD, "time,repos,branch,version,message,origin"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) { + }, aaa.RoleAction(REMOTE), web.StatsAction(), web.DreamAction(), mdb.HashAction(mdb.SHORT, REPOS, mdb.FIELD, "time,repos,branch,version,message,origin"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 { mdb.HashSelect(m, arg...).Sort(REPOS).PushAction(STATUS, mdb.REMOVE).Action(STATUS, PULL, PUSH, CLONE) } else if len(arg) == 1 {