2016-09-06 16:49:11 +02:00
|
|
|
package org.hwo.pulscounter;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Hashtable;
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import org.hwo.configuration.ConfigurableAttribute;
|
|
|
|
import org.hwo.configuration.ConfigurableObject;
|
|
|
|
import org.hwo.csv.CSV;
|
|
|
|
import org.hwo.csv.CSVRecord;
|
|
|
|
import org.hwo.interactiveobjects.InteractiveObject;
|
|
|
|
import org.hwo.interactiveobjects.ObjectEditorUI;
|
|
|
|
import org.hwo.models.TableMapper.TableColumn;
|
|
|
|
import org.hwo.pulscounter.ui.ExportSettingsEditorDialog;
|
|
|
|
|
|
|
|
@ObjectEditorUI(editor=ExportSettingsEditorDialog.class)
|
|
|
|
@ConfigurableObject
|
|
|
|
public class ExportSetting {
|
|
|
|
|
|
|
|
@ConfigurableAttribute
|
|
|
|
private String name;
|
|
|
|
@ConfigurableAttribute
|
|
|
|
private TriggerType triggerType;
|
|
|
|
@ConfigurableAttribute
|
|
|
|
private Integer triggerSource;
|
|
|
|
@ConfigurableAttribute
|
|
|
|
private String fileName;
|
|
|
|
@ConfigurableAttribute
|
|
|
|
private String path;
|
|
|
|
@ConfigurableAttribute
|
|
|
|
private Boolean extended;
|
|
|
|
@ConfigurableAttribute
|
|
|
|
private Boolean autostart;
|
|
|
|
@ConfigurableAttribute
|
|
|
|
private Boolean recordDelta;
|
|
|
|
|
|
|
|
private SimpleDateFormat dateFormat;
|
|
|
|
|
|
|
|
public ExportSetting() {
|
|
|
|
this.dateFormat = new SimpleDateFormat();
|
|
|
|
this.name = "unbenannt";
|
|
|
|
this.path = ".";
|
|
|
|
this.fileName = "synololog.csv";
|
|
|
|
this.triggerType = triggerType.ALL;
|
|
|
|
this.triggerSource = 0;
|
|
|
|
this.extended = false;
|
|
|
|
this.autostart = false;
|
|
|
|
this.recordDelta = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@TableColumn(label="Benennung",firstColumn=true)
|
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
public void setName(String name) {
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@TableColumn(label="Auslöser")
|
|
|
|
public TriggerType getTriggerType() {
|
|
|
|
return triggerType;
|
|
|
|
}
|
|
|
|
public void setTriggerType(TriggerType triggerType) {
|
|
|
|
this.triggerType = triggerType;
|
|
|
|
}
|
|
|
|
|
|
|
|
@TableColumn(label="Dateiname")
|
|
|
|
public String getFileName() {
|
|
|
|
return fileName;
|
|
|
|
}
|
|
|
|
public void setFileName(String fileName) {
|
|
|
|
this.fileName = fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@TableColumn(label="Verzeichnis")
|
|
|
|
public String getPath() {
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
public void setPath(String path) {
|
|
|
|
this.path = path;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Integer getTriggerSource() {
|
|
|
|
return triggerSource;
|
|
|
|
}
|
|
|
|
public void setTriggerSource(Integer triggerSource) {
|
|
|
|
this.triggerSource = triggerSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Boolean getExtended() {
|
|
|
|
return extended;
|
|
|
|
}
|
|
|
|
public void setExtended(Boolean extended) {
|
|
|
|
this.extended = extended;
|
|
|
|
}
|
|
|
|
|
|
|
|
@TableColumn(label="Autostart",after="Auslöser")
|
|
|
|
public Boolean getAutostart() {
|
|
|
|
return autostart;
|
|
|
|
}
|
|
|
|
public void setAutostart(Boolean autostart) {
|
|
|
|
this.autostart = autostart;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Boolean getRecordDelta() {
|
|
|
|
return recordDelta;
|
|
|
|
}
|
|
|
|
public void setRecordDelta(Boolean recordDelta) {
|
|
|
|
this.recordDelta = recordDelta;
|
|
|
|
}
|
|
|
|
|
|
|
|
private String calculateFileName(String filename,SnapShot ss){
|
|
|
|
Date d = new Date(((long)ss.getTimestamp())*1000);
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
c.setTime(d);
|
|
|
|
|
|
|
|
return filename
|
|
|
|
.replaceAll("\\%Y", String.format("%04d", new Integer(c.get(Calendar.YEAR))))
|
|
|
|
.replaceAll("\\%M", String.format("%02d", new Integer(c.get(Calendar.MONTH)+1)))
|
|
|
|
.replaceAll("\\%D", String.format("%02d", new Integer(c.get(Calendar.DAY_OF_MONTH))));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void export(){
|
2016-09-08 18:47:31 +02:00
|
|
|
SnapshotManager ssm = PulsCounterApplication.getApplication().getSnapshotManager();
|
2016-09-06 16:49:11 +02:00
|
|
|
|
|
|
|
Hashtable<String, CSV> hash = new Hashtable<String, CSV>();
|
|
|
|
|
|
|
|
for (int n=0;n<ssm.size();n++){
|
|
|
|
SnapShot ss = ssm.loadSnapShot(n);
|
|
|
|
String fn = calculateFileName(fileName, ss);
|
|
|
|
|
|
|
|
if ((triggerType==TriggerType.ALL)||(ss.getTriggerType()==triggerType)){
|
|
|
|
if (triggerSource.equals(-1) || triggerSource.equals(ss.getSource())){
|
|
|
|
|
|
|
|
if (!hash.containsKey(fn)){
|
|
|
|
hash.put(fn, new CSV());
|
|
|
|
if (extended){
|
|
|
|
hash.get(fn).getRecords().add(new CSVRecord(new Object[]{
|
|
|
|
"Zeitstempel", "Datum/Zeit", "Trigger", "Quelle",
|
|
|
|
"CH0","CH1","CH2","CH3","CH4","CH5","CH6","CH7",
|
|
|
|
"CH8","CH9","CH10","CH11","CH12","CH13","CH14","CH15",
|
|
|
|
"CH16","CH17","CH18","CH19","CH20","CH21","CH22","CH23",
|
|
|
|
"CH24","CH25","CH26","CH27","CH28","CH29","CH30","CH31",
|
|
|
|
"AN0","AN1","AN2","AN3","AN4","AN5","AN6","AN7"}));
|
|
|
|
} else {
|
|
|
|
hash.get(fn).getRecords().add(new CSVRecord(new Object[]{
|
|
|
|
"Datum/Zeit",
|
|
|
|
"CH0","CH1","CH2","CH3","CH4","CH5","CH6","CH7",
|
|
|
|
"CH8","CH9","CH10","CH11","CH12","CH13","CH14","CH15",
|
|
|
|
"CH16","CH17","CH18","CH19","CH20","CH21","CH22","CH23",
|
|
|
|
"CH24","CH25","CH26","CH27","CH28","CH29","CH30","CH31",
|
|
|
|
"AN0","AN1","AN2","AN3","AN4","AN5","AN6","AN7"}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hash.get(fn).getRecords().add(ss.getCSVRecord(extended));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (String fn: hash.keySet()){
|
|
|
|
if (recordDelta){
|
|
|
|
CSV csv = hash.get(fn);
|
|
|
|
if (!csv.getRecords().isEmpty()){
|
|
|
|
Iterator<CSVRecord> iter = csv.getRecords().iterator();
|
|
|
|
|
|
|
|
iter.next();
|
|
|
|
|
|
|
|
CSVRecord n = iter.next();
|
|
|
|
Integer[] vals = new Integer[32];
|
|
|
|
|
|
|
|
for (int i=0;i<32;i++){
|
|
|
|
vals[i] = n.getIntegerValue(extended ? i + 4 : i + 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
while (iter.hasNext()){
|
|
|
|
n = iter.next();
|
|
|
|
|
|
|
|
for (int i=0;i<32;i++){
|
|
|
|
Integer v = n.getIntegerValue(extended ? i + 4 : i + 1 );
|
|
|
|
n.setValue(extended ? i + 4 : i + 1 , v - vals[i]);
|
|
|
|
vals[i] = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
csv.getRecords().remove(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
hash.get(fn).saveToFile(new File(path,fn));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|