1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-25 17:18:05 +08:00

add stats

This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-11-16 13:11:03 +08:00
parent 96553ee70c
commit 15066a6706
7 changed files with 108 additions and 5 deletions

View File

@ -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
}

57
base/web/stats.go Normal file
View File

@ -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))
}

View File

@ -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")

View File

@ -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 {

View File

@ -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])) })

View File

@ -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 {

View File

@ -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 {