content: /**
   * Copyright 2020 Alexander Herzog
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package ui.statistics;
  
  import java.net.URL;
  
  import language.Language;
  import mathtools.TimeTools;
  import simulator.statistics.Statistics;
  import systemtools.statistics.StatisticViewerText;
  import systemtools.statistics.StatisticsBasePanel;
  import ui.help.Help;
  import ui.statistics.analyticcompare.AnalyticInfo;
  import ui.tools.FlatLaFHelper;
  
  /**
   * Vergleicht die Statistikergebnisse eines Modells mit einem zugehrigen Erlang-C-Modell.
   * @author Alexander Herzog
   */
  public class StatisticViewerErlangCCompare extends StatisticViewerText {
  	/** Statistikobjekt, aus dem die anzuzeigenden Daten entnommen werden sollen */
  	private final Statistics statistics;
  
  	/**
  	 * Konstruktor der Klasse
  	 * @param statistics	Statistikobjekt, aus dem die anzuzeigenden Daten entnommen werden sollen
  	 */
  	public StatisticViewerErlangCCompare(final Statistics statistics) {
  		this.statistics=statistics;
  	}
  
  	/**
  	 * Zeigt im Fubereich der Hilfeseite eine "Erklrung einblenden"-Schaltflche, die,
  	 * wenn sie angeklickt wird, eine html-Hilfeseite anzeigt.
  	 * @param topic	Hilfe-Thema (wird als Datei in den "description_*"-Ordern gesucht)
  	 */
  	private void addDescription(final String topic) {
  		final URL url=StatisticViewerOverviewText.class.getResource("description_"+Language.getCurrentLanguage()+"/"+topic+".html");
  		addDescription(url,helpTopic->Help.topic(getViewer(false),helpTopic));
  	}
  
  	@Override
  	protected String getDescriptionCustomStyles() {
  		if (FlatLaFHelper.isDark()) return StatisticsPanel.DARK_MODE_DESACRIPTION_STYLE;
  		return null;
  	}
  
  	@Override
  	protected void buildText() {
  		addHeading(1,Language.tr("Statistics.ErlangCCompare"));
  
  		final AnalyticInfo analyticInfo=new AnalyticInfo();
  		if (!analyticInfo.build(statistics.editModel)) {buildNotCompareable(); return;}
  		final AnalyticInfo.SimulationResults simulationResults=new AnalyticInfo.SimulationResults(statistics);
  
  		buildTextModelInfo(analyticInfo);
  		buildTextSimResults(simulationResults);
  		buildTextAnalytic(analyticInfo,simulationResults);
  
  		/* Infotext  */
  		addDescription("ErlangCCompare");
  	}
  
  	/**
  	 * Gibt aus, dass zu dem gegebenen Modell
  	 * kein analytisches Vergleichsmodell erstellt
  	 * werden kann.
  	 */
  	private void buildNotCompareable() {
  		beginParagraph();
  		addLine(Language.tr("Statistics.ErlangCCompare.NotCompareable"));
  		endParagraph();
  	}
  
  	/**
  	 * Gibt allgemeine Modell-Informationen aus.
  	 * @param analyticInfo	Analytisches Vergleichsmodell
  	 */
  	private void buildTextModelInfo(final AnalyticInfo analyticInfo) {
  		addHeading(2,Language.tr("Statistics.ErlangCCompare.SimModel"));
  
  		addHeading(3,Language.tr("Statistics.ErlangCompare.Arrival"));
  		beginParagraph();
  		addLines(analyticInfo.getSourceInfo());
  		endParagraph();
  
  		addHeading(3,Language.tr("Statistics.ErlangCompare.Service"));
  		beginParagraph();
  		addLines(analyticInfo.getProcessInfo());
  		endParagraph();
  	}
  
  	/**
  	 * Gibt die Simulationsergebnisse aus.
  	 * @param simulationResults	Simulationsergebnisse
  	 */
  	private void buildTextSimResults(final AnalyticInfo.SimulationResults simulationResults) {
  		addHeading(2,Language.tr("Statistics.ErlangCCompare.SimResults"));
  
  		addHeading(3,Language.tr("Statistics.ErlangCompare.NumberOfClients"));
  		beginParagraph();
  		addLine("E[NQ]"+StatisticTools.formatNumberExt(simulationResults.ENQ,true));
  		addLine("E[NS]"+StatisticTools.formatNumberExt(simulationResults.ENS,true));
  		addLine("E[N]"+StatisticTools.formatNumberExt(simulationResults.EN,true));
  		endParagraph();
  
  		addHeading(3,Language.tr("Statistics.ErlangCompare.Times"));
  		beginParagraph();
  		addLine("E[W]"+StatisticTools.formatNumberExt(simulationResults.EW,true)+" "+Language.tr("Statistics.Seconds")+" ("+TimeTools.formatExactTime(simulationResults.EW,1)+")");
  		addLine("E[V]"+StatisticTools.formatNumberExt(simulationResults.EV,true)+" "+Language.tr("Statistics.Seconds")+" ("+TimeTools.formatExactTime(simulationResults.EV,1)+")");
  		endParagraph();
  
  		if (!simulationResults.resourceInfo.isEmpty()) {
  			addHeading(3,Language.tr("Statistics.Utilization"));
  			beginParagraph();
  			addLines(simulationResults.resourceInfo);
  			endParagraph();
  		}
  	}
  
  	/**
  	 * Gibt die Ergebnisse der analytische Rechnungen aus.
  	 * @param results	Ergebnisse der analytische Rechnungen
  	 */
  	private void outputAnalyticResults(final AnalyticInfo.InfoResult results) {
  		if (results==null) return;
  
  		addHeading(3,Language.tr("Statistics.ErlangCCompare.Results.Input"));
  		beginParagraph();
  		addLines(results.getInput());
  		endParagraph();
  
  		final String calculated=results.getCalculated();
  		if (!calculated.isEmpty()) {
  			addHeading(3,Language.tr("Statistics.ErlangCCompare.Results.Calculated"));
  			beginParagraph();
  			addLines(calculated);
  			endParagraph();
  		}
  
  		final String numbers=results.getNumbers();
  		if (!numbers.isEmpty()) {
  			addHeading(3,Language.tr("Statistics.ErlangCompare.NumberOfClients"));
  			beginParagraph();
  			addLines(numbers);
  			endParagraph();
  		}
  
  		final String times=results.getTimes();
  		if (!times.isEmpty()) {
  			addHeading(3,Language.tr("Statistics.ErlangCompare.Times"));
  			beginParagraph();
  			addLines(times);
  			endParagraph();
  		}
  
  		final String info=results.getInfo();
  		if (!info.isEmpty()) {
  			addHeading(3,Language.tr("Statistics.ErlangCompare.Info"));
  			beginParagraph();
  			addLines(info);
  			endParagraph();
  		}
  	}
  
  	/**
  	 * Gibt die Vergleichsrechnungen fr die verschiedenen analytischen Modelle aus.
  	 * @param analyticInfo	Analytisches Vergleichsmodell
  	 * @param simulationResults	Simulationsergebnisse
  	 */
  	private void buildTextAnalytic(final AnalyticInfo analyticInfo, final AnalyticInfo.SimulationResults simulationResults) {
  		addHeading(2,Language.tr("Statistics.ErlangCCompare.Results.ErlangC"));
  		outputAnalyticResults(analyticInfo.getErlangC(simulationResults));
  
  		if (analyticInfo.hasCancelTimes()) {
  			addHeading(2,Language.tr("Statistics.ErlangCCompare.Results.ErlangCExt"));
  			outputAnalyticResults(analyticInfo.getErlangCExt(simulationResults));
  		}
  
  		addHeading(2,Language.tr("Statistics.ErlangCCompare.Results.AllenCunneen"));
  		outputAnalyticResults(analyticInfo.getAllenCunneen(simulationResults));
  	}
  
  	/**
  	 * Soll fr diese Komponente der Standard-FileDrop-Listener des {@link StatisticsBasePanel} verwendet werden?
  	 * @return	bergeordneten FileDrop-Listener verwenden (<code>false</code>) oder eigenen (<code>true</code>)
  	 */
  	@Override
  	public boolean hasOwnFileDropListener() {
  		return false;
  	}
  }