簡體   English   中英

Powershell 連續日期摘要

[英]Powershell Contiguous Date summary

從這個 object (和其他類似的):

    $Times = @(
    "12:00 AM",
    "1:00 AM",
    "2:00 AM",
    "3:00 AM",
    "4:00 AM",
    "5:00 AM",
    "6:00 AM",
    "7:00 AM",
    "8:00 AM",
    "9:00 AM",
    "10:00 AM",
    "11:00 AM",
    "12:00 PM",
    "1:00 PM",
    "2:00 PM",
    "3:00 PM",
    "4:00 PM",
    "5:00 PM",
    "6:00 PM",
    "7:00 PM",
    "8:00 PM",
    "9:00 PM",
    "10:00 PM",
    "11:00 PM"
)

$Example = @()
$times | % {$time = $_; $Example += [pscustomobject]@{Day = 'Sunday'; Time = $time;RatelimitingSchedule = '100'}}

$Example[5].RatelimitingSchedule = '50'
6..20 | % {$Example[$_].RatelimitingSchedule = '10'}
$Example[21].RatelimitingSchedule = '50'

$Example

這會產生 output 像這樣:在此處輸入圖像描述

我的問題是,我怎樣才能將它按摩成這個匯總表格(按所示順序):

  • 早上 5 點到 6 點之間,50% 速率限制
  • 早上 6 點到晚上 9 點之間,10% 速率限制
  • 晚上 9 點到 10 點之間,50% 速率限制
  • 晚上 10 點到凌晨 5 點之間,100% 速率限制

歡迎任何幫助!

對於任何在未來尋找這個答案的人...... https://www.reddit.com/user/bis/請為我創建這個:

 &{ $Example; 0 } | # append a dummy to the end of the data, so the last record gets processed
  ForEach-Object -Begin {
    $StartTime = $EndTime = $null
    $CurrentRate = -1
  } -Process {
    if($_.RateLimitingSchedule -eq $CurrentRate) {
      $EndTime = $_.Time
    } else {
      if($null -ne $StartTime) {
        [pscustomobject]@{Start = $StartTime; End = $EnDTime; Rate = 
    $CurrentRate}
      }
      $StartTime = $EndTime = $_.Time
      $CurrentRate = $_.RateLimitingSchedule
    }
  } |
  ForEach-Object {
    "between $($_.Start) and $($_.End), $($_.Rate)% Rate limiting"
  }

作為這篇文章的一部分: https://www.reddit.com/r/PowerShell/comments/wpuxm2/24hour_contiguous_schedule_summary/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM