以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]代码简化后运行时间太长? (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=160844) |
||||
-- 作者:cqlpjks -- 发布时间:2021/2/23 20:38:00 -- [求助]代码简化后运行时间太长?
代码简化后运行时间太长,要98秒,简化前只需7秒,但运算结果一样。不知代码是否存在问题?请指教,谢谢! [此贴子已经被作者于2021/2/23 21:48:43编辑过]
|
||||
-- 作者:有点蓝 -- 发布时间:2021/2/23 20:42:00 -- 肯定有问题 |
||||
-- 作者:cqlpjks -- 发布时间:2021/2/23 21:51:00 -- 但不知如何修改代码,请指教。谢谢! |
||||
-- 作者:有点蓝 -- 发布时间:2021/2/23 22:42:00 -- 1、标准差的计算建议网上搜索算法自己写一个函数处理,不要在循环里使用Tables("成绩库").Aggregate、Tables("总分"& tjnj &"级有效分").Aggregate这种方式 2、这种代码和循环没有任何关系,没有必要放到循环里 3、循环里的处理和其它表有什么关系,为什么要遍历所有表 7、如果只是简单的红色加粗,建议到全局表事件drawcell处理
[此贴子已经被作者于2021/2/23 22:42:18编辑过]
|
||||
-- 作者:cqlpjks -- 发布时间:2021/2/23 22:59:00 -- 问题确实多,待我慢慢解决,如遇困难再请教。谢谢! |
||||
-- 作者:cqlpjks -- 发布时间:2021/2/24 21:02:00 -- 只是建表和平均分、标准差的计算就耗时160多秒时间,估计是这个代码存在问题,我实在找不到原因,请指教。谢谢! Dim Values() As String = {"总分"} Dim s1() As String = New String() {"总分"} Dim tjnj As String = 2018 Dim lm1s() As String = {"序号","部别","年级","科目"} Dim lm2s() As String = {"参考人数","平均分","标准差"} Dim dhs() As String = {"重点A","本科A","专科A"} Dim lm3s() As String = {"平均分","标准差","平均分之和","标准差之和","目标","分数线","有效分"} For Each Value As String In Values \'建表 Dim dtb As New DataTableBuilder( value & tjnj & "级有效分") For Each lm1 As String In lm1s dtb.AddDef( lm1 ,Gettype(String),8) Next For Each lm2 As String In lm2s dtb.AddDef( lm2 ,Gettype(Double)) Next For Each dh As String In dhs For Each lm3 As String In lm3s dtb.AddDef( dh & lm3 ,Gettype(Double),"", dh & "及以上_ "& lm3 &"") Next Next dtb.Build() For Each bm As DataTable In DataTables If bm.name <> "成绩库" AndAlso bm.Name <> "校名设置" AndAlso bm.Name <> "目标设置" AndAlso bm.Name <> "名册" AndAlso bm.Name <> "信息表" AndAlso bm.Name <> "原始名册"AndAlso bm.Name <> "基数" AndAlso bm.Name <> "调用人数" AndAlso bm.Name <> "赋分" Dim kemu_list() As String = {"语文","数学","英语","物理","历史","选科"} For Each kemu As String In kemu_list For Each bubie As String In DataTables("成绩库").GetValues("部别","年级 = \'" & tjnj & "\'") Dim dr As DataRow dr = DataTables(bm.name).addnew() dr("科目") = kemu dr("年级") = tjnj dr("部别") = bubie dr("参考人数") = DataTables("成绩库").Compute("count(" & dr("科目") & ")", "[部别] = \'" & dr("部别") & "\' And [年级] = \'" & dr("年级") & "\'") \'平均分\\标准差 dr("平均分") = Format(DataTables("成绩库").Compute("Avg(" & dr("科目") & ")", "[部别] = \'" & dr("部别") & "\' And [年级] = \'" & dr("年级") & "\'"),"0.00") Dim jdr As DataRow = DataTables("目标设置").Find("部别 = \'" & dr("部别") & "\' And 年级 = \'" & dr("年级") & "\'And 类别 = \'区合计\'") For Each dh As String In dhs For Each lm3 As String In lm3s For j As Integer = 0 To dhs.length - 1 dr(dhs(j) & "目标") = jdr(dhs(j)) \'目标取值填充 Dim tj As String = Left(bm.name,2) & "排名" Dim tj1 As String = Left(bm.name,2) tj1 = Left(bm.name,2) Dim pm As Double = DataTables("成绩库").Find(" " & tj & " = \'" & jdr(dhs(j)) & "\' And [部别] = \'" & dr("部别") & "\' And [年级] = \'" & dr("年级") & "\'")(tj1) \'排名 dr(dhs(j) & "分数线") = DataTables("成绩库").Compute("Max(" & tj1 & ") ", " " & tj1 & " = \'" & pm & "\'And [部别] = \'" & dr("部别") & "\' And [年级] = \'" & dr("年级") & "\'") dr(dhs(j) & "平均分") = Format(DataTables("成绩库").Compute("Avg(" & dr("科目") & ")", "[部别] = \'" & dr("部别") & "\' And [年级] = \'" & dr("年级") & "\'And [总分] >= \'" & pm & "\' "),"0.00") Tables("成绩库").Filter = " 部别 = \'" & dr("部别") & "\' And 年级 = \'" & dr("年级") & "\'" Dim p As Integer = Tables("成绩库").Cols("" & dr("科目") & "").Index \'指定位置的列 Dim rs As Integer = Tables("成绩库").Rows.Count -1 \'指定位置的行 dr("标准差") = Tables("成绩库").Aggregate(AggregateEnum.Std, 0, p, rs, p) dr(dhs(j) & "标准差") = Format(Tables("成绩库").Compute("StDev(" & dr("科目") & ")", "[部别] = \'" & dr("部别") & "\' And [年级] = \'" & dr("年级") & "\'And [总分] >= \'" & pm & "\'"),"0.00") Tables("成绩库").Filter = "" Tables("总分"& tjnj &"级有效分").Sort = "部别" Next Next Next DataTables("总分"& tjnj &"级有效分").DeleteFor("[参考人数] <= 0 ") \'序号填充 Dim tj2 As String = "序号" Dim drs As List(Of DataRow) = DataTables("总分"& tjnj &"级有效分").Select("[年级] = \'" & tjnj & "\'", "部别") For n As Integer = 0 To drs.Count - 1 \'遍历所有行 drs(n)(tj2) = n \'设置排序 Next Next Next End If Next Next DataTables("成绩库").ResumeRedraw
|
||||
-- 作者:有点蓝 -- 发布时间:2021/2/25 8:31:00 -- 看4楼1、2、5. 另外为什么dhs要遍历2次 For Each dh As String In dhs For Each lm3 As String In lm3s For j As Integer = 0 To dhs.length - 1 |
||||
-- 作者:cqlpjks -- 发布时间:2021/2/25 10:54:00 -- 在执行过程中执行表呈白板,好像死机了似的,运行结束后才显示。不知是哪句代码造成的?请指教。谢谢! [此贴子已经被作者于2021/2/25 10:55:00编辑过]
|
||||
-- 作者:有点蓝 -- 发布时间:2021/2/25 10:59:00 --
|
||||
-- 作者:cqlpjks -- 发布时间:2021/2/25 11:29:00 -- 代码执行前加:DataTables("成绩库").StopRedraw 代码执行后加:DataTables("成绩库").ResumeRedraw 还是不得行。
|