123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- package classes;
- import com.google.gson.annotations.Expose;
- import classes.HolonElement;
- import ui.model.Model;
- public class StorageElement extends HolonElement {
- @Expose
- private Mode status;
-
- @Expose
- private float stateOfCharge;
-
- @Expose
- private float capacity;
-
- @Expose
- private float maxInRatio;
-
- @Expose
- private float maxOutRatio;
- public StorageElement(String eleName, int amount, float energy, Model model) {
- super(eleName, amount, energy, model);
- this.stateOfCharge = 4000;
- this.maxInRatio = 5000;
- this.maxOutRatio = 5000;
- this.capacity = 10000 * 60;// for example tesla power wall 10kwh, 10kw per hour thus * 60 if iteration =
- // minutes//TODO:!
- this.status = Mode.STANDBY;
- }
- public float getEnergyPerElement() {
- switch (status) {
- case STANDBY://TODO: switch wirklich notwendig?
- return 0;
- default:
- return this.energyPerElement;
- }
- }
- public float getPossibleProduction() {
- if (stateOfCharge > 0) {
- if (stateOfCharge >= maxOutRatio) {
- return maxOutRatio;
- } else {
- return stateOfCharge;
- }
- } else {
- return 0;
- }
- }
- /**
- *
- * @param status Mode of currect operation
- * @param energyWanted float how much energy is needed from storage/ can be collected
- * by the storage
- * @return float how much energy was collected/emited
- */
- //TODO: das beachtet nicht wie viel durch widerstand verloren geht
- public float setStatusAndSetEnergy(Mode status, float energyWanted) {
- this.status = status;
- switch (status) {
- case STANDBY:
- this.setEnergyPerElement(0);
- return 0;
- case EMIT:
- if (energyWanted >= maxOutRatio) { // more energy wanted than can be giving
- if (stateOfCharge >= maxOutRatio) { // more energy wanted than can be given
- this.setEnergyPerElement(maxOutRatio);
- return maxOutRatio;
- } else { // less energy stored that can be given
- return notEnoughChargedToEmitWantedEnergy();
- }
- } else {// not enough energy stored than what can be given
- if (stateOfCharge >= energyWanted) { // more energy stored than wanted
- this.setEnergyPerElement(energyWanted);
- return energyWanted;
- } else { // less energy stored than wanted
- return notEnoughChargedToEmitWantedEnergy();
- }
- }
- case COLLECT://TODO: testing
- if (energyWanted >= maxInRatio) { // more engery given than can be collected
- if (stateOfCharge + maxInRatio > capacity) { // Storage nearly full only load rest to get full
- this.setEnergyPerElement(-(capacity - stateOfCharge));
- // stateOfCharge = capacity;
- return capacity - stateOfCharge;
- } else { // load with maximal of what can be collected
- this.setEnergyPerElement(-maxInRatio);
- // stateOfCharge = stateOfCharge + maxInRatio;
- return maxInRatio;
- }
- } else { // less engery given than can be taken in
- if (capacity == stateOfCharge) { // storage full no energy collected
- this.status = Mode.STANDBY;
- return 0;
- } else {
- if (stateOfCharge + energyWanted > capacity) { // Storage nearly full only load rest to get full
- this.setEnergyPerElement(-(capacity - stateOfCharge));
- // stateOfCharge = capacity;
- return capacity - stateOfCharge;
- } else { // take all engery that is available
- this.setEnergyPerElement(-energyWanted);
- // stateOfCharge = stateOfCharge + energy;
- return energyWanted;
- }
- }
- }
- default:
- System.out.println("no status available");
- return 0;
- }
- }
- public Mode getStatus() {
- return this.status;
- }
- public void stateOfChargeCalculation(){
- System.out.println("stateofcharge" + getId()+ "before:" + stateOfCharge + " with incomming " + status + " " + getEnergyPerElement() );
- switch (status){
- case COLLECT:
- case EMIT:
- stateOfCharge = stateOfCharge - getEnergyPerElement();
- break;
- default:
- }
- if(stateOfCharge <= 0 || stateOfCharge >= capacity){
- status = Mode.STANDBY;
- setEnergyPerElement(0);
- }
- System.out.println("stateofcharge after:" + stateOfCharge + " now as " + status + " " + getEnergyPerElement() );
- }
- public void setStateOfCharge(float stateOfCharge){
- if(stateOfCharge < capacity){
- this.stateOfCharge = stateOfCharge;
- }else{
- this.stateOfCharge = capacity;
- }
- }
- private float notEnoughChargedToEmitWantedEnergy(){
- if(stateOfCharge <= 0){
- this.status = Mode.STANDBY;
- this.setEnergyPerElement(0);
- return 0;
- }else{
- this.setEnergyPerElement(stateOfCharge);
- return stateOfCharge;
- }
- }
- public float getStateOfCharge() {
- return stateOfCharge;
- }
- public float getMaxOutRatio() {
- return maxOutRatio;
- }
- public boolean storageChargeDepleted(){
- if(stateOfCharge <= 0){
- return true;
- }else{
- return false;
- }
- }
- public enum Mode {
- COLLECT, EMIT, STANDBY
- }
- }
|