我试图编写一个简单的Ecto查询,但我收到的错误是我没有完全理解。
基本上我尝试将两个ID相互匹配。这是我目前的尝试:
public class SerialTest extends JFrame implements SerialPortEventListener{
SerialPort serialPort;
Vector<String> header;
Vector<Vector<String>> dataList=new Vector<Vector<String>>();
Vector<String> lista=new Vector<String>();
DefaultTableModel tableMod;
private static final String PORT_NAMES[] = {
"/dev/tty.usbserial-A9007UX1", // Mac OS X
"/dev/ttyACM0", // Raspberry Pi
"/dev/ttyUSB0", // Linux
"COM8", // Windows
};
private BufferedReader input;
private OutputStream output;
private static final int TIME_OUT=200;
private static final int DATA_RATE=9600;
JButton btn=new JButton("Insert");
SerialTest(){
super("Serial Test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
header=new Vector<String>();
header.add("PWM");
header.add("Uin");
header.add("Uout");
btn.setSize(70, 50);
JPanel panelbtn=new JPanel();
panelbtn.add(btn);
tableMod=new DefaultTableModel();
JTable table=new JTable(tableMod);
tableMod.addColumn("PWM");
tableMod.addColumn("Uin");
tableMod.addColumn("Uout");
btn.setVisible(true);
btn.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
for(Vector<String> v: dataList){
tableMod.addRow(v);
}
}
});
JFrame frame=new JFrame();
frame.add(panelbtn);
table.setPreferredScrollableViewportSize(new Dimension(500,70));
JScrollPane scrollPane=new JScrollPane(table);
getContentPane().add(scrollPane,BorderLayout.CENTER);
getContentPane().add(panelbtn, BorderLayout.NORTH);
frame.setVisible(true);
}
public void initialize(){
//System.setProperty("gnu.io.rxtx.SerialPorts", "/dev/ttyACM0");
CommPortIdentifier portId=null;
Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
while(portEnum.hasMoreElements()){
CommPortIdentifier currPortId=(CommPortIdentifier)portEnum.nextElement();
for(String portName : PORT_NAMES){
if(currPortId.getName().equals(portName)){
portId=currPortId;
break;
}
}
}
if(portId==null){
System.out.println("Could non find COM port");
return;
}
try {
serialPort=(SerialPort)portId.open(this.getClass().getName(),TIME_OUT);
serialPort.setSerialPortParams(DATA_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
input=new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
output=serialPort.getOutputStream();
serialPort.addEventListener(this);
serialPort.notifyOnDataAvailable(true);
serialPort.disableReceiveTimeout();
serialPort.enableReceiveThreshold(1);
} catch (Exception e) {
System.err.println(e.toString());
}
}
public synchronized void close(){
if(serialPort != null){
serialPort.removeEventListener();
serialPort.close();
}
}
@Override
public void serialEvent(SerialPortEvent oEvent) {
if(oEvent.getEventType()==SerialPortEvent.DATA_AVAILABLE){
try{
String inputLine=input.readLine();
String[] rows=inputLine.split(",");
for(String row: rows){
row=row.trim();
lista.addAll(Arrays.asList(row.split("\n")));
dataList.add(lista);
}
System.out.println(dataList);
}catch(Exception e){
System.err.println(e.toString());
}return;
}
}
public static void main(String[] args) throws Exception {
SerialTest main=new SerialTest();
main.initialize();
main.setVisible(true);
Thread t=new Thread(){
public void run(){
try{Thread.sleep(100000);}catch(InterruptedException ie){}
}
};
t.start();
}
}
from(p in prediction_scores, where: p.league.id == ^league.id)
我有** (Ecto.Query.CompileError) `p.league().id()` is not a valid query expression
(ecto) expanding macro: Ecto.Query.where/3
属于PredictionScore
,然后我有一个传递单独的League
的函数。我的查询是尝试将prediction_score联盟ID与传入的联盟ID进行匹配。
希望这是足够的信息......如果您需要了解更多信息,请与我们联系。我很乐意更新。
答案 0 :(得分:1)
您需要明确地进行连接:
from p in prediction_scores,
join: l in assoc(p, :league),
where: l.id == ^league.id