Showing
5 changed files
with
199 additions
and
10 deletions
| ... | @@ -31,6 +31,12 @@ | ... | @@ -31,6 +31,12 @@ |
| 31 | <artifactId>spark-csv_2.11</artifactId> | 31 | <artifactId>spark-csv_2.11</artifactId> |
| 32 | <version>1.5.0</version> | 32 | <version>1.5.0</version> |
| 33 | </dependency> | 33 | </dependency> |
| 34 | + <dependency> | ||
| 35 | + <groupId>com.googlecode.json-simple</groupId> | ||
| 36 | + <artifactId>json-simple</artifactId> | ||
| 37 | + <version>1.1</version> | ||
| 38 | + </dependency> | ||
| 39 | + | ||
| 34 | </dependencies> | 40 | </dependencies> |
| 35 | 41 | ||
| 36 | <build> | 42 | <build> | ... | ... |
| 1 | +import org.json.simple.JSONObject; | ||
| 2 | +import org.json.simple.parser.JSONParser; | ||
| 3 | +import org.json.simple.JSONArray; | ||
| 4 | + | ||
| 1 | import org.apache.spark.sql.Dataset; | 5 | import org.apache.spark.sql.Dataset; |
| 2 | import org.apache.spark.sql.Row; | 6 | import org.apache.spark.sql.Row; |
| 3 | import org.apache.spark.sql.SparkSession; | 7 | import org.apache.spark.sql.SparkSession; |
| 4 | import org.apache.spark.sql.expressions.Window; | 8 | import org.apache.spark.sql.expressions.Window; |
| 5 | import org.apache.spark.sql.expressions.WindowSpec; | 9 | import org.apache.spark.sql.expressions.WindowSpec; |
| 6 | 10 | ||
| 11 | + | ||
| 12 | +import javax.swing.*; | ||
| 13 | +import javax.swing.table.DefaultTableModel; | ||
| 14 | +import java.util.List; | ||
| 15 | +import java.io.*; | ||
| 16 | +import javax.swing.table.*; | ||
| 17 | + | ||
| 18 | + | ||
| 7 | import static org.apache.spark.sql.functions.*; | 19 | import static org.apache.spark.sql.functions.*; |
| 8 | -import static org.apache.spark.sql.functions.lit; | ||
| 9 | -import static org.apache.spark.sql.functions.when; | ||
| 10 | 20 | ||
| 11 | public class Aggregation { | 21 | public class Aggregation { |
| 12 | 22 | ||
| 13 | public static void main(String[] args) throws Exception { | 23 | public static void main(String[] args) throws Exception { |
| 14 | 24 | ||
| 15 | - new GUI(); | 25 | + |
| 16 | 26 | ||
| 17 | //Create Session | 27 | //Create Session |
| 18 | SparkSession spark = SparkSession | 28 | SparkSession spark = SparkSession |
| ... | @@ -30,8 +40,12 @@ public class Aggregation { | ... | @@ -30,8 +40,12 @@ public class Aggregation { |
| 30 | dataset = agg.clickTimeDelta(dataset); | 40 | dataset = agg.clickTimeDelta(dataset); |
| 31 | dataset = agg.countClickInTenMinutes(dataset); | 41 | dataset = agg.countClickInTenMinutes(dataset); |
| 32 | 42 | ||
| 33 | - //test | 43 | + List<String> stringDataset = dataset.toJSON().collectAsList(); |
| 34 | - dataset.where("ip == '5348' and app == '19'").show(10); | 44 | + GUI gui = new GUI(stringDataset); |
| 45 | + | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + | ||
| 35 | } | 49 | } |
| 36 | 50 | ||
| 37 | 51 | ... | ... |
| 1 | +import org.apache.spark.sql.Dataset; | ||
| 2 | +import org.apache.spark.sql.Row; | ||
| 3 | + | ||
| 1 | import javax.swing.*; | 4 | import javax.swing.*; |
| 2 | import java.awt.*; | 5 | import java.awt.*; |
| 6 | +import java.io.BufferedReader; | ||
| 7 | +import java.io.StringReader; | ||
| 8 | +import java.sql.ResultSet; | ||
| 9 | +import java.sql.ResultSetMetaData; | ||
| 10 | +import java.sql.Statement; | ||
| 11 | +import java.util.List; | ||
| 12 | +import java.util.Vector; | ||
| 13 | +import java.awt.BorderLayout; | ||
| 14 | +import java.awt.GridLayout; | ||
| 15 | +import java.awt.event.ActionEvent; | ||
| 16 | +import java.awt.event.ActionListener; | ||
| 17 | +import java.sql.Connection; | ||
| 18 | +import java.sql.DriverManager; | ||
| 19 | +import java.sql.ResultSet; | ||
| 20 | +import java.sql.ResultSetMetaData; | ||
| 21 | +import java.sql.Statement; | ||
| 22 | +import java.util.Vector; | ||
| 23 | + | ||
| 24 | +import javax.swing.JButton; | ||
| 25 | +import javax.swing.JFrame; | ||
| 26 | +import javax.swing.JLabel; | ||
| 27 | +import javax.swing.JPanel; | ||
| 28 | +import javax.swing.JScrollPane; | ||
| 29 | +import javax.swing.JTable; | ||
| 30 | +import javax.swing.JTextField; | ||
| 31 | +import javax.swing.table.AbstractTableModel; | ||
| 32 | +import javax.swing.table.DefaultTableModel; | ||
| 3 | 33 | ||
| 4 | public class GUI extends JFrame { | 34 | public class GUI extends JFrame { |
| 5 | JTabbedPane tab = new JTabbedPane(); | 35 | JTabbedPane tab = new JTabbedPane(); |
| 6 | - public GUI() { | 36 | + |
| 37 | + public GUI(List<String> q) { | ||
| 7 | super("CESCO"); | 38 | super("CESCO"); |
| 8 | 39 | ||
| 9 | tab.addTab("png", new PngPane()); | 40 | tab.addTab("png", new PngPane()); |
| 10 | - tab.addTab("gif",new GifPane()); | 41 | + tab.addTab("gif", new GifPane()); |
| 11 | - tab.addTab("jpg",new JpgPane()); | 42 | + tab.addTab("jpg", new JpgPane()); |
| 43 | + tab.addTab("table", new createTable(q)); | ||
| 12 | 44 | ||
| 13 | add(tab); | 45 | add(tab); |
| 14 | 46 | ||
| ... | @@ -38,7 +70,7 @@ class GifPane extends JPanel { | ... | @@ -38,7 +70,7 @@ class GifPane extends JPanel { |
| 38 | ImageIcon image = new ImageIcon("data/model.gif"); | 70 | ImageIcon image = new ImageIcon("data/model.gif"); |
| 39 | JLabel label = new JLabel("", image, JLabel.CENTER); | 71 | JLabel label = new JLabel("", image, JLabel.CENTER); |
| 40 | setLayout(new BorderLayout()); | 72 | setLayout(new BorderLayout()); |
| 41 | - add( label, BorderLayout.CENTER ); | 73 | + add(label, BorderLayout.CENTER); |
| 42 | } | 74 | } |
| 43 | } | 75 | } |
| 44 | 76 | ||
| ... | @@ -48,6 +80,60 @@ class JpgPane extends JPanel { | ... | @@ -48,6 +80,60 @@ class JpgPane extends JPanel { |
| 48 | ImageIcon image = new ImageIcon("data/model.jpg"); | 80 | ImageIcon image = new ImageIcon("data/model.jpg"); |
| 49 | JLabel label = new JLabel("", image, JLabel.CENTER); | 81 | JLabel label = new JLabel("", image, JLabel.CENTER); |
| 50 | setLayout(new BorderLayout()); | 82 | setLayout(new BorderLayout()); |
| 51 | - add( label, BorderLayout.CENTER ); | 83 | + add(label, BorderLayout.CENTER); |
| 84 | + } | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +class createTable extends JPanel { | ||
| 88 | + | ||
| 89 | + public createTable(List<String> data) { //constructor : display table | ||
| 90 | + getTableModel(data); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + private DefaultTableModel getTableModel(List<String> data) { | ||
| 94 | + String column_n[]={"ip","app","device","os","channel","is_attributed","click_time", | ||
| 95 | + "avg_valid_click_count","click_time_delta","count_click_in_tenmin"}; | ||
| 96 | + Object tabledata[][]={}; | ||
| 97 | + DefaultTableModel model = new DefaultTableModel(tabledata,column_n); | ||
| 98 | + JTable jtable = new JTable(model); | ||
| 99 | + JScrollPane jScollPane = new JScrollPane(jtable); | ||
| 100 | + add(jScollPane); | ||
| 101 | + try { | ||
| 102 | + for(int i =0; i<data.size();i++){ | ||
| 103 | + BufferedReader reader = getFileReader(data.get(i)); | ||
| 104 | + String line = reader.readLine(); | ||
| 105 | + | ||
| 106 | + | ||
| 107 | + line = line.replace("\"", ""); | ||
| 108 | + line = line.replace("_", ""); | ||
| 109 | + //line = line.replace("\\{",""); | ||
| 110 | + line = line.replaceAll("\\{|\\}",""); | ||
| 111 | + line = line.replaceAll("\\w+:", ""); | ||
| 112 | + | ||
| 113 | + //System.out.println(line); | ||
| 114 | + Object [] temp= line.split(","); | ||
| 115 | + | ||
| 116 | + model.addRow(temp); | ||
| 117 | + | ||
| 118 | + reader.close(); | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + } catch (Exception e) { | ||
| 122 | + System.out.println(e); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + | ||
| 126 | + return model; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + private BufferedReader getFileReader(String data) { | ||
| 130 | + | ||
| 131 | + BufferedReader reader = new BufferedReader(new StringReader(data)); | ||
| 132 | + | ||
| 133 | + // In your real application the data would come from a file | ||
| 134 | + | ||
| 135 | + //Reader reader = new BufferedReader( new FileReader(...) ); | ||
| 136 | + | ||
| 137 | + return reader; | ||
| 52 | } | 138 | } |
| 53 | } | 139 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
tree.py
0 → 100644
File mode changed
tree.txt
0 → 100644
| 1 | +ionTreeRegressionModel (uid=dtr_4046612293fa) of depth 5 with 55 nodes | ||
| 2 | + If (feature 2 <= 0.5) | ||
| 3 | + If (feature 0 <= 195796.5) | ||
| 4 | + If (feature 5 <= 3.5) | ||
| 5 | + If (feature 3 <= 29.5) | ||
| 6 | + If (feature 0 <= 65878.0) | ||
| 7 | + Predict: 0.12087912087912088 | ||
| 8 | + Else (feature 0 > 65878.0) | ||
| 9 | + Predict: 0.0547945205479452 | ||
| 10 | + Else (feature 3 > 29.5) | ||
| 11 | + If (feature 0 <= 175794.5) | ||
| 12 | + Predict: 0.0 | ||
| 13 | + Else (feature 0 > 175794.5) | ||
| 14 | + Predict: 0.3333333333333333 | ||
| 15 | + Else (feature 5 > 3.5) | ||
| 16 | + If (feature 1 <= 19.5) | ||
| 17 | + Predict: 1.0 | ||
| 18 | + Else (feature 1 > 19.5) | ||
| 19 | + Predict: 0.0 | ||
| 20 | + Else (feature 0 > 195796.5) | ||
| 21 | + If (feature 1 <= 19.5) | ||
| 22 | + If (feature 0 <= 212250.0) | ||
| 23 | + If (feature 3 <= 3.5) | ||
| 24 | + Predict: 0.6666666666666666 | ||
| 25 | + Else (feature 3 > 3.5) | ||
| 26 | + Predict: 0.0 | ||
| 27 | + Else (feature 0 > 212250.0) | ||
| 28 | + If (feature 3 <= 3.5) | ||
| 29 | + Predict: 0.15384615384615385 | ||
| 30 | + Else (feature 3 > 3.5) | ||
| 31 | + Predict: 0.3181818181818182 | ||
| 32 | + Else (feature 1 > 19.5) | ||
| 33 | + If (feature 3 <= 47.5) | ||
| 34 | + Predict: 0.0 | ||
| 35 | + Else (feature 3 > 47.5) | ||
| 36 | + If (feature 5 <= 0.5) | ||
| 37 | + Predict: 0.5 | ||
| 38 | + Else (feature 5 > 0.5) | ||
| 39 | + Predict: 0.0 | ||
| 40 | + Else (feature 2 > 0.5) | ||
| 41 | + If (feature 1 <= 28.5) | ||
| 42 | + If (feature 2 <= 3.5) | ||
| 43 | + If (feature 0 <= 212250.0) | ||
| 44 | + If (feature 0 <= 118331.5) | ||
| 45 | + Predict: 2.176407740097345E-4 | ||
| 46 | + Else (feature 0 > 118331.5) | ||
| 47 | + Predict: 8.741258741258741E-4 | ||
| 48 | + Else (feature 0 > 212250.0) | ||
| 49 | + If (feature 4 <= 115.5) | ||
| 50 | + Predict: 0.04215456674473068 | ||
| 51 | + Else (feature 4 > 115.5) | ||
| 52 | + Predict: 0.0016492578339747114 | ||
| 53 | + Else (feature 2 > 3.5) | ||
| 54 | + If (feature 1 <= 18.5) | ||
| 55 | + Predict: 0.0 | ||
| 56 | + Else (feature 1 > 18.5) | ||
| 57 | + If (feature 0 <= 123267.0) | ||
| 58 | + Predict: 0.14285714285714285 | ||
| 59 | + Else (feature 0 > 123267.0) | ||
| 60 | + Predict: 0.3611111111111111 | ||
| 61 | + Else (feature 1 > 28.5) | ||
| 62 | + If (feature 4 <= 279.0) | ||
| 63 | + If (feature 0 <= 175794.5) | ||
| 64 | + If (feature 4 <= 265.5) | ||
| 65 | + Predict: 0.06231454005934718 | ||
| 66 | + Else (feature 4 > 265.5) | ||
| 67 | + Predict: 0.6666666666666666 | ||
| 68 | + Else (feature 0 > 175794.5) | ||
| 69 | + If (feature 4 <= 228.0) | ||
| 70 | + Predict: 0.36923076923076925 | ||
| 71 | + Else (feature 4 > 228.0) | ||
| 72 | + Predict: 1.0 | ||
| 73 | + Else (feature 4 > 279.0) | ||
| 74 | + If (feature 4 <= 333.5) | ||
| 75 | + If (feature 1 <= 30.5) | ||
| 76 | + Predict: 0.5 | ||
| 77 | + Else (feature 1 > 30.5) | ||
| 78 | + Predict: 0.0 | ||
| 79 | + Else (feature 4 > 333.5) | ||
| 80 | + If (feature 3 <= 8.5) | ||
| 81 | + Predict: 0.0234375 | ||
| 82 | + Else (feature 3 > 8.5) | ||
| 83 | + Predict: 0.002178649237472767 |
-
Please register or login to post a comment