User Tools

Site Tools


zalozeni:grafika:mainresultcellforinstances

MainResultCellForInstances

Metoda getMainResultCellForInstances() tridy ExperimentTypeGraphicFactory bere jako vstup List<ExperimentInstance> a vraci GenericCell se statistikou vysledu z dilcich ExperientInstance. Obecne povidani o GenericCell vcetne direktiv, ktere je treba pri jejim vytvareni dodrzovat, je mozno nalezt zde.

Toto je jedina GenericCell, kde je jedna zrada, nebot defaultni constructor bere jako parametr ExperimentIntance. Nasleduje workaround (staci se podivat na constructory).

Dale je zde ukazana dulezita trida, ktera pocita statistiku. Ta se odkazuje na tridy v jadre.

public class DokuwikiMainResultCellController extends GenericCell {
 
	@FXML
	private Label lblRes1;
 
	private List<ExperimentInstance> expInstances;
	private DokuwikiCalculator calculator;
 
	public DokuwikiMainResultCellController(ExperimentInstance expInst) {
		super(expInst);
		setFXMLFile("DokuwikiMainResultCell.fxml");
	}
 
	public DokuwikiMainResultCellController(List<ExperimentInstance> expInstances) {
		super(null);
		setFXMLFile("DokuwikiMainResultCell.fxml");
		this.expInstances = expInstances;
 
		calculator = new DokuwikiCalculator(expInstances);
	}
 
	public void initialize(URL location, ResourceBundle resources) {
	}
 
	@Override
	public void fillGraphics() {
		setBackgroundColor();
 
		if (expInstances == null || expInstances.isEmpty())
			return;
 
		lblRes1.setText(calculator.getRes1Stat().asString(1, 1));
	}
 
}
public class DokuwikiCalculator {
 
	private Statistic res1Stat;
 
	private List<ExperimentInstance> expInstances = new ArrayList<ExperimentInstance>();
 
	public DokuwikiCalculator(List<ExperimentInstance> expInstances) {
		for (ExperimentInstance experimentInstance : expInstances) {
			if (experimentInstance.getStatus() == ExperimentStatus.ABORTED || experimentInstance.getStatus() == ExperimentStatus.ENDED) {
				this.expInstances.add(experimentInstance);
			}
		}
		if (this.expInstances.isEmpty())
			return;
		calculate();
	}
 
	private void calculate() {
		List<Double> res1List = new ArrayList<Double>();
 
		DokuwikiDataService dataService;
		for (ExperimentInstance experimentInstance : expInstances) {
			dataService = (DokuwikiDataService) experimentInstance.getDataService();
			res1List.add(dataService.getResult1());
		}
 
		res1Stat = StatisticCalculator.getStatistic(res1List);
	}
 
	public Statistic getRes1Stat() {
		return res1Stat;
	}
 
}
zalozeni/grafika/mainresultcellforinstances.txt · Last modified: 2016/07/28 17:40 by jlochman