Skip to content

Commit

Permalink
Feature/conluz 68 (#69)
Browse files Browse the repository at this point in the history
* [conluz-68] Moved classes to get package

* [conluz-68] Renamed measurement to replace - by _

* [conluz-68] Created method to get an auth method to perform request through the Huawei REST API

* [conluz-68] Created repository to get real time production from Huawei REST API

* [conluz-68] Created DB migration to create Huawei config table

* [conluz-68] Created test to verify repository retrieving real time production data

* [conluz-68] Completed a call to get real-time production

* [conluz-68] Prepared job to run every five minutes and sync real time production for a Huawei inverter

* [conluz-68] Fixed tests

* [conluz-68] Implemented job to retrieve hourly production from a Huawei inverter throught the REST API every hour

* [conluz-68] Implemented endpoint to to create a plant

* [conluz-68] Implemented endpoint to get all plants

* [conluz-68] Implemented endpoint to update a plant

* [conluz-68] Implemented endponit to delete a plant
  • Loading branch information
viktorKhan authored Apr 13, 2024
1 parent bed84a4 commit 2094b71
Show file tree
Hide file tree
Showing 109 changed files with 4,661 additions and 315 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public SupplyAlreadyExistsException(SupplyCode code) {
this.code = code;
}

public SupplyCode getUserId() {
public SupplyCode getCode() {
return code;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.lucoenergia.conluz.domain.admin.supply.update.UpdateSupplyRepository;
import org.lucoenergia.conluz.domain.admin.user.User;
import org.lucoenergia.conluz.domain.admin.user.get.GetUserRepository;
import org.lucoenergia.conluz.infrastructure.shared.time.StringToLocalDateConverter;
import org.lucoenergia.conluz.infrastructure.shared.time.DateConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
Expand All @@ -25,13 +25,15 @@ public class DatadisSuppliesSyncService {
private final UpdateSupplyRepository updateSupplyRepository;
private final GetSupplyRepositoryDatadis getSupplyRepositoryDatadis;
private final GetUserRepository getUserRepository;
private final DateConverter dateConverter;

public DatadisSuppliesSyncService(GetSupplyRepository getSupplyRepository, UpdateSupplyRepository updateSupplyRepository,
GetSupplyRepositoryDatadis getSupplyRepositoryDatadis, GetUserRepository getUserRepository) {
GetSupplyRepositoryDatadis getSupplyRepositoryDatadis, GetUserRepository getUserRepository, DateConverter dateConverter) {
this.getSupplyRepository = getSupplyRepository;
this.updateSupplyRepository = updateSupplyRepository;
this.getSupplyRepositoryDatadis = getSupplyRepositoryDatadis;
this.getUserRepository = getUserRepository;
this.dateConverter = dateConverter;
}

/**
Expand All @@ -53,7 +55,7 @@ public void synchronizeSupplies() {
supply.setDistributor(datadisSupply.getDistributor());
supply.setPointType(datadisSupply.getPointType());
supply.setValidDateFrom(datadisSupply.getValidDateFrom() != null ?
StringToLocalDateConverter.convert(datadisSupply.getValidDateFrom()) :
dateConverter.convertStringToLocalDate(datadisSupply.getValidDateFrom()) :
null);

updateSupplyRepository.update(supply);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.lucoenergia.conluz.domain.price.sync;

import org.lucoenergia.conluz.domain.price.PriceByHour;
import org.lucoenergia.conluz.domain.price.persist.PersistOmiePricesRepository;
import org.lucoenergia.conluz.infrastructure.price.omie.get.GetPriceRepositoryInflux;
import org.springframework.stereotype.Service;

Expand All @@ -11,12 +12,15 @@
public class SyncDailyPricesService {

private final GetPriceRepositoryInflux getPriceRepository;
private final PersistOmiePricesRepository persistOmiePricesRepository;

public SyncDailyPricesService(GetPriceRepositoryInflux getPriceRepository) {
public SyncDailyPricesService(GetPriceRepositoryInflux getPriceRepository, PersistOmiePricesRepository persistOmiePricesRepository) {
this.getPriceRepository = getPriceRepository;
this.persistOmiePricesRepository = persistOmiePricesRepository;
}

public void syncDailyPrices(OffsetDateTime day) {
List<PriceByHour> prices = getPriceRepository.getPricesByDay(day);
persistOmiePricesRepository.persistPrices(prices);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.lucoenergia.conluz.domain.production;

public enum InverterProvider {

HUAWEI
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.lucoenergia.conluz.domain.production.get;

import org.lucoenergia.conluz.domain.production.plant.Plant;
import org.lucoenergia.conluz.domain.production.InverterProvider;

import java.util.List;

public interface GetEnergyStationRepository {

List<Plant> findAll();

List<Plant> findAllByInverterProvider(InverterProvider provider);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package org.lucoenergia.conluz.domain.production;
package org.lucoenergia.conluz.domain.production.get;

import org.lucoenergia.conluz.domain.production.InstantProduction;
import org.lucoenergia.conluz.domain.production.ProductionByTime;

import java.time.OffsetDateTime;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.lucoenergia.conluz.domain.production;
package org.lucoenergia.conluz.domain.production.get;

import org.lucoenergia.conluz.domain.admin.supply.get.GetSupplyRepository;
import org.lucoenergia.conluz.domain.admin.supply.Supply;
import org.lucoenergia.conluz.domain.admin.supply.SupplyNotFoundException;
import org.lucoenergia.conluz.domain.production.InstantProduction;
import org.lucoenergia.conluz.domain.production.ProductionByTime;
import org.lucoenergia.conluz.domain.shared.SupplyId;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package org.lucoenergia.conluz.domain.production.huawei;

import java.time.OffsetDateTime;

public class HourlyProduction {

private OffsetDateTime time;
private String stationCode;
/**
* Global irradiation in kWh/m²
*/
private Double radiationIntensity;
/**
* Theoretical yield in kWh
*/
private Double theoryPower;
/**
* Inverter yield in kWh
*/
private Double inverterPower;
/**
* Feed-in energy in kWh
*/
private Double ongridPower;
/**
* Revenue.
* The currency specified in the management system
*/
private Double powerProfit;

public OffsetDateTime getTime() {
return time;
}

public String getStationCode() {
return stationCode;
}

public Double getRadiationIntensity() {
return radiationIntensity;
}

public Double getTheoryPower() {
return theoryPower;
}

public Double getInverterPower() {
return inverterPower;
}

public Double getOngridPower() {
return ongridPower;
}

public Double getPowerProfit() {
return powerProfit;
}


public static class Builder {
private OffsetDateTime time;
private Double radiationIntensity;
private Double theoryPower;
private Double inverterPower;
private Double ongridPower;
private Double powerProfit;
private String stationCode;

public Builder withTime(OffsetDateTime time) {
this.time = time;
return this;
}

public Builder withRadiationIntensity(Double radiationIntensity) {
this.radiationIntensity = radiationIntensity;
return this;
}

public Builder withTheoryPower(Double theoryPower) {
this.theoryPower = theoryPower;
return this;
}

public Builder withInverterPower(Double inverterPower) {
this.inverterPower = inverterPower;
return this;
}

public Builder withOngridPower(Double ongridPower) {
this.ongridPower = ongridPower;
return this;
}

public Builder withPowerProfit(Double powerProfit) {
this.powerProfit = powerProfit;
return this;
}

public Builder withStationCode(String stationCode) {
this.stationCode = stationCode;
return this;
}

public HourlyProduction build() {
HourlyProduction hourlyProduction = new HourlyProduction();
hourlyProduction.time = this.time;
hourlyProduction.radiationIntensity = this.radiationIntensity;
hourlyProduction.theoryPower = this.theoryPower;
hourlyProduction.inverterPower = this.inverterPower;
hourlyProduction.ongridPower = this.ongridPower;
hourlyProduction.powerProfit = this.powerProfit;
hourlyProduction.stationCode = this.stationCode;
return hourlyProduction;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.lucoenergia.conluz.domain.production.huawei;

import java.util.UUID;

public class HuaweiConfig {

public static final String HUAWEI_REAL_TIME_PRODUCTION_MEASUREMENT = "huawei_production_realtime";
public static final String HUAWEI_HOURLY_PRODUCTION_MEASUREMENT = "huawei_production_hourly";

public static final String BASE_URL = "https://eu5.fusionsolar.huawei.com/thirdData";

private UUID id;
private String username;
private String password;

public UUID getId() {
return id;
}

public String getUsername() {
return username;
}

public String getPassword() {
return password;
}

public static class Builder {
private UUID id;
private String username;
private String password;

public Builder setId(UUID id) {
this.id = id;
return this;
}

public Builder setUsername(String username) {
this.username = username;
return this;
}

public Builder setPassword(String password) {
this.password = password;
return this;
}

public HuaweiConfig build() {
HuaweiConfig huaweiConfig = new HuaweiConfig();
huaweiConfig.id = this.id;
huaweiConfig.username = this.username;
huaweiConfig.password = this.password;
return huaweiConfig;
}
}
}
Loading

0 comments on commit 2094b71

Please sign in to comment.