是否可以在 Iron python 中使用字符串对动态数组进行排序
本文关键字:动态 字符串 数组 排序 Iron python 是否 | 更新日期: 2023-09-27 18:35:40
我正在 spotfire 中编写一个铁 python 代码,通过传递现有的数据表过滤器,根据需要从数据表中提取数据。问题是用户希望按照他们指定的特定排序顺序对值进行排序。问题是:如果我们有整个数据表,我们可以通过浏览列属性 ->排序顺序 ->自定义排序顺序并排列它们来对行中的值进行排序。但是现在我们没有完整的值,所以我们如何在铁蟒脚本或 spotfire 中处理它。
提前致谢
我做了类似的工作,将数字值排序为字符串。
我的建议是创建一个计算列,根据您希望的排序方式在实际字符串之前添加空格。 在 Spotfire 可视化中,它会修剪字符串,以便用户不会看到它未对齐,并且所有内容都相应地排序。
如果这是一项简单的任务,则可以直接在计算列的表达式中完成。
我的例子:
If([AR Days]<>"(PA)",
If(Integer([AR Days])>360,">360",
If(Integer([AR Days])>359," " & [AR Days],
If(Integer([AR Days])>349," " & [AR Days],
If(Integer([AR Days])>339," " & [AR Days],
If(Integer([AR Days])>329," " & [AR Days],
If(Integer([AR Days])>319," " & [AR Days],
If(Integer([AR Days])>309," " & [AR Days],
If(Integer([AR Days])>299," " & [AR Days],
If(Integer([AR Days])>289," " & [AR Days],
If(Integer([AR Days])>279," " & [AR Days],
If(Integer([AR Days])>269," " & [AR Days],
If(Integer([AR Days])>259," " & [AR Days],
If(Integer([AR Days])>249," " & [AR Days],
If(Integer([AR Days])>239," " & [AR Days],
If(Integer([AR Days])>229," " & [AR Days],
If(Integer([AR Days])>219," " & [AR Days],
If(Integer([AR Days])>209," " & [AR Days],
If(Integer([AR Days])>199," " & [AR Days],
If(Integer([AR Days])>189," " & [AR Days],
If(Integer([AR Days])>179," " & [AR Days],
If(Integer([AR Days])>169," " & [AR Days],
If(Integer([AR Days])>159," " & [AR Days],
If(Integer([AR Days])>149," " & [AR Days],
If(Integer([AR Days])>139," " & [AR Days],
If(Integer([AR Days])>129," " & [AR Days],
If(Integer([AR Days])>119," " & [AR Days],
If(Integer([AR Days])>109," " & [AR Days],
If(Integer([AR Days])>99," " & [AR Days],
If(Integer([AR Days])>89," " & [AR Days],
If(Integer([AR Days])>79," " & [AR Days],
If(Integer([AR Days])>69," " & [AR Days],
If(Integer([AR Days])>59," " & [AR Days],
If(Integer([AR Days])>49," " & [AR Days],
If(Integer([AR Days])>39," " & [AR Days],
If(Integer([AR Days])>29," " & [AR Days],
If(Integer([AR Days])>19," " & [AR Days],
If(Integer([AR Days])>9," " & [AR Days],
" " & [AR Days]))))))))))))))))))))))))))))))))))))),
" (PA)")
对于更复杂的示例,我允许用户为类似的存储桶选择自定义大小分组,最终存储桶的硬上限为 360+。 此值是文本输入框中的整数(名为 udBucketSize 的属性),更改时的脚本如下所示:
bck = Document.Properties["udBucketSize"]
if bck < 10:
x = 'If([ACCOUNT LOCATION (2)]="1"," (PA)",'
else:
x = 'If([ACCOUNT LOCATION (2)]="1"," (PA)",'
y = ')'
oldbck = 0
if bck == 1:
x = "[AR Days Workaround]"
else:
while oldbck + bck < 360 and bck > 0:
if oldbck == 0:
x += 'If(DateDiff("day",[FINAL BILL DATE],[SNAPSHOTDATE])<=' + str(oldbck + bck) + ',"'
else:
x += 'If(DateDiff("day",[FINAL BILL DATE],[SNAPSHOTDATE])<=' + str(oldbck + bck - 1) + ',"'
if bck < 10:
z = (360 - oldbck)/10 + 1
n = 1
while n <= z:
x += ' '
n += 1
else:
if oldbck < 100:
x+= ' '
elif oldbck < 200:
x+= ' '
elif oldbck < 300:
x+= ' '
else:
x+= ' '
if oldbck == 0:
x+= str(oldbck) + '-' + str(oldbck+bck) +'",'
oldbck += 1
else:
x+= str(oldbck) + '-' + str(oldbck+bck - 1) +'",'
y+= ')'
oldbck += bck
x += 'If(DateDiff("day",[FINAL BILL DATE],[SNAPSHOTDATE])<=360," ' + str(oldbck) + '-360", ">360")' + y
print x
Document.Properties["udBucketString"] = x
属性 udBucketString 当时是我的计算列的表达式,现在按我想要的方式排序。
类似的方法可用于对字母或特殊字符进行排序。