Added heatmap
Former-commit-id: 65cd207c8664abe42926759c7003d95e7a39d293
This commit is contained in:
parent
9195e578d1
commit
6c5a5585c2
9 changed files with 157 additions and 36 deletions
|
|
@ -1,26 +0,0 @@
|
|||
package se.koc.hal;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.net.http.HttpHeaderParser;
|
||||
import zutil.net.http.HttpPage;
|
||||
import zutil.net.http.HttpPrintStream;
|
||||
import zutil.parser.Templator;
|
||||
|
||||
public class PCConfigureHttpPage implements HttpPage {
|
||||
|
||||
@Override
|
||||
public void respond(HttpPrintStream out, HttpHeaderParser client_info,
|
||||
Map<String, Object> session, Map<String, String> cookie,
|
||||
Map<String, String> request) throws IOException {
|
||||
|
||||
Templator tmpl = new Templator(FileUtil.find("web-resource/configure.html"));
|
||||
|
||||
out.print(tmpl.compile());
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -3,6 +3,9 @@ package se.koc.hal;
|
|||
|
||||
import se.koc.hal.deamon.DataAggregatorDaemon;
|
||||
import se.koc.hal.deamon.HalDaemon;
|
||||
import se.koc.hal.page.PCConfigureHttpPage;
|
||||
import se.koc.hal.page.PCHeatMapHttpPage;
|
||||
import se.koc.hal.page.PCOverviewHttpPage;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.CompactLogFormatter;
|
||||
|
|
@ -39,10 +42,11 @@ public class PowerChallenge {
|
|||
daemon.initiate(daemonTimer);
|
||||
}
|
||||
|
||||
HttpServer http = new HttpServer(8080);
|
||||
HttpServer http = new HttpServer(80);
|
||||
http.setDefaultPage(new HttpFilePage(FileUtil.find("web-resource/")));
|
||||
http.setPage("/", new PCOverviewHttpPage());
|
||||
http.setPage("/configure", new PCConfigureHttpPage());
|
||||
http.setPage("/heatmap", new PCHeatMapHttpPage());
|
||||
http.start();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
39
src/se/koc/hal/page/PCConfigureHttpPage.java
Normal file
39
src/se/koc/hal/page/PCConfigureHttpPage.java
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package se.koc.hal.page;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import se.koc.hal.PowerChallenge;
|
||||
import se.koc.hal.struct.Sensor;
|
||||
import se.koc.hal.struct.User;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.net.http.HttpHeaderParser;
|
||||
import zutil.net.http.HttpPage;
|
||||
import zutil.net.http.HttpPrintStream;
|
||||
import zutil.parser.Templator;
|
||||
|
||||
public class PCConfigureHttpPage implements HttpPage {
|
||||
|
||||
@Override
|
||||
public void respond(HttpPrintStream out, HttpHeaderParser client_info,
|
||||
Map<String, Object> session, Map<String, String> cookie,
|
||||
Map<String, String> request) throws IOException {
|
||||
|
||||
try {
|
||||
DBConnection db = PowerChallenge.db;
|
||||
|
||||
Templator tmpl = new Templator(FileUtil.find("web-resource/configure.html"));
|
||||
tmpl.set("user", User.getLocalUser(db));
|
||||
tmpl.set("localSensor", Sensor.getLocalSensors(db));
|
||||
tmpl.set("extUsers", User.getExternalUsers(db));
|
||||
tmpl.set("extSensor", Sensor.getExternalSensors(db));
|
||||
out.print(tmpl.compile());
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package se.koc.hal;
|
||||
package se.koc.hal.page;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.ResultSet;
|
||||
|
|
@ -7,6 +7,7 @@ import java.sql.Statement;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import se.koc.hal.PowerChallenge;
|
||||
import se.koc.hal.deamon.DataAggregatorDaemon;
|
||||
import zutil.db.SQLResultHandler;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
|
@ -1,11 +1,53 @@
|
|||
package se.koc.hal.struct;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.db.bean.DBBean;
|
||||
import zutil.db.bean.DBBeanSQLResultHandler;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-12-03.
|
||||
*/
|
||||
@DBBean.DBTable("sensor")
|
||||
public class Sensor extends DBBean{
|
||||
private String name;
|
||||
private int user_id;
|
||||
private String type;
|
||||
private String config;
|
||||
|
||||
|
||||
public static List<Sensor> getExternalSensors(DBConnection db) throws SQLException{
|
||||
PreparedStatement stmt = db.getPreparedStatement( "SELECT sensor.* FROM sensor,user WHERE user.external == 1 AND user.id == sensor.user_id" );
|
||||
return DBConnection.exec(stmt, DBBeanSQLResultHandler.createList(Sensor.class, db) );
|
||||
}
|
||||
|
||||
public static List<Sensor> getLocalSensors(DBConnection db) throws SQLException{
|
||||
PreparedStatement stmt = db.getPreparedStatement( "SELECT sensor.* FROM sensor,user WHERE user.external == 0 AND user.id == sensor.user_id" );
|
||||
return DBConnection.exec(stmt, DBBeanSQLResultHandler.createList(Sensor.class, db) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public int getUser_id() {
|
||||
return user_id;
|
||||
}
|
||||
public void setUser_id(int user_id) {
|
||||
this.user_id = user_id;
|
||||
}
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
package se.koc.hal.struct;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.db.bean.DBBean;
|
||||
import zutil.db.bean.DBBeanSQLResultHandler;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-12-03.
|
||||
|
|
@ -8,9 +14,58 @@ import zutil.db.bean.DBBean;
|
|||
@DBBean.DBTable("user")
|
||||
public class User extends DBBean{
|
||||
|
||||
private String name;
|
||||
private String username;
|
||||
private String address;
|
||||
private boolean external;
|
||||
private int external;
|
||||
|
||||
private String hostname;
|
||||
private int port;
|
||||
|
||||
|
||||
|
||||
public static List<User> getExternalUsers(DBConnection db) throws SQLException{
|
||||
PreparedStatement stmt = db.getPreparedStatement( "SELECT * FROM user WHERE user.external == 1" );
|
||||
return DBConnection.exec(stmt, DBBeanSQLResultHandler.createList(User.class, db) );
|
||||
}
|
||||
|
||||
public static User getLocalUser(DBConnection db) throws SQLException{
|
||||
PreparedStatement stmt = db.getPreparedStatement( "SELECT * FROM user WHERE user.external == 0" );
|
||||
return DBConnection.exec(stmt, DBBeanSQLResultHandler.create(User.class, db) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public String getName() {
|
||||
return username;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.username = name;
|
||||
}
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
public boolean isExternal() {
|
||||
return external > 0;
|
||||
}
|
||||
public void setExternal(boolean external) {
|
||||
this.external = (external? 1:0 );
|
||||
}
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
public void setHostname(String hostname) {
|
||||
this.hostname = hostname;
|
||||
}
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue