User Tools

Site Tools


zalozeni:experiment:dataservice

ExperimentInstanceDataService

ExperimentInstanceDataService poskytuje metody pro ukladani dat do dvou tabulek DB

  1. casova data reprezentovana entitou ExperimentInstanceTimedData. Tato data predstavuji tabulku namerenych dat experimentu
  2. finalni data reprezentovana entitou ExperimentInstanceSingleData. Tato data predstavuji finalni data, vysledky experimentu

Priklad implementace teto tridy je ukazan. DATA_ROW zde reprezentuje ExperimentInstanceTimedData, Result1 reprezentuje ExperimentInstanceSingleData.

Stoji za komentar, ze casova data jsou zaobalena do tridy DokuwikiDataRow.

public class DokuwikiDataService extends ExperimentInstanceDataService {
 
	private final static String DATA_ROW = "DR";
 
	private final static String RESULT1 = "res1";
 
	public DokuwikiDataService(ExperimentInstance instance) {
		super(instance);
	}
 
	public void saveDataRow(DokuwikiDataRow dataRow) {
		addTimedStringValue(dataRow.asString(), DATA_ROW, dataRow.getTime());
	}
 
	public List<DokuwikiDataRow> getDataRows() {
		List<DokuwikiDataRow> dataRows = new ArrayList<DokuwikiDataRow>();
 
		List<ExperimentInstanceTimedData> timedData = instance.getTimedData();
		for (ExperimentInstanceTimedData eiTD : timedData) {
			DokuwikiDataRow dataRow = new DokuwikiDataRow();
			dataRow.fromString(eiTD.getValue(), eiTD.getExperimentTime());
			dataRows.add(dataRow);
		}
		Collections.sort(dataRows);
 
		return dataRows;
	}
 
	public void saveResult1(double result1) {
		saveFinalDoubleValue(result1, RESULT1);
	}
 
	public double getResult1() {
		return loadSingleDoubleValue(RESULT1);
	}
 
}

Trida DokuwikiDataRow zaobaluje vsechna data, ktera se v danem case meri. Neni odvozena z jadra, je treba si ji vytvorit rucne. Ukazalo se jako uzitecne do teto tridy zakomponovat

  • metody pro vypis jednotlivych hodnot jako String: getTimeString(), getValue1String(), getValue2String()
  • metodu pro prevod do Stringu: asString()
  • metodu pro nacteni ze Stringu: fromString(String s, long time)
  • implemetovat interface Comparable<DokuwikiDataRow>: metoda compareTo(DokuwikiDataRow o)
public class DokuwikiDataRow implements Comparable<DokuwikiDataRow> {
 
	private final static String SEPARATOR = ";";
 
	private long time;
	private double value1;
	private double value2;
 
	public DokuwikiDataRow() {
		clear();
	}
 
	public DokuwikiDataRow(long time) {
		this();
		this.time = time;
	}
 
	public void clear() {
		this.time = 0;
		this.value1 = 0;
		this.value2 = 0;
	}
 
	public String getTimeString() {
		return TimeUtils.getStringFromLongTime(getTime());
	}
 
	public String getValue1String() {
		return DecimalHelper.toString(value1, 1);
	}
 
	public String getValue2String() {
		return DecimalHelper.toString(value2, 1);
	}
 
	public String asString() {
		String result = "" + getValue1String() + SEPARATOR + getValue2String();
		return result;
	}
 
	public void fromString(String s, long time) {
		this.time = time;
 
		List<String> items = Arrays.asList(s.split(SEPARATOR));
		if (items.size() != 2)
			return;
		this.value1 = Double.parseDouble(items.get(0));
		this.value2 = Double.parseDouble(items.get(1));
	}
 
	public long getTime() {
		return time;
	}
 
	public void setTime(long time) {
		this.time = time;
	}
 
	public double getValue1() {
		return value1;
	}
 
	public void setValue1(double value1) {
		this.value1 = value1;
	}
 
	public double getValue2() {
		return value2;
	}
 
	public void setValue2(double value2) {
		this.value2 = value2;
	}
 
	public int compareTo(DokuwikiDataRow o) {
		return (int) (this.getTime() - o.getTime());
	}
 
}
zalozeni/experiment/dataservice.txt · Last modified: 2016/07/22 13:29 by jlochman