瀏覽代碼

InformationPanel

Troppmann, Tom 4 年之前
父節點
當前提交
f583d21dd5
共有 1 個文件被更改,包括 36 次插入5 次删除
  1. 36 5
      src/addOns/InformationPanel.java

+ 36 - 5
src/addOns/InformationPanel.java

@@ -6,6 +6,7 @@ import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Insets;
 import java.util.ArrayList;
+import java.util.DoubleSummaryStatistics;
 import java.util.List;
 import java.util.Locale;
 import java.util.Random;
@@ -49,6 +50,8 @@ public class InformationPanel implements AddOn {
 			private int amountFullySupplied;
 			private int amountOversupllied;
 		private int amountSupplier;
+	private DoubleSummaryStatistics partiallySuppliedStats;
+	private DoubleSummaryStatistics overSuppliedStats;
 	
 	private int amountHolonElements;
 		private int amountElementEssential;
@@ -83,7 +86,7 @@ public class InformationPanel implements AddOn {
 	private int amountGroupNodes;
 	private int amountHolons;
 	
-	List<Entry> entryList = new ArrayList<Entry>();
+	List<IEntry> entryList = new ArrayList<IEntry>();
 
 	private int currentEntryVerticalPosition = 0;
 
@@ -132,8 +135,10 @@ public class InformationPanel implements AddOn {
 		entryList.add(new Entry(() -> Integer.toString(amountConsumer) + addPercentage(amountConsumer, amountHolonObjects), "\tConsumer", middle));
 		entryList.add(new Entry(() -> Integer.toString(amountUnderSupplied) + addPercentage(amountUnderSupplied, amountConsumer), "\t\tUnderSupplied", middle));
 		entryList.add(new Entry(() -> Integer.toString(amountPatiallySupplied) + addPercentage(amountPatiallySupplied, amountConsumer), "\t\tPatiallySupplied", middle));
+		entryList.add(new StatEntry(() -> StatToFancyString(partiallySuppliedStats), middle));		
 		entryList.add(new Entry(() -> Integer.toString(amountFullySupplied) + addPercentage(amountFullySupplied, amountConsumer), "\t\tFullySupplied", middle));
 		entryList.add(new Entry(() -> Integer.toString(amountOversupllied) + addPercentage(amountOversupllied, amountConsumer), "\t\tOversupllied", middle));
+		entryList.add(new StatEntry(() -> StatToFancyString(overSuppliedStats), middle));
 		entryList.add(new Entry(() -> Integer.toString(amountSupplier) + addPercentage(amountSupplier, amountHolonObjects), "\tSupplier", middle));
 		entryList.add(new Entry(() -> Integer.toString(amountPassiv) + addPercentage(amountPassiv, amountHolonObjects), "\tPassiv", middle));
 		addSeperator(middle);
@@ -227,6 +232,7 @@ public class InformationPanel implements AddOn {
 		amountInactiveSwitch = amountSwitch - amountActiveSwitch;
 		this.amountUnderSupplied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED)).reduce(0, Integer::sum);
 		this.amountPatiallySupplied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED)).reduce(0, Integer::sum);
+		
 		this.amountFullySupplied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED)).reduce(0, Integer::sum);
 		this.amountOversupllied = dState.getNetworkList().stream().map(net -> net.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED)).reduce(0, Integer::sum);
 		amountSupplier = dState.getNetworkList().stream().map(net -> net.getAmountOfSupplier()).reduce(0, Integer::sum);
@@ -234,9 +240,13 @@ public class InformationPanel implements AddOn {
 		
 		this.amountHolonObjects = amountConsumer + amountSupplier + amountPassiv;
 		
+		partiallySuppliedStats = dState.getNetworkList().stream().flatMap(net -> {
+			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.PARTIALLY_SUPPLIED);
+		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
 		
-		
-		
+		overSuppliedStats = dState.getNetworkList().stream().flatMap(net -> {
+			return net.getConsumerList().stream().filter(con -> con.getState() == HolonObjectState.OVER_SUPPLIED);
+		}).mapToDouble(con -> con.getSupplyBarPercentage()).summaryStatistics();
 		
 		List<Flexibility> flexList = control.getSimManager().getActualFlexManager().getAllFlexWrapper().stream().filter(flexwrapper -> flexwrapper.getFlex().offered).map(flex -> flex.getFlex()).collect(Collectors.toList());
 		amountEssential = (int)flexList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Essential).count();
@@ -315,7 +325,7 @@ public class InformationPanel implements AddOn {
 		if(control != null)  updateEntrys();
 	}
 	
-	private class Entry{
+	private class Entry implements IEntry{
 		public Entry( Supplier<String> getter, String label, JPanel panel) {
 			this.getter = getter;
 			//RegisterToPanel
@@ -336,6 +346,27 @@ public class InformationPanel implements AddOn {
 		
 		
 		
-		
+	}
+	private String StatToFancyString (DoubleSummaryStatistics stats) {
+		return "Min:" + stats.getMin() + " Max:" + stats.getMax() + " Average:" + stats.getAverage();
+	}
+	public  class StatEntry implements IEntry 
+	{
+		JLabel textLabel = new JLabel("Nothing");
+		private Supplier<String> updateFunction = null;
+		public StatEntry( Supplier<String> updateText, JPanel panel){
+			updateFunction = updateText;
+			panel.add(textLabel, createGbConstrain(1, currentEntryVerticalPosition));
+			currentEntryVerticalPosition++;
+		}
+		@Override
+		public void update() {
+			textLabel.setText(updateFunction.get());
+		}
+	}
+	
+	
+	private interface IEntry{
+		public void update();
 	}
 }