首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >根据PowerShell中Invoke-RestMethod的结果计算值

根据PowerShell中Invoke-RestMethod的结果计算值
EN

Stack Overflow用户
提问于 2021-05-21 17:47:31
回答 1查看 42关注 0票数 1

我可以通过Invoke-RestMethod从提供以下格式的API中获取数据:

代码语言:javascript
复制
    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格式是:

代码语言:javascript
复制
{
  "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-performancecurrent_utilization值的平均值,但我不知道如何做到这一点。有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-21 19:00:23

有很多解决方案:

代码语言:javascript
复制
$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
}

结果:

代码语言:javascript
复制
current_utilization  =  19.3466666666667
peak_performance  =  29.1
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67634513

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档