Added heatmap
Former-commit-id: 65cd207c8664abe42926759c7003d95e7a39d293
This commit is contained in:
parent
9195e578d1
commit
6c5a5585c2
9 changed files with 157 additions and 36 deletions
BIN
hal.db
BIN
hal.db
Binary file not shown.
|
|
@ -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.DataAggregatorDaemon;
|
||||||
import se.koc.hal.deamon.HalDaemon;
|
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.db.DBConnection;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
import zutil.log.CompactLogFormatter;
|
import zutil.log.CompactLogFormatter;
|
||||||
|
|
@ -39,10 +42,11 @@ public class PowerChallenge {
|
||||||
daemon.initiate(daemonTimer);
|
daemon.initiate(daemonTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpServer http = new HttpServer(8080);
|
HttpServer http = new HttpServer(80);
|
||||||
http.setDefaultPage(new HttpFilePage(FileUtil.find("web-resource/")));
|
http.setDefaultPage(new HttpFilePage(FileUtil.find("web-resource/")));
|
||||||
http.setPage("/", new PCOverviewHttpPage());
|
http.setPage("/", new PCOverviewHttpPage());
|
||||||
http.setPage("/configure", new PCConfigureHttpPage());
|
http.setPage("/configure", new PCConfigureHttpPage());
|
||||||
|
http.setPage("/heatmap", new PCHeatMapHttpPage());
|
||||||
http.start();
|
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.io.IOException;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
|
@ -7,6 +7,7 @@ import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import se.koc.hal.PowerChallenge;
|
||||||
import se.koc.hal.deamon.DataAggregatorDaemon;
|
import se.koc.hal.deamon.DataAggregatorDaemon;
|
||||||
import zutil.db.SQLResultHandler;
|
import zutil.db.SQLResultHandler;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
|
|
@ -1,11 +1,53 @@
|
||||||
package se.koc.hal.struct;
|
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.DBBean;
|
||||||
|
import zutil.db.bean.DBBeanSQLResultHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-12-03.
|
* Created by Ziver on 2015-12-03.
|
||||||
*/
|
*/
|
||||||
@DBBean.DBTable("sensor")
|
@DBBean.DBTable("sensor")
|
||||||
public class Sensor extends DBBean{
|
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;
|
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.DBBean;
|
||||||
|
import zutil.db.bean.DBBeanSQLResultHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-12-03.
|
* Created by Ziver on 2015-12-03.
|
||||||
|
|
@ -8,9 +14,58 @@ import zutil.db.bean.DBBean;
|
||||||
@DBBean.DBTable("user")
|
@DBBean.DBTable("user")
|
||||||
public class User extends DBBean{
|
public class User extends DBBean{
|
||||||
|
|
||||||
private String name;
|
private String username;
|
||||||
private String address;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@
|
||||||
<div class="col-sm-3 col-md-2 sidebar">
|
<div class="col-sm-3 col-md-2 sidebar">
|
||||||
<ul class="nav nav-sidebar">
|
<ul class="nav nav-sidebar">
|
||||||
<li><a href="/">Overview</a></li>
|
<li><a href="/">Overview</a></li>
|
||||||
<li><a href="#">Heat Map</a></li>
|
<li><a href="heatmap">Heat Map</a></li>
|
||||||
<li><a href="#">Statistics</a></li>
|
<li><a href="#">Statistics</a></li>
|
||||||
<li class="active"><a href="configure">Configuration <span class="sr-only">(current)</span></a></li>
|
<li class="active"><a href="configure">Configuration <span class="sr-only">(current)</span></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
@ -51,7 +51,11 @@
|
||||||
<form>
|
<form>
|
||||||
<div class="form-group col-md-4">
|
<div class="form-group col-md-4">
|
||||||
<label for="username">Username</label>
|
<label for="username">Username</label>
|
||||||
<input type="text" class="form-control" id="username" value="{{username}}">
|
<input type="text" class="form-control" id="username" value="{{user.username}}">
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-md-8">
|
||||||
|
<label for="address">Address</label>
|
||||||
|
<input type="text" class="form-control" id="username" value="{{user.address}}">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<button type="submit" class="btn btn-default">Save</button>
|
<button type="submit" class="btn btn-default">Save</button>
|
||||||
|
|
@ -89,13 +93,15 @@
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Username</th>
|
<th>Username</th>
|
||||||
|
<th>Address</th>
|
||||||
<th>Hostname</th>
|
<th>Hostname</th>
|
||||||
<th>Port</th>
|
<th>Port</th>
|
||||||
</tr>
|
</tr>
|
||||||
{{#extUsers}}
|
{{#extUsers}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{.username}}</td>
|
<td>{{.username}}</td>
|
||||||
<td>{{.host}}</td>
|
<td>{{.address}}</td>
|
||||||
|
<td>{{.hostname}}</td>
|
||||||
<td>{{.port}}</td>
|
<td>{{.port}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/extUsers}}
|
{{/extUsers}}
|
||||||
|
|
@ -113,13 +119,13 @@
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
<th>Configuration</th>
|
<th>Configuration</th>
|
||||||
</tr>
|
</tr>
|
||||||
{{#localSensor}}
|
{{#extSensor}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{.name}}</td>
|
<td>{{.name}}</td>
|
||||||
<td>{{.type}}</td>
|
<td>{{.type}}</td>
|
||||||
<td>{{.config}}</td>
|
<td>{{.config}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/localSensor}}
|
{{/extSensor}}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@
|
||||||
<div class="col-sm-3 col-md-2 sidebar">
|
<div class="col-sm-3 col-md-2 sidebar">
|
||||||
<ul class="nav nav-sidebar">
|
<ul class="nav nav-sidebar">
|
||||||
<li class="active"><a href="/">Overview <span class="sr-only">(current)</span></a></li>
|
<li class="active"><a href="/">Overview <span class="sr-only">(current)</span></a></li>
|
||||||
<li><a href="#">Heat Map</a></li>
|
<li><a href="heatmap">Heat Map</a></li>
|
||||||
<li><a href="#">Statistics</a></li>
|
<li><a href="#">Statistics</a></li>
|
||||||
<li><a href="configure">Configuration</a></li>
|
<li><a href="configure">Configuration</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue