我可以通过Invoke-RestMethod从提供以下格式的API中获取数据:
1612142668000000000 : @{peak_performance=29.18; current_utilization=19.15}
1612146268000000000 : @{peak_performance=29.05; current_utilization=20.03}
1612149868000000000 : @{peak_performance=29.07; current_utilization=18.86}如果有帮助,上面的JSON格式是:
{
"1612142668000000000": {
"peak_performance": 29.18,
"current_utilization": 19.15
},
"1612146268000000000": {
"peak_performance": 29.05,
"current_utilization": 20.03
},
"1612149868000000000": {
"peak_performance": 29.07,
"current_utilization": 18.86
}
}我希望能够计算和显示所有可用的peak-performance和current_utilization值的平均值,但我不知道如何做到这一点。有什么想法吗?
发布于 2021-05-21 19:00:23
有很多解决方案:
$json = @"
{
"1612142668000000000": {
"peak_performance": 29.18,
"current_utilization": 19.15
},
"1612146268000000000": {
"peak_performance": 29.05,
"current_utilization": 20.03
},
"1612149868000000000": {
"peak_performance": 29.07,
"current_utilization": 18.86
}
}
"@
$jout = $json | ConvertFrom-Json
$result = $jout.PSObject.Properties.Value | Measure-Object -Property current_utilization,peak_performance -Average
foreach($v in $result){
Write-Host $v.Property " = " $v.Average
}结果:
current_utilization = 19.3466666666667
peak_performance = 29.1https://stackoverflow.com/questions/67634513
复制相似问题