KimchiSoup(junu)

Java-Cesco/Detecting_fraud_clicks#13 ui-create table

......@@ -31,6 +31,12 @@
<artifactId>spark-csv_2.11</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<build>
......
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.JSONArray;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;
import org.apache.spark.sql.expressions.Window;
import org.apache.spark.sql.expressions.WindowSpec;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.util.List;
import java.io.*;
import javax.swing.table.*;
import static org.apache.spark.sql.functions.*;
import static org.apache.spark.sql.functions.lit;
import static org.apache.spark.sql.functions.when;
public class Aggregation {
public static void main(String[] args) throws Exception {
new GUI();
//Create Session
SparkSession spark = SparkSession
......@@ -29,9 +39,13 @@ public class Aggregation {
dataset = agg.averageValidClickCount(dataset);
dataset = agg.clickTimeDelta(dataset);
dataset = agg.countClickInTenMinutes(dataset);
//test
dataset.where("ip == '5348' and app == '19'").show(10);
List<String> stringDataset = dataset.toJSON().collectAsList();
GUI gui = new GUI(stringDataset);
}
......
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import javax.swing.*;
import java.awt.*;
import java.io.BufferedReader;
import java.io.StringReader;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.List;
import java.util.Vector;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
public class GUI extends JFrame {
JTabbedPane tab = new JTabbedPane();
public GUI() {
public GUI(List<String> q) {
super("CESCO");
tab.addTab("png", new PngPane());
tab.addTab("gif",new GifPane());
tab.addTab("jpg",new JpgPane());
tab.addTab("gif", new GifPane());
tab.addTab("jpg", new JpgPane());
tab.addTab("table", new createTable(q));
add(tab);
......@@ -38,7 +70,7 @@ class GifPane extends JPanel {
ImageIcon image = new ImageIcon("data/model.gif");
JLabel label = new JLabel("", image, JLabel.CENTER);
setLayout(new BorderLayout());
add( label, BorderLayout.CENTER );
add(label, BorderLayout.CENTER);
}
}
......@@ -48,6 +80,60 @@ class JpgPane extends JPanel {
ImageIcon image = new ImageIcon("data/model.jpg");
JLabel label = new JLabel("", image, JLabel.CENTER);
setLayout(new BorderLayout());
add( label, BorderLayout.CENTER );
add(label, BorderLayout.CENTER);
}
}
class createTable extends JPanel {
public createTable(List<String> data) { //constructor : display table
getTableModel(data);
}
private DefaultTableModel getTableModel(List<String> data) {
String column_n[]={"ip","app","device","os","channel","is_attributed","click_time",
"avg_valid_click_count","click_time_delta","count_click_in_tenmin"};
Object tabledata[][]={};
DefaultTableModel model = new DefaultTableModel(tabledata,column_n);
JTable jtable = new JTable(model);
JScrollPane jScollPane = new JScrollPane(jtable);
add(jScollPane);
try {
for(int i =0; i<data.size();i++){
BufferedReader reader = getFileReader(data.get(i));
String line = reader.readLine();
line = line.replace("\"", "");
line = line.replace("_", "");
//line = line.replace("\\{","");
line = line.replaceAll("\\{|\\}","");
line = line.replaceAll("\\w+:", "");
//System.out.println(line);
Object [] temp= line.split(",");
model.addRow(temp);
reader.close();
}
} catch (Exception e) {
System.out.println(e);
}
return model;
}
private BufferedReader getFileReader(String data) {
BufferedReader reader = new BufferedReader(new StringReader(data));
// In your real application the data would come from a file
//Reader reader = new BufferedReader( new FileReader(...) );
return reader;
}
}
\ No newline at end of file
......
File mode changed
ionTreeRegressionModel (uid=dtr_4046612293fa) of depth 5 with 55 nodes
If (feature 2 <= 0.5)
If (feature 0 <= 195796.5)
If (feature 5 <= 3.5)
If (feature 3 <= 29.5)
If (feature 0 <= 65878.0)
Predict: 0.12087912087912088
Else (feature 0 > 65878.0)
Predict: 0.0547945205479452
Else (feature 3 > 29.5)
If (feature 0 <= 175794.5)
Predict: 0.0
Else (feature 0 > 175794.5)
Predict: 0.3333333333333333
Else (feature 5 > 3.5)
If (feature 1 <= 19.5)
Predict: 1.0
Else (feature 1 > 19.5)
Predict: 0.0
Else (feature 0 > 195796.5)
If (feature 1 <= 19.5)
If (feature 0 <= 212250.0)
If (feature 3 <= 3.5)
Predict: 0.6666666666666666
Else (feature 3 > 3.5)
Predict: 0.0
Else (feature 0 > 212250.0)
If (feature 3 <= 3.5)
Predict: 0.15384615384615385
Else (feature 3 > 3.5)
Predict: 0.3181818181818182
Else (feature 1 > 19.5)
If (feature 3 <= 47.5)
Predict: 0.0
Else (feature 3 > 47.5)
If (feature 5 <= 0.5)
Predict: 0.5
Else (feature 5 > 0.5)
Predict: 0.0
Else (feature 2 > 0.5)
If (feature 1 <= 28.5)
If (feature 2 <= 3.5)
If (feature 0 <= 212250.0)
If (feature 0 <= 118331.5)
Predict: 2.176407740097345E-4
Else (feature 0 > 118331.5)
Predict: 8.741258741258741E-4
Else (feature 0 > 212250.0)
If (feature 4 <= 115.5)
Predict: 0.04215456674473068
Else (feature 4 > 115.5)
Predict: 0.0016492578339747114
Else (feature 2 > 3.5)
If (feature 1 <= 18.5)
Predict: 0.0
Else (feature 1 > 18.5)
If (feature 0 <= 123267.0)
Predict: 0.14285714285714285
Else (feature 0 > 123267.0)
Predict: 0.3611111111111111
Else (feature 1 > 28.5)
If (feature 4 <= 279.0)
If (feature 0 <= 175794.5)
If (feature 4 <= 265.5)
Predict: 0.06231454005934718
Else (feature 4 > 265.5)
Predict: 0.6666666666666666
Else (feature 0 > 175794.5)
If (feature 4 <= 228.0)
Predict: 0.36923076923076925
Else (feature 4 > 228.0)
Predict: 1.0
Else (feature 4 > 279.0)
If (feature 4 <= 333.5)
If (feature 1 <= 30.5)
Predict: 0.5
Else (feature 1 > 30.5)
Predict: 0.0
Else (feature 4 > 333.5)
If (feature 3 <= 8.5)
Predict: 0.0234375
Else (feature 3 > 8.5)
Predict: 0.002178649237472767