Power.Dev Optimization Services

<back to all web services

TODOptimizerRequest

The following routes are available for this service:
POST/optimizer/tod
<?php namespace dtos;

use DateTime;
use Exception;
use DateInterval;
use JsonSerializable;
use ServiceStack\{IReturn,IReturnVoid,IGet,IPost,IPut,IDelete,IPatch,IMeta,IHasSessionId,IHasBearerToken,IHasVersion};
use ServiceStack\{ICrud,ICreateDb,IUpdateDb,IPatchDb,IDeleteDb,ISaveDb,AuditBase,QueryDb,QueryDb2,QueryData,QueryData2,QueryResponse};
use ServiceStack\{ResponseStatus,ResponseError,EmptyResponse,IdResponse,ArrayList,KeyValuePair2,StringResponse,StringsResponse,Tuple2,Tuple3,ByteArray};
use ServiceStack\{JsonConverters,Returns,TypeContext};


class AnnualRateItem implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $year=0,
        /** @var float */
        public float $value=0.0
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['year'])) $this->year = $o['year'];
        if (isset($o['value'])) $this->value = $o['value'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->year)) $o['year'] = $this->year;
        if (isset($this->value)) $o['value'] = $this->value;
        return empty($o) ? new class(){} : $o;
    }
}

class YoyFactorOptimizarItem implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $year=0,
        /** @var float */
        public float $factor=0.0
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['year'])) $this->year = $o['year'];
        if (isset($o['factor'])) $this->factor = $o['factor'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->year)) $o['year'] = $this->year;
        if (isset($this->factor)) $o['factor'] = $this->factor;
        return empty($o) ? new class(){} : $o;
    }
}

class TodOptimizerRequestItem implements JsonSerializable
{
    public function __construct(
        /** @var int */
        public int $year=0,
        /** @var int */
        public int $month=0,
        /** @var int */
        public int $hour=0,
        /** @var int */
        public int $weekDay=0,
        /** @var float */
        public float $energyPrice=0.0,
        /** @var float */
        public float $capacityPrice=0.0
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['year'])) $this->year = $o['year'];
        if (isset($o['month'])) $this->month = $o['month'];
        if (isset($o['hour'])) $this->hour = $o['hour'];
        if (isset($o['weekDay'])) $this->weekDay = $o['weekDay'];
        if (isset($o['energyPrice'])) $this->energyPrice = $o['energyPrice'];
        if (isset($o['capacityPrice'])) $this->capacityPrice = $o['capacityPrice'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->year)) $o['year'] = $this->year;
        if (isset($this->month)) $o['month'] = $this->month;
        if (isset($this->hour)) $o['hour'] = $this->hour;
        if (isset($this->weekDay)) $o['weekDay'] = $this->weekDay;
        if (isset($this->energyPrice)) $o['energyPrice'] = $this->energyPrice;
        if (isset($this->capacityPrice)) $o['capacityPrice'] = $this->capacityPrice;
        return empty($o) ? new class(){} : $o;
    }
}

class TodOptimizerRequestBase implements JsonSerializable
{
    public function __construct(
        /** @var string */
        public string $projectId='',
        /** @var float */
        public float $chargeDischargeLimit=0.0,
        /** @var float */
        public float $batteryCapacity=0.0,
        /** @var float */
        public float $chargeEfficiency=0.0,
        /** @var float */
        public float $dischargeEfficiency=0.0,
        /** @var float */
        public float $paraciticLossesOperation=0.0,
        /** @var float */
        public float $paraciticLossesResting=0.0,
        /** @var float */
        public float $hvacLosses=0.0,
        /** @var float */
        public float $acCablingLosses=0.0,
        /** @var float */
        public float $transformatorLosses=0.0,
        /** @var float */
        public float $thermalLosses=0.0,
        /** @var float */
        public float $unavailabilityLoss=0.0,
        /** @var float */
        public float $otherLosses=0.0,
        /** @var bool|null */
        public ?bool $enableCapacity=null,
        /** @var array<AnnualRateItem>|null */
        public ?array $energySchedule=null,
        /** @var array<AnnualRateItem>|null */
        public ?array $capacitySchedule=null,
        /** @var array<YoyFactorOptimizarItem>|null */
        public ?array $yoyFactors=null,
        /** @var array<TodOptimizerRequestItem>|null */
        public ?array $data=null,
        /** @var string */
        public string $apiActionId=''
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['projectId'])) $this->projectId = $o['projectId'];
        if (isset($o['chargeDischargeLimit'])) $this->chargeDischargeLimit = $o['chargeDischargeLimit'];
        if (isset($o['batteryCapacity'])) $this->batteryCapacity = $o['batteryCapacity'];
        if (isset($o['chargeEfficiency'])) $this->chargeEfficiency = $o['chargeEfficiency'];
        if (isset($o['dischargeEfficiency'])) $this->dischargeEfficiency = $o['dischargeEfficiency'];
        if (isset($o['paraciticLossesOperation'])) $this->paraciticLossesOperation = $o['paraciticLossesOperation'];
        if (isset($o['paraciticLossesResting'])) $this->paraciticLossesResting = $o['paraciticLossesResting'];
        if (isset($o['hvacLosses'])) $this->hvacLosses = $o['hvacLosses'];
        if (isset($o['acCablingLosses'])) $this->acCablingLosses = $o['acCablingLosses'];
        if (isset($o['transformatorLosses'])) $this->transformatorLosses = $o['transformatorLosses'];
        if (isset($o['thermalLosses'])) $this->thermalLosses = $o['thermalLosses'];
        if (isset($o['unavailabilityLoss'])) $this->unavailabilityLoss = $o['unavailabilityLoss'];
        if (isset($o['otherLosses'])) $this->otherLosses = $o['otherLosses'];
        if (isset($o['enableCapacity'])) $this->enableCapacity = $o['enableCapacity'];
        if (isset($o['energySchedule'])) $this->energySchedule = JsonConverters::fromArray('AnnualRateItem', $o['energySchedule']);
        if (isset($o['capacitySchedule'])) $this->capacitySchedule = JsonConverters::fromArray('AnnualRateItem', $o['capacitySchedule']);
        if (isset($o['yoyFactors'])) $this->yoyFactors = JsonConverters::fromArray('YoyFactorOptimizarItem', $o['yoyFactors']);
        if (isset($o['data'])) $this->data = JsonConverters::fromArray('TodOptimizerRequestItem', $o['data']);
        if (isset($o['apiActionId'])) $this->apiActionId = $o['apiActionId'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->projectId)) $o['projectId'] = $this->projectId;
        if (isset($this->chargeDischargeLimit)) $o['chargeDischargeLimit'] = $this->chargeDischargeLimit;
        if (isset($this->batteryCapacity)) $o['batteryCapacity'] = $this->batteryCapacity;
        if (isset($this->chargeEfficiency)) $o['chargeEfficiency'] = $this->chargeEfficiency;
        if (isset($this->dischargeEfficiency)) $o['dischargeEfficiency'] = $this->dischargeEfficiency;
        if (isset($this->paraciticLossesOperation)) $o['paraciticLossesOperation'] = $this->paraciticLossesOperation;
        if (isset($this->paraciticLossesResting)) $o['paraciticLossesResting'] = $this->paraciticLossesResting;
        if (isset($this->hvacLosses)) $o['hvacLosses'] = $this->hvacLosses;
        if (isset($this->acCablingLosses)) $o['acCablingLosses'] = $this->acCablingLosses;
        if (isset($this->transformatorLosses)) $o['transformatorLosses'] = $this->transformatorLosses;
        if (isset($this->thermalLosses)) $o['thermalLosses'] = $this->thermalLosses;
        if (isset($this->unavailabilityLoss)) $o['unavailabilityLoss'] = $this->unavailabilityLoss;
        if (isset($this->otherLosses)) $o['otherLosses'] = $this->otherLosses;
        if (isset($this->enableCapacity)) $o['enableCapacity'] = $this->enableCapacity;
        if (isset($this->energySchedule)) $o['energySchedule'] = JsonConverters::toArray('AnnualRateItem', $this->energySchedule);
        if (isset($this->capacitySchedule)) $o['capacitySchedule'] = JsonConverters::toArray('AnnualRateItem', $this->capacitySchedule);
        if (isset($this->yoyFactors)) $o['yoyFactors'] = JsonConverters::toArray('YoyFactorOptimizarItem', $this->yoyFactors);
        if (isset($this->data)) $o['data'] = JsonConverters::toArray('TodOptimizerRequestItem', $this->data);
        if (isset($this->apiActionId)) $o['apiActionId'] = $this->apiActionId;
        return empty($o) ? new class(){} : $o;
    }
}

class TODOptimizerRequest extends TodOptimizerRequestBase implements JsonSerializable
{
    /**
     * @param string $projectId
     * @param float $chargeDischargeLimit
     * @param float $batteryCapacity
     * @param float $chargeEfficiency
     * @param float $dischargeEfficiency
     * @param float $paraciticLossesOperation
     * @param float $paraciticLossesResting
     * @param float $hvacLosses
     * @param float $acCablingLosses
     * @param float $transformatorLosses
     * @param float $thermalLosses
     * @param float $unavailabilityLoss
     * @param float $otherLosses
     * @param bool|null $enableCapacity
     * @param array<AnnualRateItem>|null $energySchedule
     * @param array<AnnualRateItem>|null $capacitySchedule
     * @param array<YoyFactorOptimizarItem>|null $yoyFactors
     * @param array<TodOptimizerRequestItem>|null $data
     * @param string $apiActionId
     */
    public function __construct(
        string $projectId='',
        float $chargeDischargeLimit=0.0,
        float $batteryCapacity=0.0,
        float $chargeEfficiency=0.0,
        float $dischargeEfficiency=0.0,
        float $paraciticLossesOperation=0.0,
        float $paraciticLossesResting=0.0,
        float $hvacLosses=0.0,
        float $acCablingLosses=0.0,
        float $transformatorLosses=0.0,
        float $thermalLosses=0.0,
        float $unavailabilityLoss=0.0,
        float $otherLosses=0.0,
        ?bool $enableCapacity=null,
        ?array $energySchedule=null,
        ?array $capacitySchedule=null,
        ?array $yoyFactors=null,
        ?array $data=null,
        string $apiActionId=''
    ) {
        parent::__construct($projectId,$chargeDischargeLimit,$batteryCapacity,$chargeEfficiency,$dischargeEfficiency,$paraciticLossesOperation,$paraciticLossesResting,$hvacLosses,$acCablingLosses,$transformatorLosses,$thermalLosses,$unavailabilityLoss,$otherLosses,$enableCapacity,$energySchedule,$capacitySchedule,$yoyFactors,$data,$apiActionId);
    }

    /** @throws Exception */
    public function fromMap($o): void {
        parent::fromMap($o);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = parent::jsonSerialize();
        return empty($o) ? new class(){} : $o;
    }
}

enum ApiResponseStatus : int
{
    case Undefined = 0;
    case Success = 1;
    case Pending = 10;
    case Failed = 100;
}

class TodOptimizerResponseItem extends TodOptimizerRequestItem implements JsonSerializable
{
    /**
     * @param int $year
     * @param int $month
     * @param int $hour
     * @param int $weekDay
     * @param float $energyPrice
     * @param float $capacityPrice
     */
    public function __construct(
        int $year=0,
        int $month=0,
        int $hour=0,
        int $weekDay=0,
        float $energyPrice=0.0,
        float $capacityPrice=0.0,
        /** @var float */
        public float $chargeState=0.0,
        /** @var float */
        public float $charging=0.0,
        /** @var float */
        public float $loss=0.0,
        /** @var float */
        public float $chargeRate=0.0
    ) {
        parent::__construct($year,$month,$hour,$weekDay,$energyPrice,$capacityPrice);
    }

    /** @throws Exception */
    public function fromMap($o): void {
        parent::fromMap($o);
        if (isset($o['chargeState'])) $this->chargeState = $o['chargeState'];
        if (isset($o['charging'])) $this->charging = $o['charging'];
        if (isset($o['loss'])) $this->loss = $o['loss'];
        if (isset($o['chargeRate'])) $this->chargeRate = $o['chargeRate'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = parent::jsonSerialize();
        if (isset($this->chargeState)) $o['chargeState'] = $this->chargeState;
        if (isset($this->charging)) $o['charging'] = $this->charging;
        if (isset($this->loss)) $o['loss'] = $this->loss;
        if (isset($this->chargeRate)) $o['chargeRate'] = $this->chargeRate;
        return empty($o) ? new class(){} : $o;
    }
}

class TodOptimizerResponse implements JsonSerializable
{
    public function __construct(
        /** @var ApiResponseStatus|null */
        public ?ApiResponseStatus $status=null,
        /** @var string|null */
        public ?string $message=null,
        /** @var string */
        public string $apiActionId='',
        /** @var array<TodOptimizerResponseItem>|null */
        public ?array $testItems=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['status'])) $this->status = JsonConverters::from('ApiResponseStatus', $o['status']);
        if (isset($o['message'])) $this->message = $o['message'];
        if (isset($o['apiActionId'])) $this->apiActionId = $o['apiActionId'];
        if (isset($o['testItems'])) $this->testItems = JsonConverters::fromArray('TodOptimizerResponseItem', $o['testItems']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->status)) $o['status'] = JsonConverters::to('ApiResponseStatus', $this->status);
        if (isset($this->message)) $o['message'] = $this->message;
        if (isset($this->apiActionId)) $o['apiActionId'] = $this->apiActionId;
        if (isset($this->testItems)) $o['testItems'] = JsonConverters::toArray('TodOptimizerResponseItem', $this->testItems);
        return empty($o) ? new class(){} : $o;
    }
}

PHP TODOptimizerRequest DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .json suffix or ?format=json

To embed the response in a jsonp callback, append ?callback=myCallback

HTTP + JSON

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

POST /optimizer/tod HTTP/1.1 
Host: dev-optimization.power.dev 
Accept: application/json
Content-Type: application/json
Content-Length: length

{"projectId":"00000000000000000000000000000000","chargeDischargeLimit":0,"batteryCapacity":0,"chargeEfficiency":0,"dischargeEfficiency":0,"paraciticLossesOperation":0,"paraciticLossesResting":0,"hvacLosses":0,"acCablingLosses":0,"transformatorLosses":0,"thermalLosses":0,"unavailabilityLoss":0,"otherLosses":0,"enableCapacity":false,"apiActionId":"00000000000000000000000000000000"}
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: length

{"status":"Undefined","message":"String","apiActionId":"00000000000000000000000000000000","testItems":[{"chargeState":0,"charging":0,"loss":0,"chargeRate":0,"year":0,"month":0,"hour":0,"weekDay":0,"energyPrice":0,"capacityPrice":0}]}