嗨 - 我正在尝试编写一个遵循此工作流程的脚本:
1 - 在某个起始日期时间(例如 2021 年 10 月 1 日上午 11:00)开始循环。我将其称为第 n 行。从 col1[row n] 获取值。
2 - 转到下一行,n+1。设置 col2 = col1 [n+1] - col1[n]。
3 - 转到下一行,n+2,设置 col2 = col1 [n+2] - col1[n]
4 - 转到下一行,n+3,设置 col2 = col1[ n+3] - col1[n]。继续循环遍历每个后续行,直到 datetime[n+k] = datetime[n] + 7 天。(请注意,随着循环的进行,k 将根据行之间的时间增量而变化;例如,时间从一行到下一行增加 5 分钟、15 分钟、1 小时等,具体取决于所讨论的行。)
5 - 使用在步骤 4 中获得的新“开始日期”对每个新的一周数据重复步骤 1 到 4。继续循环遍历另外 7 天的数据。
6 - 重复步骤 5,直到数据表用完行。
目标是对 col1 数据进行计算,将一周的行与该周的第一行进行比较,然后在随后的每个周(第 2 周、第 3 周、第 4 周等)一遍又一遍地重复此操作,直到所有行已处理。:)
你能给出一个包含你期望数据的小数据表吗?或者至少您使用的数据表是什么样的? 听起来像列公式将是一个更简单的解决方案。
我想你可能会说这样的话?
Names default to here(1);
dt = New Table( "Untitled 1133",
Add Rows( 5 ),
New Column( "Week1",
Numeric,
"Continuous",
Format( "d/m/y h:m:s", 22, 0 ),
Input Format( "d/m/y h:m:s", 0 ),
Set Values( [3716957885, 3716957886, 3716957887, 3716957888, 3716957889] )
),
New Column( "Week2",
Numeric,
"Continuous",
Format( "d/m/y h:m:s", 22, 0 ),
Input Format( "d/m/y h:m:s", 0 ),
Set Values( [3716957885, 3716957886, 3716957887, 3716957888, 3716957889] )
),
New Column( "Week3",
Numeric,
"Continuous",
Format( "d/m/y h:m:s", 22, 0 ),
Input Format( "d/m/y h:m:s", 0 ),
Set Values( [3716957885, 3716957886, 3716957887, 3716957888, 3716957889] )
)
);
nc = ncols(dt);
for(i=1, i<=nc, i++,
col_name = column(i) << Get Name(); // get the original column name
Eval(EvalExpr( // you have to do this so you can substitute in the actual col_name instead of a variable
dt << New Column(col_name || " comparison",
// just take current row minus first row
formula(Expr(column(dt, col_name))[row()]-Expr(column(dt, col_name))[1])
)
));
);
当然。谢谢你。附件是我在excel中创建的数据集片段作为示例。
谢谢文斯。我现在正在经历这个......作为一个 JSL 新手(!),我有几个问题可以帮助我遵循你的方法。为什么要向新数据表添加 5 行?为什么你需要“设定值”,为什么选择这五个数字?你的脚本是 3 周,但我的实际数据集大约有 120 周。
最后,脚本如何知道哪一列是要计算的值(即我的示例中的“流”)?(我的数据表的列比示例中显示的三列多。)分配列名而不是切换列不是更容易吗?我可能在这里遗漏了一些东西。