PowerGridForecast 클래스

정의

디바이스가 연결된 전력망에 대한 정보를 포함합니다. 데이터는 워크로드가 발생하는 시간을 시간 이동하거나 강렬한 시간 동안 에너지 소비를 줄이기 위한 예측에 사용됩니다.

public ref class PowerGridForecast sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Devices.Power.PowerGridApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class PowerGridForecast final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Devices.Power.PowerGridApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class PowerGridForecast
Public NotInheritable Class PowerGridForecast
상속
Object Platform::Object IInspectable PowerGridForecast
특성

Windows 요구 사항

디바이스 패밀리
Windows Desktop Extension SDK (10.0.26100.0에서 도입되었습니다.)
API contract
Windows.Devices.Power.PowerGridApiContract (v1.0에서 도입되었습니다.)

예제

using Windows.Devices.Power;

void PrintBestTimes(PowerGridForecast forecast)
{
    double bestSeverity = double.MaxValue;
    double bestLowImpactSeverity = double.MaxValue;
    DateTime bestTime = DateTime.MaxValue;
    DateTime bestLowImpactTime = DateTime.MaxValue;
    TimeSpan blockDuration = forecast.BlockDuration;
    DateTime startTime = forecast.StartTime;
    IList<PowerGridData> forecastSignals = forecast.Forecast;

    if (forecastSignals.Count == 0)
    {
        Console.WriteLine("Error encountered with getting forecast; try again later.");
        return;
    }

    foreach (PowerGridData data in forecastSignals)
    {
        if (data.Severity < bestSeverity)
        {
            bestSeverity = data.Severity;
            bestTime = startTime;
        }

        if (data.IsLowUserExperienceImpact && data.Severity < bestLowImpactSeverity)
        {
            bestLowImpactSeverity = data.Severity;
            bestLowImpactTime = startTime;
        }

        startTime = startTime + blockDuration;
    }

    if (bestLowImpactTime != DateTime.MaxValue)
    {
        DateTime endBestLowImpactTime = bestLowImpactTime + blockDuration;
        Console.WriteLine($"Lowest severity during low impact is {bestLowImpactSeverity}, which starts at {bestLowImpactTime.ToString()}, and ends at {endBestLowImpactTime}.");
    }
    else
    {
        Console.WriteLine("There's no low-user-impact time in which to do work.");
    }

    if (bestTime != DateTime.MaxValue)
    {
        DateTime endBestSeverity = bestTime + blockDuration;
        Console.WriteLine($"Lowest severity is {bestSeverity}, which starts at {bestTime.ToString()}, and ends at {endBestSeverity.ToString()}.");
    }
}

PowerGridForecast forecast = PowerGridForecast.GetForecast();
PrintBestTimes(forecast);
#include "pch.h"
#include <iostream>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Devices.Power.h>

using namespace winrt::Windows::Devices::Power;
using namespace winrt::Windows::Foundation::Collections;
using namespace winrt::Windows::Foundation;

void PrintFullForecast(PowerGridForecast const& forecast)
{
    IVectorView<PowerGridData> forecastSignals = forecast.Forecast();
    DateTime forecastStartTime = forecast.StartTime();
    TimeSpan forecastBlockDuration = forecast.BlockDuration();
    DateTime blockStartTime = forecastStartTime;

    // On failure the forecast will be empty.
    if (forecastSignals.Size() == 0)
    {
        std::wcout << L"Error encountered while reading the forecast; try again later." << std::endl;
        return;
    }

    // Iterate through the forecast printing all the data.
    for (auto const& block : forecastSignals)
    {
        auto severity = block.Severity();
        auto isLowImpact = block.IsLowUserExperienceImpact();

        std::wcout << L"Start time - ";
        PrintDateTime(blockStartTime, true);
        std::wcout << L" | End time - ";
        PrintDateTime(blockStartTime + forecastBlockDuration, true);
        std::wcout << L" | Intensity - " << severity << L" | IsLowImpactTime - " << (isLowImpact ? L"TRUE" : L"FALSE") << std::endl;

        blockStartTime = blockStartTime + forecastBlockDuration;
    }
}

void PrintBestTimes(PowerGridForecast const& forecast)
{
    IVectorView<PowerGridData> forecastSignals = forecast.Forecast();
    DateTime forecastStartTime = forecast.StartTime();
    TimeSpan forecastBlockDuration = forecast.BlockDuration();
    DateTime blockStartTime = forecastStartTime;

    // On failure the forecast will be empty
    if (forecastSignals.Size() == 0)
    {
        std::wcout << L"Error encountered while reading the forecast; try again later." << std::endl;
        return;
    }

    DateTime bestSeverityTimeUTC = DateTime::max();
    DateTime bestSeverityTimeInLowUserImpactTimeUTC = DateTime::max();

    // 1.0 is maximum severity the API can return.
    double bestSeverity = 1.0;
    double bestSeverityInLowUserImpactTime = 1.0;

    // Iterate through the forecast looking for the best times.
    for (auto const& block : forecastSignals)
    {
        auto severity = block.Severity();
        auto isLowImpact = block.IsLowUserExperienceImpact();

        // Check if there is lower severity
        if (severity < bestSeverity)
        {
            bestSeverity = severity;
            bestSeverityTimeUTC = blockStartTime;
        }

        // Check whether there's a lower severity that's also at a time with low user impact.
        if (isLowImpact && severity < bestSeverityInLowUserImpactTime)
        {
            bestSeverityInLowUserImpactTime = severity;
            bestSeverityTimeInLowUserImpactTimeUTC = blockStartTime;
        }

        blockStartTime = blockStartTime + forecastBlockDuration;
    }

    // Print out the best times only if they've been set.
    if (bestSeverityTimeUTC != DateTime::max())
    {
        std::wcout << L"Best time to do work is ";
        PrintDateTime(bestSeverityTimeUTC, true);
        std::wcout << L" with a severity of " << bestSeverity;
        std::wcout << L" and ends at ";
        PrintDateTime(bestSeverityTimeUTC + forecastBlockDuration, true);
        std::wcout << std::endl;
    }

    if (bestSeverityTimeInLowUserImpactTimeUTC != DateTime::max())
    {
        std::wcout << L"Best time with low user impact is ";
        PrintDateTime(bestSeverityTimeInLowUserImpactTimeUTC, true);
        std::wcout << L" with a severity of " << bestSeverityInLowUserImpactTime;
        std::wcout << L" and ends at ";
        PrintDateTime(bestSeverityTimeInLowUserImpactTimeUTC + forecastBlockDuration, true);
        std::wcout << std::endl;
    }
    else
    {
        std::wcout << "There's no low-user-impact time in which to do work." << std::endl;
    }
}

int main() 
{
    std::wcout << L"Power Grid Forecast WinRT API sample app." << std::endl;

    // Register for the forecast notification.
    auto revoker = PowerGridForecast::ForecastUpdated(winrt::auto_revoke, [&](auto, winrt::Windows::Foundation::IInspectable const&) {
        std::wcout << L"Forecast updated..." << std::endl;

        // Forecast has been updated; find the next best times.
        PowerGridForecast forecast = PowerGridForecast::GetForecast();
        PrintBestTimes(forecast);
    });

    // Print out the full forecast.
    PowerGridForecast forecast = PowerGridForecast::GetForecast();
    PrintFullForecast(forecast);

    // Wait until the user presses a key to exit.
    std::cout << "Listening to the signal: a new forecast has been created."
                    "Leave this program open to see when a new forecast is created, otherwise press any key to exit this program..." << std::endl;
    std::cin.get();

    return 0;
}

설명

Windows는 디바이스가 연결된 전력망을 기반으로 전력망 탄소 배출량에 대한 예측을 표시합니다. 이 데이터는 이미 Windows 업데이트 탄소 배출을 줄이기 위해 업데이트가 발생할 때 시간 전환에 사용됩니다. 이 API는 일부 워크로드의 탄소 배출을 줄일 수 있도록 이러한 동일한 예측을 사용자에게 노출합니다. 예를 들어 앱/게임의 업데이트가 발생하는 경우 시간 변경을 수행할 수 있습니다. 또는 오디오 재생의 비트 속도 또는 다른 렌더링 충실도 수준을 제한합니다. 또는 효율성 모드(있는 경우)를 사용하도록 설정합니다.

Power Grid 예측 API는 두 가지 신호를 제공합니다(시간 이동을 프롬프트하기 위해). 하나의 신호에는 최적화할 그리드 조건의 정규화된 심각도 값(0.0에서 1.0 사이)이 포함되어 있습니다(탄소 강도). 다른 신호인 IsLowUserExperienceImpact는 Windows에서 사용자가 디바이스에서 멀어질 것으로 생각할 때를 나타내는 부울 값입니다. 둘 다 대신 하나의 신호만 사용하도록 선택할 수 있습니다. 신호는 개별적으로 뿐만 아니라 함께 값을 갖습니다.

시간 이동은 동일한 에너지를 사용하여 작업을 수행하는 것을 의미하지만 신호에 따라 다른 시간에 수행합니다.

심각도 는 0.0에서 1.0 사이의 정규화된 값입니다. 여기서 0은 가장 좋은 것으로 간주되고 1은 최악입니다. 디바이스가 있는 위치에 따라 전력망 탄소 심각도에 해당합니다.

낮은 사용자 환경 영향. Windows에서 사용자가 자리를 비우거나 많은 리소스를 사용하지 않을 경우를 나타내는 부울 값입니다. 이는 역활성 시간이라고 생각할 수 있습니다. 값이 인 true경우 워크로드를 시간 이동에 적합한 시간으로 간주합니다. 인 경우 false사용자 환경 측면에서 워크로드를 시간 이동에 나쁜 시간으로 간주합니다.

속성

BlockDuration

예측 벡터에 있는 각 요소의 기간입니다.

Forecast

예측 데이터가 포함된 벡터를 가져옵니다. 예측은 연속되며 StartTime에서 시작됩니다. 각 요소의 시작 시간은 로 StartTime + (index * BlockDuration)계산할 수 있습니다.

StartTime

Forecast에서 첫 번째 요소의 시작 시간을 가져옵니다.

메서드

GetForecast()

예측을 검색하는 정적 메서드입니다. 실패하면 빈 예측을 반환합니다.

이벤트

ForecastUpdated

새 예측 페이로드가 준비되면 구독자에게 알리는 이벤트입니다. 앱이 이 알림을 받으면 GetForecast를 호출할 것으로 예상됩니다.

적용 대상