我在spotfire中编写了一个铁python代码,通过传递现有的数据表过滤器,根据需求从数据表中提取数据。事情是用户想要按照它们指定的特定排序顺序对值进行排序。 问题在于:如果我们有完整的数据表,我们可以通过遍历列属性对行中的值进行排序 - >排序顺序 - >自定义排序顺序并安排它们。但是现在我们没有完整的价值,所以我们怎么能用铁蟒蛇脚本或点火来处理它。
先谢谢
答案 0 :(得分:1)
我做了类似的工作,将数字值排序为字符串。
我的建议是根据您的订购方式制作一个计算列,在实际字符串之前添加空格。在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然后是我计算列的表达式,现在按照我希望的方式对其进行排序。
类似的方法可用于对字母或特殊字符进行排序。