basic plotting working
Former-commit-id: 338d5cedbd9c87c7e0e78beb41c3c86bc6395dfa
This commit is contained in:
parent
4a60f18489
commit
b88f260ebc
23 changed files with 12229 additions and 19 deletions
|
|
@ -40,7 +40,8 @@ public class PowerChallenge {
|
|||
}
|
||||
|
||||
HttpServer http = new HttpServer(8080);
|
||||
http.setDefaultPage(new HttpFilePage(FileUtil.find("resource/")));
|
||||
http.setDefaultPage(new HttpFilePage(FileUtil.find("web-resource/")));
|
||||
http.setPage("/", new PowerChallengeHttpPage());
|
||||
http.start();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,15 @@
|
|||
package se.koc.hal;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import se.koc.hal.deamon.DataAggregatorDaemon;
|
||||
import zutil.db.SQLResultHandler;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.net.http.HttpHeaderParser;
|
||||
import zutil.net.http.HttpPage;
|
||||
import zutil.net.http.HttpPrintStream;
|
||||
|
|
@ -11,13 +18,54 @@ import zutil.parser.Templator;
|
|||
public class PowerChallengeHttpPage 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 {
|
||||
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("resource/index.tmpl");
|
||||
try {
|
||||
ArrayList<PowerData> minDataList = PowerChallenge.db.exec(
|
||||
"SELECT * FROM sensor_data_aggr "
|
||||
+ "WHERE sensor_id == 1 AND timestamp_end-timestamp_start == " + (DataAggregatorDaemon.FIVE_MINUTES_IN_MS-1),
|
||||
new SQLPowerDataBuilder());
|
||||
ArrayList<PowerData> hourDataList = PowerChallenge.db.exec(
|
||||
"SELECT * FROM sensor_data_aggr "
|
||||
+ "WHERE sensor_id == 1 AND timestamp_end-timestamp_start == " + (DataAggregatorDaemon.HOUR_IN_MS-1),
|
||||
new SQLPowerDataBuilder());
|
||||
ArrayList<PowerData> dayDataList = PowerChallenge.db.exec(
|
||||
"SELECT * FROM sensor_data_aggr "
|
||||
+ "WHERE sensor_id == 1 AND timestamp_end-timestamp_start == " + (DataAggregatorDaemon.DAY_IN_MS-1),
|
||||
new SQLPowerDataBuilder());
|
||||
|
||||
out.print(tmpl.compile());
|
||||
|
||||
Templator tmpl = new Templator(FileUtil.find("web-resource/index.html"));
|
||||
tmpl.set("minData", minDataList);
|
||||
tmpl.set("hourData", hourDataList);
|
||||
tmpl.set("dayData", dayDataList);
|
||||
tmpl.set("username", "Ziver");
|
||||
|
||||
out.print(tmpl.compile());
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class PowerData{
|
||||
long timestamp;
|
||||
int data;
|
||||
public PowerData(long time, int data) {
|
||||
this.timestamp = time;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SQLPowerDataBuilder implements SQLResultHandler<ArrayList<PowerData>> {
|
||||
@Override
|
||||
public ArrayList<PowerData> handleQueryResult(Statement stmt, ResultSet result) throws SQLException {
|
||||
ArrayList<PowerData> list = new ArrayList<>();
|
||||
while(result.next()){
|
||||
list.add(new PowerData(result.getLong("timestamp_start"), result.getInt("data")));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,12 +20,12 @@ import zutil.log.LogUtil;
|
|||
*/
|
||||
public class DataAggregatorDaemon extends TimerTask implements HalDaemon {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
private static final long FIVE_MINUTES_IN_MS = 5 * 60 * 1000;
|
||||
private static final long HOUR_IN_MS = FIVE_MINUTES_IN_MS * 12;
|
||||
private static final long DAY_IN_MS = HOUR_IN_MS * 24;
|
||||
public static final long FIVE_MINUTES_IN_MS = 5 * 60 * 1000;
|
||||
public static final long HOUR_IN_MS = FIVE_MINUTES_IN_MS * 12;
|
||||
public static final long DAY_IN_MS = HOUR_IN_MS * 24;
|
||||
|
||||
private static final long HOUR_AGGREGATION_OFFSET = DAY_IN_MS;
|
||||
private static final long DAY_AGGREGATION_OFFSET = DAY_IN_MS * 30 * 6; // ~6 months
|
||||
private static final long DAY_AGGREGATION_OFFSET = DAY_IN_MS * 3;
|
||||
|
||||
|
||||
public void initiate(Timer timer){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue