Statistics
| Revision:

root / hci / trunk / EneraptorSim2 / EneraptorSim.java @ 70

History | View | Annotate | Download (1013 Bytes)

1
import java.sql.*;
2

    
3
public class EneraptorSim {
4

    
5
        public static void main(String[] args) throws Exception {
6

    
7
                Class.forName("org.postgresql.Driver");
8

    
9
                Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost/eneraptor", "eneraptor-hci", "eneraptor-hci");
10

    
11
                // CONFIGURE
12
                
13
                double val = 24;
14
                String deviceId = "thermometer";
15
                
16
                while(true) {
17
                
18
                        java.util.Date now = new java.util.Date();
19
                        double a = Math.random();
20
                        if(a < 0.05)
21
                                val += 0.1;
22
                        else if(a > 0.95)
23
                                val -= 0.1;
24
                        
25
                        Statement st = conn.createStatement();
26
                        String stm = "INSERT INTO logged_data(id, \"version\", date_recieved, device_id, reported_data) VALUES (nextval('hibernate_sequence'), 0, '" + now + "', '" + deviceId + "', '" + val + "');";
27
                        st.execute(stm);
28
                        System.out.println("Inserted " + val);
29
                        st.close();
30
                        
31
                        try {
32
                                Thread.currentThread().sleep(1000);
33
                        }
34
                        catch (InterruptedException e) {
35
                                e.printStackTrace();
36
                        }
37
                        
38
                }
39
        
40
        }
41
        
42
}