User Tools

Site Tools


zalozeni:experiment:exportservice

ExperimentExportService

ExperimentExportService je servica pro export namerenych dat ve formatech txt, csv, pdf. Uchovava si v pameti List<ExperimentInstance>, ktere maji ExperimentStatus = [ENDED, ABORTED] - pouze tyto ExperimentInstance jsou predmetem exportu.

Metody exportAsTXT(), exportAsCSV() jsou jednoduche a je prihodne je definovat primo v service. Vytvoreni protokolu je peklo a je prenechano tride DokuwikiPDFCreator, jez je popsana zde.

public class DokuwikiExportService extends ExperimentExportService {
 
	public DokuwikiExportService(List<ExperimentInstance> expInstances) {
		super(expInstances);
	}
 
	@Override
	public void exportAsTXT(String fullFileName) throws IOException {
		int counter = 0;
		for (ExperimentInstance expInstance : expInstances) {
			counter++;
 
			File file = new File(fullFileName + "_" + counter + ".txt");
			if (!file.exists()) {
				file.createNewFile();
			}
 
			FileWriter fw = new FileWriter(file.getAbsoluteFile());
			BufferedWriter bw = new BufferedWriter(fw);
 
			DokuwikiDataService dataService = (DokuwikiDataService) expInstance.getDataService();
			List<DokuwikiDataRow> dataRows = dataService.getDataRows();
 
			String head = I18n.getGraphicsBundle().getString("time") + ",";
			head += I18n.getGraphicsBundle().getString("value1") + ",";
			head += I18n.getGraphicsBundle().getString("value2") + ";";
			bw.write(head);
 
			bw.newLine();
			String line;
			for (DokuwikiDataRow dr : dataRows) {
				line = dr.getTimeString() + ",";
				line += dr.getValue1String() + ",";
				line += dr.getValue2String() + ";";
				bw.write(line);
				bw.newLine();
			}
 
			bw.close();
			fw.close();
		}
	}
 
	@Override
	public void exportAsCSV(String fullFileName) throws IOException {
		// similiar to previous one
	}
 
	@Override
	public void exportAsPDF(String fullFileName) throws IOException {
		DokuwikiPDFCreator pdfCreator = new DokuwikiPDFCreator(expInstances, fullFileName);
		pdfCreator.createPDF();
	}
 
}
zalozeni/experiment/exportservice.txt · Last modified: 2016/07/22 14:43 by jlochman