数据库显示进度百分比、估算时间、勾选框数量

本贴最后更新于 363 天前,其中的信息可能已经天翻地覆

用数据库管理要看的书和课程时,发现要用到“模板”功能来实现“进度”、“耗时估算”的展现,而模板功能要通过代码实现,经过对论坛大佬教程和 GPT 的参考,有了点眉目,这里分享下本编程小白的实践过程,以及加减乘数运算模板代码。(按照评论区大佬的建议更新了下)

首先,在汇总页旁的“+”号新建“进行中”、“时间统计”,专门显示进度百分比和估算时间,右击列可以隐藏不想见到的列。

微信图片 20240224001200.png

显示进度百分比

进度百分比显示效果如下图,个人习惯按章节算数量,比如总数 26 就是 26 章:

微信截图 20240223230832.png

第一步:新建“已完成数”和“总数”两列(类型:数字),再新建“进度”列(类型:模板)

第二步:点击“进度”,选择“编辑”

微信截图 20240223234453.png

第三步:输入代码

统计百分比整数

.action{ if not (empty (index . "总数")) } .action{ $a := index . "已完成" } .action{ $b := index . "总数" } .action{ $c := div (mul $a 100) $b } .action{mulf (divf $a $b) 100 | int}% .action{end}

统计带小数后两位

.action{ if not (empty (index . "总数")) } .action{ $a := index . "已完成" } .action{ $b := index . "总数" } .action{ $c := divf (mulf $a 100) $b } .action{printf "%.2f%%" (mulf (divf $a $b) 100)} .action{end}

估算时间

估算时间效果如下图:

微信截图 20240224143923.png

第一步,新建“每部分耗时”(类型:数字),“已耗时”“总耗时”(类型:模板)

第二步,在“已耗时”编辑输入代码

.action{$a:= index . "每部分耗时" } .action{$b:= index . "已完成数" } .action{$total_minutes:= (mulf $a $b)} .action{$hours:= divf $total_minutes 60} .action{$remaining:= sub $total_minutes (mulf $hours 60)} .action{$hours}h .action{$remaining}m # 若要显示为分钟数,后4行换成这段代码:.action{$total_minutes}分钟

第三步,在“总耗时”编辑输入代码

.action{$a:= index . "每部分耗时" } .action{$b:= index . "总数" } .action{$total_minutes:= (mulf $a $b)} .action{$hours:= divf $total_minutes 60} .action{$remaining:= sub $total_minutes (mulf $hours 60)} .action{$hours}h .action{$remaining}m # 若要显示为分钟数,后4行换成这段代码:.action{$total_minutes}分钟

数据库计算用到的加减乘除模板

其实就是分别使用 add(加法)、减法(sub)、乘法(mul)、除法(div),"a"、"b"对应的是列名称,使用时只需要替换引号("a"、"b")里的内容

1.加法

.action{$a:= index . "a" } .action{$b:= index . "b" } .action{$result:= add $a $b} .action{$result}

2.减法

.action{$a:= index . "a" } .action{$b:= index . "b" } .action{$result:= sub $a $b} .action{$result}

3.乘法

.action{$a:= index . "a" } .action{$b:= index . "b" } .action{$result:= mulf $a $b} .action{$result}

4.除法

.action{$a:= index . "a" } .action{$b:= index . "b" } .action{$result:= divf $a $b} .action{$result}

统计勾选框数量

该例子统计一周打卡数量

.action{$count := 0} .action{$Z1:= index . "周一" } .action{$Z2:= index . "周二" } .action{$Z3:= index . "周三" } .action{$Z4:= index . "周四" } .action{$Z5:= index . "周五" } .action{$Z6:= index . "周六" } .action{$Z7:= index . "周日" } .action{if eq $Z1 "√"} .action{$count = add $count 1} .action{end} .action{if eq $Z2 "√"} .action{$count = add $count 1} .action{end} .action{if eq $Z3 "√"} .action{$count = add $count 1} .action{end} .action{if eq $Z4 "√"} .action{$count = add $count 1} .action{end} .action{if eq $Z5 "√"} .action{$count = add $count 1} .action{end} .action{if eq $Z6 "√"} .action{$count = add $count 1} .action{end} .action{if eq $Z7 "√"} .action{$count = add $count 1} .action{end} .action{$count}
  • 数据库

    据说 99% 的性能瓶颈都在数据库。

    345 引用 • 742 回帖
3 操作
Itherael 在 2024-04-25 23:35:22 更新了该帖
Itherael 在 2024-04-25 23:25:16 更新了该帖
Itherael 在 2024-02-24 14:42:11 更新了该帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...
请输入回帖内容 ...