Somehow works better than before
This commit is contained in:
@@ -32,11 +32,11 @@ public class DataMessage extends Message{
|
||||
private final List<Object> data;
|
||||
private final List<Metadata> metadata;
|
||||
|
||||
public DataMessage(){
|
||||
this.data = new ArrayList<Object>();
|
||||
this.metadata = new ArrayList<>();
|
||||
}
|
||||
|
||||
// public DataMessage(){
|
||||
// this.data = new ArrayList<Object>();
|
||||
// this.metadata = new ArrayList<>();
|
||||
// }
|
||||
//
|
||||
public DataMessage(List<Metadata> metadata){
|
||||
this.data = new ArrayList<Object>();
|
||||
this.metadata = metadata;
|
||||
|
||||
@@ -391,7 +391,7 @@ public class DataDeserializerMDA implements DataDeserializer {
|
||||
for(Message m: container.getMessage()){
|
||||
if(m instanceof DataMessage){
|
||||
// Add own data to message and pass it to container
|
||||
DataMessage mm = new DataMessage();
|
||||
DataMessage mm = new DataMessage(new ArrayList<Metadata>()); // Workaround
|
||||
for(Double[] d: data){
|
||||
mm.getData().add(d[i]);
|
||||
}
|
||||
@@ -419,7 +419,7 @@ public class DataDeserializerMDA implements DataDeserializer {
|
||||
logger.fine("Convert data structure [rank="+scanRank+"]...");
|
||||
|
||||
for(int t = 0; t<npts ; t++){
|
||||
DataMessage m = new DataMessage();
|
||||
DataMessage m = new DataMessage(new ArrayList<Metadata>()); // workaround
|
||||
for(Double[] d: data){
|
||||
m.getData().add(d[t]);
|
||||
}
|
||||
|
||||
@@ -42,9 +42,9 @@ import ch.psi.fda.core.Manipulation;
|
||||
import ch.psi.fda.core.manipulator.JythonManipulation;
|
||||
import ch.psi.fda.core.messages.ComponentMetadata;
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.DataMessageMetadata;
|
||||
import ch.psi.fda.core.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.core.messages.Message;
|
||||
import ch.psi.fda.core.messages.Metadata;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMapping;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMappingChannel;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMappingID;
|
||||
@@ -77,8 +77,6 @@ public class ManipulatorTest {
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testConstructor() {
|
||||
DataMessageMetadata dmm = new DataMessageMetadata();
|
||||
|
||||
String id="computedId";
|
||||
String script = "import math\ndef process(o):\n return math.cos(10.0) + math.sin(o)";
|
||||
List<JythonParameterMapping> mapping = new ArrayList<JythonParameterMapping>();
|
||||
@@ -89,14 +87,12 @@ public class ManipulatorTest {
|
||||
// id "myid" which is expected in the mapping
|
||||
List<Manipulation> manipulations = new ArrayList<Manipulation>();
|
||||
manipulations.add(manipulation);
|
||||
new Manipulator(bus, dmm, manipulations);
|
||||
new Manipulator(bus, manipulations);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorNoMappingNoParam() {
|
||||
DataMessageMetadata dmm = new DataMessageMetadata();
|
||||
|
||||
String id="cid";
|
||||
String script = "import math\ndef process():\n return 0.0";
|
||||
List<JythonParameterMapping> mapping = new ArrayList<JythonParameterMapping>();
|
||||
@@ -105,15 +101,15 @@ public class ManipulatorTest {
|
||||
|
||||
List<Manipulation> manipulations = new ArrayList<Manipulation>();
|
||||
manipulations.add(manipulation);
|
||||
new Manipulator(bus, dmm, manipulations);
|
||||
new Manipulator(bus, manipulations);
|
||||
// Expect IllegalArgument Exception as there is no mapping for the parameter c
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorMappingNoParam() {
|
||||
DataMessageMetadata dmm = new DataMessageMetadata();
|
||||
dmm.getComponents().add(new ComponentMetadata("myid"));
|
||||
dmm.getComponents().add(new ComponentMetadata("myid2"));
|
||||
List<Metadata> dmm = new ArrayList<>();
|
||||
dmm.add(new Metadata("myid"));
|
||||
dmm.add(new Metadata("myid2"));
|
||||
|
||||
String id="cid";
|
||||
String script = "import math\ndef process():\n return 0.0";
|
||||
@@ -123,8 +119,7 @@ public class ManipulatorTest {
|
||||
|
||||
List<Manipulation> manipulations = new ArrayList<Manipulation>();
|
||||
manipulations.add(manipulation);
|
||||
new Manipulator(bus, dmm, manipulations);
|
||||
// Expect IllegalArgument Exception as there is no mapping for the parameter c
|
||||
new Manipulator(bus, manipulations).onMessage(new DataMessage(dmm));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,9 +127,9 @@ public class ManipulatorTest {
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testConstructorNoMapping() {
|
||||
DataMessageMetadata dmm = new DataMessageMetadata();
|
||||
dmm.getComponents().add(new ComponentMetadata("myid"));
|
||||
dmm.getComponents().add(new ComponentMetadata("myid2"));
|
||||
List<Metadata> dmm = new ArrayList<>();
|
||||
dmm.add(new Metadata("myid"));
|
||||
dmm.add(new Metadata("myid2"));
|
||||
|
||||
String id="cid";
|
||||
String script = "import math\ndef process(o ,c):\n return math.cos(c) + math.sin(o)";
|
||||
@@ -144,7 +139,8 @@ public class ManipulatorTest {
|
||||
|
||||
List<Manipulation> manipulations = new ArrayList<Manipulation>();
|
||||
manipulations.add(manipulation);
|
||||
new Manipulator(bus, dmm, manipulations);
|
||||
new Manipulator(bus, manipulations).onMessage(new DataMessage(dmm));;
|
||||
|
||||
// Expect IllegalArgument Exception as there is no mapping for the parameter c
|
||||
}
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@ import org.junit.Test;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import ch.psi.fda.core.messages.ComponentMetadata;
|
||||
import ch.psi.fda.core.messages.ControlMessage;
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.Message;
|
||||
import ch.psi.fda.core.messages.Metadata;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
@@ -63,30 +63,39 @@ public class DataDeserializerMDATest {
|
||||
@Test
|
||||
public void testRead() throws InterruptedException {
|
||||
|
||||
// Visualize metadata
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("[");
|
||||
StringBuilder b1 = new StringBuilder();
|
||||
b1.append("[");
|
||||
for(ComponentMetadata cm : deserializer.getMetadata().getComponents()){
|
||||
b.append(" ");
|
||||
b.append(cm.getId());
|
||||
b1.append(" ");
|
||||
b1.append(cm.getDimension());
|
||||
}
|
||||
b.append(" ]");
|
||||
b1.append(" ]");
|
||||
|
||||
logger.info("Metadata "+b.toString());
|
||||
logger.info("Metadata "+b1.toString());
|
||||
|
||||
|
||||
// Do "read" data
|
||||
bus.register(new Object(){
|
||||
boolean first = true;
|
||||
|
||||
@Subscribe
|
||||
public void onMessage(Message m){
|
||||
if(m instanceof DataMessage){
|
||||
DataMessage x = (DataMessage) m;
|
||||
|
||||
if(first){
|
||||
first=false;
|
||||
// Visualize metadata
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("[");
|
||||
StringBuilder b1 = new StringBuilder();
|
||||
b1.append("[");
|
||||
for(Metadata cm : x.getMetadata()){
|
||||
b.append(" ");
|
||||
b.append(cm.getId());
|
||||
b1.append(" ");
|
||||
b1.append(cm.getDimension());
|
||||
}
|
||||
b.append(" ]");
|
||||
b1.append(" ]");
|
||||
|
||||
logger.info("Metadata "+b.toString());
|
||||
logger.info("Metadata "+b1.toString());
|
||||
}
|
||||
|
||||
|
||||
logger.info( x.toString() );
|
||||
}
|
||||
else if(m instanceof ControlMessage){
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
package ch.psi.fda.serializer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -27,9 +29,8 @@ import org.junit.Test;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
||||
import ch.psi.fda.core.messages.ComponentMetadata;
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.DataMessageMetadata;
|
||||
import ch.psi.fda.core.messages.Metadata;
|
||||
import ch.psi.fda.core.messages.StreamDelimiterMessage;
|
||||
import ch.psi.fda.core.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.serializer.DataSerializer;
|
||||
@@ -44,7 +45,6 @@ public class DataSerializerTest {
|
||||
|
||||
private static final String tmpDirectory = "target/tmp";
|
||||
|
||||
private DataMessageMetadata metadata;
|
||||
private EventBus bus;
|
||||
|
||||
/**
|
||||
@@ -53,7 +53,6 @@ public class DataSerializerTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
new File(tmpDirectory).mkdirs();
|
||||
metadata = new DataMessageMetadata();
|
||||
bus = new EventBus();
|
||||
}
|
||||
|
||||
@@ -62,19 +61,19 @@ public class DataSerializerTest {
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
private void generate1DData() throws InterruptedException{
|
||||
|
||||
metadata.getComponents().add(new ComponentMetadata("id0", 0));
|
||||
metadata.getComponents().add(new ComponentMetadata("id1", 0));
|
||||
metadata.getComponents().add(new ComponentMetadata("id2", 0));
|
||||
List<Metadata> metadata = new ArrayList<>();
|
||||
metadata.add(new Metadata("id0", 0));
|
||||
metadata.add(new Metadata("id1", 0));
|
||||
metadata.add(new Metadata("id2", 0));
|
||||
|
||||
// Dimension
|
||||
DataMessage m = new DataMessage();
|
||||
DataMessage m = new DataMessage(metadata);
|
||||
m.getData().add(0.000000000000000001);
|
||||
m.getData().add(0.1);
|
||||
m.getData().add(1d); // have this value as double
|
||||
bus.post(m);
|
||||
|
||||
m = new DataMessage();
|
||||
m = new DataMessage(metadata);
|
||||
m.getData().add(0.02);
|
||||
m.getData().add(0.2);
|
||||
m.getData().add(2d); // have this value as double
|
||||
@@ -87,15 +86,15 @@ public class DataSerializerTest {
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
private void generate2DData() throws InterruptedException{
|
||||
|
||||
metadata.getComponents().add(new ComponentMetadata("id0", 1));
|
||||
metadata.getComponents().add(new ComponentMetadata("id1", 0));
|
||||
metadata.getComponents().add(new ComponentMetadata("id2", 0));
|
||||
List<Metadata> metadata = new ArrayList<>();
|
||||
metadata.add(new Metadata("id0", 1));
|
||||
metadata.add(new Metadata("id1", 0));
|
||||
metadata.add(new Metadata("id2", 0));
|
||||
|
||||
for(double i=0;i<5;i++){
|
||||
for(double t=0.1; t<10; t=t+0.1){
|
||||
// Dimension
|
||||
DataMessage m = new DataMessage();
|
||||
DataMessage m = new DataMessage(metadata);
|
||||
m.getData().add(i);
|
||||
m.getData().add(t);
|
||||
m.getData().add(Math.log(t)); // have this value as double
|
||||
@@ -114,17 +113,17 @@ public class DataSerializerTest {
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
private void generate3DData() throws InterruptedException{
|
||||
|
||||
metadata.getComponents().add(new ComponentMetadata("id0", 2));
|
||||
metadata.getComponents().add(new ComponentMetadata("id1", 1));
|
||||
metadata.getComponents().add(new ComponentMetadata("id2", 0));
|
||||
metadata.getComponents().add(new ComponentMetadata("id3", 0));
|
||||
List<Metadata> metadata = new ArrayList<>();
|
||||
metadata.add(new Metadata("id0", 2));
|
||||
metadata.add(new Metadata("id1", 1));
|
||||
metadata.add(new Metadata("id2", 0));
|
||||
metadata.add(new Metadata("id3", 0));
|
||||
|
||||
for(double z=30;z<36;z++){
|
||||
for(double i=0;i<6;i++){
|
||||
for(double t=0.1; t<1.1; t=t+0.1){
|
||||
// Dimension
|
||||
DataMessage m = new DataMessage();
|
||||
DataMessage m = new DataMessage(metadata);
|
||||
m.getData().add(z);
|
||||
m.getData().add(i);
|
||||
m.getData().add(t);
|
||||
@@ -153,7 +152,7 @@ public class DataSerializerTest {
|
||||
*/
|
||||
@Test
|
||||
public void testRunTXT() throws InterruptedException {
|
||||
DataSerializer serializer = new DataSerializerTXT(metadata, new File(tmpDirectory+"/test.txt"), true);
|
||||
DataSerializer serializer = new DataSerializerTXT(new File(tmpDirectory+"/test.txt"), true);
|
||||
bus.register(serializer);
|
||||
generate1DData();
|
||||
}
|
||||
@@ -165,7 +164,7 @@ public class DataSerializerTest {
|
||||
@Test
|
||||
public void testRunMAT() throws InterruptedException {
|
||||
|
||||
DataSerializer serializer = new DataSerializerMAT(metadata, new File(tmpDirectory+"/test.mat"));
|
||||
DataSerializer serializer = new DataSerializerMAT(new File(tmpDirectory+"/test.mat"));
|
||||
bus.register(serializer);
|
||||
generate1DData();
|
||||
}
|
||||
@@ -176,7 +175,7 @@ public class DataSerializerTest {
|
||||
*/
|
||||
@Test
|
||||
public void testRunMAT2D() throws InterruptedException {
|
||||
DataSerializer serializer = new DataSerializerMAT2D(metadata, new File(tmpDirectory+"/test-2d.mat"));
|
||||
DataSerializer serializer = new DataSerializerMAT2D(new File(tmpDirectory+"/test-2d.mat"));
|
||||
bus.register(serializer);
|
||||
generate2DData();
|
||||
}
|
||||
@@ -187,7 +186,7 @@ public class DataSerializerTest {
|
||||
*/
|
||||
@Test
|
||||
public void testRunTXT2D() throws InterruptedException {
|
||||
DataSerializer serializer = new DataSerializerTXT2D(metadata, new File(tmpDirectory+"/test-2d.txt"));
|
||||
DataSerializer serializer = new DataSerializerTXT2D(new File(tmpDirectory+"/test-2d.txt"));
|
||||
bus.register(serializer);
|
||||
generate2DData();
|
||||
}
|
||||
@@ -198,7 +197,7 @@ public class DataSerializerTest {
|
||||
*/
|
||||
@Test
|
||||
public void testRunSplitTXT() throws InterruptedException {
|
||||
DataSerializer serializer = new DataSerializerTXTSplit(metadata, new File(tmpDirectory+"/test-2d-split.txt"));
|
||||
DataSerializer serializer = new DataSerializerTXTSplit(new File(tmpDirectory+"/test-2d-split.txt"));
|
||||
bus.register(serializer);
|
||||
generate2DData();
|
||||
}
|
||||
@@ -209,7 +208,7 @@ public class DataSerializerTest {
|
||||
*/
|
||||
@Test
|
||||
public void testRun2D() throws InterruptedException {
|
||||
DataSerializer serializer = new DataSerializerMDA(metadata, new File(tmpDirectory+"/test-2d.mda"));
|
||||
DataSerializer serializer = new DataSerializerMDA(new File(tmpDirectory+"/test-2d.mda"));
|
||||
bus.register(serializer);
|
||||
generate2DData();
|
||||
}
|
||||
@@ -220,7 +219,7 @@ public class DataSerializerTest {
|
||||
*/
|
||||
@Test
|
||||
public void testRun3D() throws InterruptedException {
|
||||
DataSerializer serializer = new DataSerializerMDA(metadata, new File(tmpDirectory+"/test-3d.mda"));
|
||||
DataSerializer serializer = new DataSerializerMDA(new File(tmpDirectory+"/test-3d.mda"));
|
||||
bus.register(serializer);
|
||||
generate3DData();
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
*
|
||||
* Copyright 2010 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* This code is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful,
|
||||
* but without any warranty; without even the implied warranty of
|
||||
* merchantability or fitness for a particular purpose. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
* This code is distributed in the hope that it will be useful, but without any
|
||||
* warranty; without even the implied warranty of merchantability or fitness for
|
||||
* a particular purpose. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
@@ -21,8 +21,7 @@ package ch.psi.fda.visualizer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
@@ -32,272 +31,178 @@ import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import ch.psi.fda.core.messages.ComponentMetadata;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.DataMessageMetadata;
|
||||
import ch.psi.fda.core.messages.DataQueue;
|
||||
import ch.psi.fda.core.messages.Metadata;
|
||||
import ch.psi.fda.core.messages.StreamDelimiterMessage;
|
||||
import ch.psi.fda.core.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.core.messages.Message;
|
||||
import ch.psi.fda.model.v1.MatrixPlot;
|
||||
import ch.psi.fda.model.v1.PseudoPositioner;
|
||||
import ch.psi.fda.model.v1.Visualization;
|
||||
import ch.psi.fda.visualizer.Visualizer;
|
||||
import ch.psi.plot.xy.LinePlot;
|
||||
import ch.psi.plot.xyz.MatrixPlotData;
|
||||
|
||||
/**
|
||||
* All test cases in this test class are meant to be executed manually
|
||||
* Remove @Ignore in front of the test function to be able to run it.
|
||||
*
|
||||
* @author ebner
|
||||
*
|
||||
* All test cases in this test class are meant to be executed manually Remove @Ignore
|
||||
* in front of the test function to be able to run it.
|
||||
*/
|
||||
public class DataVisualizerTest {
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(DataVisualizerTest.class.getName());
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.visualizer.Visualizer#run()}.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Ignore
|
||||
@Test
|
||||
public void testRun() throws InterruptedException {
|
||||
final BlockingQueue<Message> q = new LinkedBlockingQueue<Message>();
|
||||
DataMessageMetadata dm = new DataMessageMetadata();
|
||||
dm.getComponents().add(new ComponentMetadata("id1", 0));
|
||||
dm.getComponents().add(new ComponentMetadata("id2", 0));
|
||||
dm.getComponents().add(new ComponentMetadata("id3", 0));
|
||||
DataQueue queue = new DataQueue(q,dm);
|
||||
List<Metadata> metadata = new ArrayList<>();
|
||||
metadata.add(new Metadata("id1"));
|
||||
metadata.add(new Metadata("id2"));
|
||||
metadata.add(new Metadata("id3"));
|
||||
|
||||
EventBus bus = new EventBus();
|
||||
|
||||
List<SeriesDataFilter> list = new ArrayList<>();
|
||||
list.add(new XYSeriesDataFilter("id1", "id2", new LinePlot("One")));
|
||||
list.add(new XYSeriesDataFilter("id1", "id3", new LinePlot("Two")));
|
||||
|
||||
// Create visualization
|
||||
List<Visualization> vlist = new ArrayList<Visualization>();
|
||||
ch.psi.fda.model.v1.LinePlot p = new ch.psi.fda.model.v1.LinePlot();
|
||||
p.setX("id1");
|
||||
p.getY().add("id2");
|
||||
vlist.add(p);
|
||||
p = new ch.psi.fda.model.v1.LinePlot();
|
||||
p.setX("id1");
|
||||
p.getY().add("id3");
|
||||
vlist.add(p);
|
||||
|
||||
// Create visualizer
|
||||
Visualizer visualizer = new Visualizer(queue.getDataMessageMetadata(), vlist);
|
||||
|
||||
Visualizer visualizer = new Visualizer(list);
|
||||
bus.register(visualizer);
|
||||
|
||||
JFrame f = new JFrame();
|
||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
f.setSize(600, 400);
|
||||
JPanel pan = new JPanel();
|
||||
for(JPanel pp: visualizer.getPlotPanels()){
|
||||
for (JPanel pp : visualizer.getPlotPanels()) {
|
||||
pan.add(pp);
|
||||
}
|
||||
f.add(pan);
|
||||
f.setVisible(true);
|
||||
|
||||
|
||||
// Thread creating data
|
||||
Thread t = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
DataMessage m;
|
||||
for(double t=0;t<4;t++){
|
||||
for(double i =0;i<100;i=i+0.1){
|
||||
m = new DataMessage();
|
||||
m.getData().add(i);
|
||||
m.getData().add(t+Math.sin(i));
|
||||
m.getData().add(t+Math.cos(i));
|
||||
q.add(m);
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Sleep interrupted",e);
|
||||
}
|
||||
}
|
||||
q.add(new StreamDelimiterMessage(0));
|
||||
}
|
||||
|
||||
q.add(new EndOfStreamMessage());
|
||||
|
||||
|
||||
DataMessage m;
|
||||
for (double t = 0; t < 4; t++) {
|
||||
for (double i = 0; i < 100; i = i + 0.1) {
|
||||
m = new DataMessage(metadata);
|
||||
m.getData().add(i);
|
||||
m.getData().add(t + Math.sin(i));
|
||||
m.getData().add(t + Math.cos(i));
|
||||
bus.post(m);
|
||||
|
||||
Thread.sleep(5);
|
||||
}
|
||||
});
|
||||
// Start data thread
|
||||
t.start();
|
||||
|
||||
|
||||
// visualizer.visualize();
|
||||
|
||||
t.join();
|
||||
|
||||
bus.post(new StreamDelimiterMessage(0));
|
||||
}
|
||||
|
||||
bus.post(new EndOfStreamMessage());
|
||||
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testRunArray() throws InterruptedException {
|
||||
final BlockingQueue<Message> q = new LinkedBlockingQueue<Message>();
|
||||
DataMessageMetadata dm = new DataMessageMetadata();
|
||||
dm.getComponents().add(new ComponentMetadata("id1", 0));
|
||||
DataQueue queue = new DataQueue(q,dm);
|
||||
|
||||
// Create visualization
|
||||
List<Visualization> vlist = new ArrayList<Visualization>();
|
||||
ch.psi.fda.model.v1.LinePlotArray p = new ch.psi.fda.model.v1.LinePlotArray();
|
||||
p.getY().add("id1");
|
||||
p.setMaxSeries(10);
|
||||
vlist.add(p);
|
||||
|
||||
List<Metadata> metadata = new ArrayList<>();
|
||||
metadata.add(new Metadata("id1"));
|
||||
|
||||
EventBus bus = new EventBus();
|
||||
|
||||
List<SeriesDataFilter> list = new ArrayList<>();
|
||||
list.add(new XYSeriesArrayDataFilter("id1", new LinePlot("One")));
|
||||
|
||||
// Create visualizer
|
||||
Visualizer visualizer = new Visualizer(queue.getDataMessageMetadata(), vlist);
|
||||
|
||||
Visualizer visualizer = new Visualizer(list);
|
||||
bus.register(visualizer);
|
||||
|
||||
JFrame f = new JFrame();
|
||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
f.setSize(600, 400);
|
||||
JPanel pan = new JPanel();
|
||||
for(JPanel pp: visualizer.getPlotPanels()){
|
||||
for (JPanel pp : visualizer.getPlotPanels()) {
|
||||
pan.add(pp);
|
||||
}
|
||||
f.add(pan);
|
||||
f.setVisible(true);
|
||||
|
||||
|
||||
// Thread creating data
|
||||
Thread t = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
DataMessage m;
|
||||
int npoints = 10000;
|
||||
for(double t=0;t<10;t++){
|
||||
double[] values = new double[npoints];
|
||||
|
||||
for(int i=0;i<npoints;i++){
|
||||
values[i]= Math.sin(i*0.01)+Math.cos(t);
|
||||
}
|
||||
|
||||
m = new DataMessage();
|
||||
m.getData().add(values);
|
||||
q.add(m);
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Sleep interrupted",e);
|
||||
}
|
||||
}
|
||||
q.add(new StreamDelimiterMessage(0));
|
||||
q.add(new EndOfStreamMessage());
|
||||
|
||||
|
||||
DataMessage m;
|
||||
int npoints = 10000;
|
||||
for (double t = 0; t < 10; t++) {
|
||||
double[] values = new double[npoints];
|
||||
|
||||
for (int i = 0; i < npoints; i++) {
|
||||
values[i] = Math.sin(i * 0.01) + Math.cos(t);
|
||||
}
|
||||
});
|
||||
// Start data thread
|
||||
t.start();
|
||||
|
||||
|
||||
// visualizer.visualize();
|
||||
|
||||
t.join();
|
||||
|
||||
|
||||
m = new DataMessage(metadata);
|
||||
m.getData().add(values);
|
||||
bus.post(m);
|
||||
|
||||
Thread.sleep(500);
|
||||
}
|
||||
bus.post(new StreamDelimiterMessage(0));
|
||||
bus.post(new EndOfStreamMessage());
|
||||
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.visualizer.Visualizer#run()}.
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testRun2D() throws InterruptedException {
|
||||
final BlockingQueue<Message> q = new LinkedBlockingQueue<Message>();
|
||||
DataMessageMetadata dm = new DataMessageMetadata();
|
||||
dm.getComponents().add(new ComponentMetadata("id1", 1));
|
||||
dm.getComponents().add(new ComponentMetadata("id2", 0));
|
||||
dm.getComponents().add(new ComponentMetadata("id3", 0));
|
||||
DataQueue queue = new DataQueue(q,dm);
|
||||
|
||||
List<Visualization> vlist = new ArrayList<Visualization>();
|
||||
ch.psi.fda.model.v1.LinePlot p = new ch.psi.fda.model.v1.LinePlot();
|
||||
p.setX("id2");
|
||||
p.getY().add("id3");
|
||||
vlist.add(p);
|
||||
|
||||
// 0d,4d,5,0d,100d,1001
|
||||
|
||||
PseudoPositioner pos = new PseudoPositioner();
|
||||
pos.setId("id1");
|
||||
pos.setCounts(5);
|
||||
|
||||
PseudoPositioner pos1 = new PseudoPositioner();
|
||||
pos1.setId("id2");
|
||||
pos1.setCounts(1000);
|
||||
|
||||
MatrixPlot mp = new MatrixPlot();
|
||||
mp.setX(pos);
|
||||
mp.setY(pos1);
|
||||
mp.setZ("id3");
|
||||
vlist.add(mp);
|
||||
|
||||
|
||||
int nx = 100;
|
||||
int ny = 1000;
|
||||
|
||||
List<Metadata> metadata = new ArrayList<>();
|
||||
metadata.add(new Metadata("id1"));
|
||||
metadata.add(new Metadata("id2"));
|
||||
metadata.add(new Metadata("id3"));
|
||||
|
||||
// EventBus bus = new AsyncEventBus(Executors.newFixedThreadPool(1));
|
||||
EventBus bus = new EventBus();
|
||||
|
||||
List<SeriesDataFilter> list = new ArrayList<>();
|
||||
list.add(new XYSeriesDataFilter("id2", "id3", new LinePlot("Line")));
|
||||
list.add(new XYZSeriesDataFilter("id1", "id2", "id3", new ch.psi.plot.xyz.MatrixPlot("Matrix", new MatrixPlotData(1, nx, nx, 1, ny, ny))));
|
||||
|
||||
// Create visualizer
|
||||
Visualizer visualizer = new Visualizer(queue.getDataMessageMetadata(), vlist);
|
||||
|
||||
Visualizer visualizer = new Visualizer(list);
|
||||
bus.register(visualizer);
|
||||
|
||||
JFrame f = new JFrame();
|
||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
f.setSize(600, 400);
|
||||
// f.add(plot.getPlotPanel());
|
||||
// f.add(plot.getPlotPanel());
|
||||
JPanel pan = new JPanel();
|
||||
for(JPanel pp: visualizer.getPlotPanels()){
|
||||
for (JPanel pp : visualizer.getPlotPanels()) {
|
||||
pan.add(pp);
|
||||
}
|
||||
f.add(pan);
|
||||
f.setVisible(true);
|
||||
|
||||
|
||||
// Thread creating data
|
||||
Thread t = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
DataMessage m;
|
||||
for(double t=1;t<=5;t++){
|
||||
for(double i=1;i<=1000;i++){
|
||||
m = new DataMessage();
|
||||
m.getData().add(t);
|
||||
m.getData().add(i);
|
||||
m.getData().add(t+Math.cos(i));
|
||||
q.add(m);
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Sleep interrupted",e);
|
||||
}
|
||||
}
|
||||
q.add(new StreamDelimiterMessage(0));
|
||||
}
|
||||
|
||||
q.add(new EndOfStreamMessage());
|
||||
|
||||
|
||||
DataMessage m;
|
||||
for (double t = 1; t <= nx; t++) {
|
||||
for (double i = 1; i <= ny; i++) {
|
||||
m = new DataMessage(metadata);
|
||||
m.getData().add(t);
|
||||
m.getData().add(i);
|
||||
m.getData().add(t + Math.cos(i));
|
||||
bus.post(m);
|
||||
|
||||
// Thread.sleep(5);
|
||||
}
|
||||
});
|
||||
// Start data thread
|
||||
t.start();
|
||||
|
||||
|
||||
// visualizer.visualize();
|
||||
|
||||
t.join();
|
||||
|
||||
Thread.sleep(10000);
|
||||
bus.post(new StreamDelimiterMessage(0));
|
||||
}
|
||||
|
||||
bus.post(new EndOfStreamMessage());
|
||||
|
||||
logger.info("Generation done");
|
||||
|
||||
Thread.sleep(100000);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user