Revision 63
hci/trunk/eneraptor-web-app/web-app/css/style.css | ||
---|---|---|
413 | 413 |
|
414 | 414 |
.statistics-main{background:transparent url(../img/icons/eye.png) no-repeat left;} |
415 | 415 |
.statistics-graphs{background:transparent url(../img/icons/chart_curve.png) no-repeat left;} |
416 |
.statistics-newGraph{background:transparent url(../img/icons/chart_curve_add.png) no-repeat left;} |
|
416 |
.statistics-newGraph{background:transparent url(../img/icons/chart_curve_single_add.png) no-repeat left;} |
|
417 |
.statistics-newCombGraph{background:transparent url(../img/icons/chart_curve_add.png) no-repeat left;} |
|
417 | 418 |
.statistics-newReport{background:transparent url(../img/icons/report.png) no-repeat left;} |
418 | 419 |
|
419 | 420 |
.actions-main{background:transparent url(../img/icons/eye.png) no-repeat left;} |
hci/trunk/eneraptor-web-app/grails-app/views/statistics/showCombGraph.gsp | ||
---|---|---|
1 |
<html> |
|
2 |
|
|
3 |
<head> |
|
4 |
<title>Statistics » Graph view</title> |
|
5 |
<meta name="layout" content="main" /> |
|
6 |
<flot:resources /> |
|
7 |
</head> |
|
8 |
|
|
9 |
<body> |
|
10 |
|
|
11 |
<erptr:box title="Graph"> |
|
12 |
<g:javascript> |
|
13 |
var data = ${data}; |
|
14 |
var options = { |
|
15 |
lines: { show: true }, |
|
16 |
points: { show: true }, |
|
17 |
xaxis: { mode: "time", timeformat: "%y/%m/%d %H:%M" } |
|
18 |
}; |
|
19 |
</g:javascript> |
|
20 |
<div class="chart"> |
|
21 |
<flot:plot id="placeholder" style="width: 900px; height: 300px; padding:5px;" data="data" options="options" /> |
|
22 |
</div> |
|
23 |
</erptr:box> |
|
24 |
|
|
25 |
</body> |
|
26 |
|
|
27 |
</html> |
hci/trunk/eneraptor-web-app/grails-app/views/statistics/graphs.gsp | ||
---|---|---|
9 | 9 |
|
10 | 10 |
<erptr:box title="Saved graphs"> |
11 | 11 |
|
12 |
<p>Single device graphs:</p> |
|
13 |
|
|
12 | 14 |
<table> |
13 | 15 |
<thead> |
14 | 16 |
<tr> |
... | ... | |
21 | 23 |
<tbody> |
22 | 24 |
<g:each in="${savedGraphs}" var="savedGraph"> |
23 | 25 |
<tr> |
24 |
<td><p><erptr:icon w="chart_curve" /><g:link action="showGraph" id="${savedGraph.id}" >${savedGraph.name}</g:link></p></td> |
|
26 |
<td><p><erptr:icon w="chart_curve_single" /><g:link action="showGraph" id="${savedGraph.id}" >${savedGraph.name}</g:link></p></td>
|
|
25 | 27 |
<td><p>${savedGraph.deviceId}</p></td> |
26 | 28 |
<td><p>${savedGraph.type}</p></td> |
27 | 29 |
<td><p> |
28 |
<g:link action="showGraph" id="${savedGraph.id}" title="View graph only" ><erptr:icon w="chart_line" /></g:link>
|
|
30 |
<g:link action="showGraph" id="${savedGraph.id}" title="View graph only" ><erptr:icon w="magnifier" /></g:link>
|
|
29 | 31 |
<g:link action="makeReport" id="${savedGraph.id}" title="Make report" ><erptr:icon w="report" /></g:link> |
30 | 32 |
<g:link action="editGraph" id="${savedGraph.id}" title="Edit" ><erptr:icon w="pencil" /></g:link> |
31 | 33 |
<g:link action="deleteGraph" id="${savedGraph.id}" title="Delete" ><erptr:icon w="delete" /></g:link> |
... | ... | |
37 | 39 |
<g:if test="${savedGraphs.size == 0}"> |
38 | 40 |
<center><p><i>There are no saved graphs.</i></p></center> |
39 | 41 |
</g:if> |
42 |
|
|
43 |
<p>Combined graphs:</p> |
|
44 |
|
|
45 |
<table> |
|
46 |
<thead> |
|
47 |
<tr> |
|
48 |
<th><p>Graph name (short description)</p></th> |
|
49 |
<th style="width:78px;"><p>Options</p></th> |
|
50 |
</tr> |
|
51 |
</thead> |
|
52 |
<tbody> |
|
53 |
<g:each in="${combinedGraphs}" var="combGraph"> |
|
54 |
<tr> |
|
55 |
<td><p><erptr:icon w="chart_curve" /><g:link action="showCombGraph" id="${combGraph.id}" >${combGraph.name}</g:link></p></td> |
|
56 |
<td><p> |
|
57 |
<g:link action="showCombGraph" id="${combGraph.id}" title="View graph only" ><erptr:icon w="magnifier" /></g:link> |
|
58 |
<a><erptr:icon w="blank" /></a> |
|
59 |
<g:link action="editCombGraph" id="${combGraph.id}" title="Edit" ><erptr:icon w="pencil" /></g:link> |
|
60 |
<g:link action="deleteCombGraph" id="${combGraph.id}" title="Delete" ><erptr:icon w="delete" /></g:link> |
|
61 |
</p></td> |
|
62 |
</tr> |
|
63 |
</g:each> |
|
64 |
</tbody> |
|
65 |
</table> |
|
66 |
<g:if test="${combinedGraphs.size == 0}"> |
|
67 |
<center><p><i>There are no saved graphs.</i></p></center> |
|
68 |
</g:if> |
|
40 | 69 |
|
41 | 70 |
</erptr:box> |
42 | 71 |
|
43 |
<erptr:box title="Create a new graph"> |
|
72 |
<erptr:box title="Create a new single device graph">
|
|
44 | 73 |
<p>To create a new graph, select one of the graph types below:</p> |
45 | 74 |
<table style="text-align:center;border:none;"> |
46 | 75 |
<tr> |
... | ... | |
57 | 86 |
</tr> |
58 | 87 |
</table> |
59 | 88 |
</erptr:box> |
89 |
|
|
90 |
<erptr:box title="Create a new combined graph"> |
|
91 |
<p>Combined graph is simply a set of single device graphs displayed as a single one.</p> |
|
92 |
<p><g:link action="newCombGraph"><erptr:icon w="chart_curve_add" />Create a new combined graph</g:link></p> |
|
93 |
</erptr:box> |
|
60 | 94 |
|
61 | 95 |
</body> |
62 | 96 |
|
hci/trunk/eneraptor-web-app/grails-app/views/statistics/editCombGraph.gsp | ||
---|---|---|
1 |
<html> |
|
2 |
|
|
3 |
<head> |
|
4 |
<title>Statistics</title> |
|
5 |
<meta name="layout" content="main" /> |
|
6 |
</head> |
|
7 |
|
|
8 |
<body> |
|
9 |
|
|
10 |
<erptr:box title="Edit combined graph"> |
|
11 |
|
|
12 |
<g:form method="POST" name="editCombGraphForm" action="editCombGraphDo"> |
|
13 |
|
|
14 |
<fieldset> |
|
15 |
<legend>Basic info</legend> |
|
16 |
<label for="editCombGraphName">Name (short description)</label> |
|
17 |
<g:textField name="editCombGraphName" style="width:600px" value="${chosenGraph.name}" /> |
|
18 |
<br /> |
|
19 |
</fieldset> |
|
20 |
|
|
21 |
<fieldset> |
|
22 |
<legend>Graphs</legend> |
|
23 |
<p>Select which single device graphs to combine</p> |
|
24 |
<p>Select by clicking on the grpah's name while holding CTRL key on your keyboard.</p> |
|
25 |
<br /> |
|
26 |
<select multiple="multiple" name="graphsToCombine" id="graphsToCombine" size="10" style="width:820px;"> |
|
27 |
<g:each in="${graphs}" var="graph"> |
|
28 |
<g:if test="${graph.sl}"> |
|
29 |
<option value="${graph.gr.id}" selected="selected">(${graph.gr.type}) ${graph.gr.name}</option> |
|
30 |
</g:if> |
|
31 |
<g:else> |
|
32 |
<option value="${graph.gr.id}">(${graph.gr.type}) ${graph.gr.name}</option> |
|
33 |
</g:else> |
|
34 |
</g:each> |
|
35 |
</select> |
|
36 |
<br /><br /> |
|
37 |
</fieldset> |
|
38 |
|
|
39 |
<g:hiddenField name="graphId" value="${chosenGraph.id}" /> |
|
40 |
|
|
41 |
<g:submitButton name="editCombGraphSubmit" value="Save changes" /> |
|
42 |
|
|
43 |
</g:form> |
|
44 |
|
|
45 |
</erptr:box> |
|
46 |
|
|
47 |
</body> |
|
48 |
|
|
49 |
</html> |
hci/trunk/eneraptor-web-app/grails-app/views/statistics/newCombGraph.gsp | ||
---|---|---|
1 |
<html> |
|
2 |
|
|
3 |
<head> |
|
4 |
<title>Statistics</title> |
|
5 |
<meta name="layout" content="main" /> |
|
6 |
</head> |
|
7 |
|
|
8 |
<body> |
|
9 |
|
|
10 |
<erptr:box title="New combined graph"> |
|
11 |
|
|
12 |
<form name="newCombGraphForm" action="newCombGraphDo"> |
|
13 |
|
|
14 |
<fieldset> |
|
15 |
<legend>Basic info</legend> |
|
16 |
<label for="newCombGraphName">Name (short description)</label> |
|
17 |
<g:textField name="newCombGraphName" style="width:600px" /> |
|
18 |
<br /> |
|
19 |
</fieldset> |
|
20 |
|
|
21 |
<fieldset> |
|
22 |
<legend>Graphs</legend> |
|
23 |
<p>Select which single device graphs to combine</p> |
|
24 |
<p>Select by clicking on the grpah's name while holding CTRL key on your keyboard.</p> |
|
25 |
<br /> |
|
26 |
<select multiple="multiple" name="graphsToCombine" id="graphsToCombine" size="10" style="width:820px;"> |
|
27 |
<g:each in="${graphs}" var="graph"> |
|
28 |
<option value="${graph.id}">(${graph.type}) ${graph.name}</option> |
|
29 |
</g:each> |
|
30 |
</select> |
|
31 |
<br /><br /> |
|
32 |
</fieldset> |
|
33 |
|
|
34 |
<g:submitButton name="newCombGraphSubmit" value="Create new graph" /> |
|
35 |
|
|
36 |
</form> |
|
37 |
|
|
38 |
</erptr:box> |
|
39 |
|
|
40 |
</body> |
|
41 |
|
|
42 |
</html> |
hci/trunk/eneraptor-web-app/grails-app/services/com/eneraptor/hci/GraphDataService.groovy | ||
---|---|---|
1 |
package com.eneraptor.hci |
|
2 |
|
|
3 |
import groovy.sql.Sql |
|
4 |
|
|
5 |
class GraphDataService { |
|
6 |
|
|
7 |
static transactional = true |
|
8 |
|
|
9 |
def dataSource |
|
10 |
|
|
11 |
List getGraphData(EneGraph gr) { |
|
12 |
|
|
13 |
EneGraph graphToShow = gr |
|
14 |
String query |
|
15 |
|
|
16 |
List data = new ArrayList() |
|
17 |
def results |
|
18 |
def db_sql = new Sql(dataSource) |
|
19 |
|
|
20 |
if(graphToShow.timeFrameType == "day") { |
|
21 |
db_sql.eachRow "select date_trunc('day',ld.date_recieved) dt, " + graphToShow['type'] + "(to_number(ld.reported_data,'9999999999D99999')) vl from logged_data as ld where (device_id = '" + graphToShow['deviceId'] + "' and date_trunc('day',ld.date_recieved) >= '" + graphToShow.timeFrameStart + "' and date_trunc('day',ld.date_recieved) <= '" + graphToShow.timeFrameEnd + "' and date_part('hour',ld.date_recieved) >= " + graphToShow.advHoursTimeFrameStart + " and date_part('hour',ld.date_recieved) <= " + graphToShow.advHoursTimeFrameEnd + " and date_part('day',ld.date_recieved) >= " + graphToShow.advDayTimeFrameStart + " and date_part('day',ld.date_recieved) <= " + graphToShow.advDayTimeFrameEnd + " and date_part('month',ld.date_recieved) >= " + graphToShow.advMonthTimeFrameStart + " and date_part('month',ld.date_recieved) <= " + graphToShow.advMonthTimeFrameEnd + ") group by date_trunc('day',ld.date_recieved) order by date_trunc('day',ld.date_recieved) asc", { |
|
22 |
data << [it.dt.getTime(), it.vl] |
|
23 |
} |
|
24 |
} else if (graphToShow.timeFrameType == "month") { |
|
25 |
db_sql.eachRow "select date_trunc('month',ld.date_recieved) dt, " + graphToShow['type'] + "(to_number(ld.reported_data,'9999999999D99999')) vl from logged_data as ld where (device_id = '" + graphToShow['deviceId'] + "' and date_trunc('month',ld.date_recieved) >= '" + graphToShow.timeFrameStart + "' and date_trunc('month',ld.date_recieved) <= '" + graphToShow.timeFrameEnd + "' and date_part('hour',ld.date_recieved) >= " + graphToShow.advHoursTimeFrameStart + " and date_part('hour',ld.date_recieved) <= " + graphToShow.advHoursTimeFrameEnd + " and date_part('day',ld.date_recieved) >= " + graphToShow.advDayTimeFrameStart + " and date_part('day',ld.date_recieved) <= " + graphToShow.advDayTimeFrameEnd + " and date_part('month',ld.date_recieved) >= " + graphToShow.advMonthTimeFrameStart + " and date_part('month',ld.date_recieved) <= " + graphToShow.advMonthTimeFrameEnd + ") group by date_trunc('month',ld.date_recieved) order by date_trunc('month',ld.date_recieved) asc", { |
|
26 |
data << [it.dt.getTime(), it.vl] |
|
27 |
} |
|
28 |
} else if (graphToShow.timeFrameType == "year") { |
|
29 |
db_sql.eachRow "select date_trunc('year',ld.date_recieved) dt, " + graphToShow['type'] + "(to_number(ld.reported_data,'9999999999D99999')) vl from logged_data as ld where (device_id = '" + graphToShow['deviceId'] + "' and date_trunc('year',ld.date_recieved) >= '" + graphToShow.timeFrameStart + "' and date_trunc('year',ld.date_recieved) <= '" + graphToShow.timeFrameEnd + "' and date_part('hour',ld.date_recieved) >= " + graphToShow.advHoursTimeFrameStart + " and date_part('hour',ld.date_recieved) <= " + graphToShow.advHoursTimeFrameEnd + " and date_part('day',ld.date_recieved) >= " + graphToShow.advDayTimeFrameStart + " and date_part('day',ld.date_recieved) <= " + graphToShow.advDayTimeFrameEnd + " and date_part('month',ld.date_recieved) >= " + graphToShow.advMonthTimeFrameStart + " and date_part('month',ld.date_recieved) <= " + graphToShow.advMonthTimeFrameEnd + ") group by date_trunc('year',ld.date_recieved) order by date_trunc('year',ld.date_recieved) asc", { |
|
30 |
data << [it.dt.getTime(), it.vl] |
|
31 |
} |
|
32 |
} else if (graphToShow.timeFrameType == "custom") { |
|
33 |
def innerTimeFrame = (long)((graphToShow.timeFrameEnd.getTime() - graphToShow.timeFrameStart.getTime()) / graphToShow.innerSections) |
|
34 |
query = "" |
|
35 |
for(int i = 0; i < graphToShow.innerSections;i++) { |
|
36 |
def currDateMillis = graphToShow.timeFrameStart.getTime() + (i*innerTimeFrame) + innerTimeFrame/2 |
|
37 |
def currDate = new Date((long)currDateMillis) |
|
38 |
def currDateStartMillis = graphToShow.timeFrameStart.getTime() + (i*innerTimeFrame) |
|
39 |
def currDateStart = new Date((long)currDateStartMillis) |
|
40 |
def currDateStopMillis = graphToShow.timeFrameStart.getTime() + ((i+1)*innerTimeFrame) |
|
41 |
def currDateStop = new Date((long)currDateStopMillis) |
|
42 |
query += "(select timestamp without time zone '" + currDate.toTimestamp() + "' dt, " + graphToShow['type'] + "(to_number(ld.reported_data,'9999999999D99999')) vl from logged_data as ld where (device_id = '" + graphToShow['deviceId'] + "' and ld.date_recieved >= '" + currDateStart.toTimestamp() + "' and ld.date_recieved <= '" + currDateStop.toTimestamp() + "' and date_part('hour',ld.date_recieved) >= " + graphToShow.advHoursTimeFrameStart + " and date_part('hour',ld.date_recieved) <= " + graphToShow.advHoursTimeFrameEnd + " and date_part('day',ld.date_recieved) >= " + graphToShow.advDayTimeFrameStart + " and date_part('day',ld.date_recieved) <= " + graphToShow.advDayTimeFrameEnd + " and date_part('month',ld.date_recieved) >= " + graphToShow.advMonthTimeFrameStart + " and date_part('month',ld.date_recieved) <= " + graphToShow.advMonthTimeFrameEnd + ")) " |
|
43 |
if (i < (graphToShow.innerSections-1) ) query += "union " |
|
44 |
} |
|
45 |
query += "order by dt asc" |
|
46 |
db_sql.eachRow(query) { |
|
47 |
data << [it.dt.getTime(), it.vl] |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
return data |
|
52 |
|
|
53 |
} |
|
54 |
|
|
55 |
} |
hci/trunk/eneraptor-web-app/grails-app/services/com/eneraptor/hci/HciLogicCommService.groovy | ||
---|---|---|
24 | 24 |
reply['status'] = "error" |
25 | 25 |
reply['content'] = "Unknown host: " |
26 | 26 |
reply['content'] += e.getMessage() |
27 |
fromLogic?.close() |
|
28 |
toLogic?.close() |
|
29 |
logicSocket?.close() |
|
27 | 30 |
return reply |
28 | 31 |
} catch (IOException e) { |
29 | 32 |
reply['status'] = "error" |
30 | 33 |
reply['content'] += e.getMessage() |
34 |
fromLogic?.close() |
|
35 |
toLogic?.close() |
|
36 |
logicSocket?.close() |
|
31 | 37 |
return reply |
32 | 38 |
} |
33 | 39 |
|
... | ... | |
40 | 46 |
reply['content'] += it.toString() + "\n" |
41 | 47 |
} |
42 | 48 |
|
49 |
fromLogic.close() |
|
50 |
toLogic.close() |
|
51 |
logicSocket.close() |
|
52 |
|
|
43 | 53 |
return reply |
44 | 54 |
|
45 | 55 |
} |
hci/trunk/eneraptor-web-app/grails-app/services/com/eneraptor/hci/MainMenuService.groovy | ||
---|---|---|
44 | 44 |
statisticsSubMenu = new ArrayList() |
45 | 45 |
statisticsSubMenu.add(new MenuItem("Overview","statistics","main")) |
46 | 46 |
statisticsSubMenu.add(new MenuItem("Saved graphs","statistics","graphs")) |
47 |
statisticsSubMenu.add(new MenuItem("Create a new graph","statistics","newGraph")) |
|
47 |
statisticsSubMenu.add(new MenuItem("Create a new single device graph","statistics","newGraph")) |
|
48 |
statisticsSubMenu.add(new MenuItem("Create a new combined graph","statistics","newCombGraph")) |
|
48 | 49 |
statisticsSubMenu.add(new MenuItem("Make reports","statistics","newReport")) |
49 | 50 |
|
50 | 51 |
actionsSubMenu = new ArrayList() |
hci/trunk/eneraptor-web-app/grails-app/controllers/com/eneraptor/hci/StatisticsController.groovy | ||
---|---|---|
6 | 6 |
class StatisticsController { |
7 | 7 |
|
8 | 8 |
def dataSource |
9 |
|
|
10 |
def graphDataService |
|
9 | 11 |
|
10 | 12 |
def main = { } |
11 | 13 |
|
12 | 14 |
def graphs = { |
13 | 15 |
|
14 | 16 |
List savedGraphs = new ArrayList() |
17 |
List combinedGraphs = new ArrayList() |
|
15 | 18 |
|
16 | 19 |
savedGraphs = EneGraph.list() |
20 |
combinedGraphs = CombGraph.list() |
|
17 | 21 |
|
18 |
[savedGraphs: savedGraphs] |
|
22 |
[savedGraphs: savedGraphs, combinedGraphs:combinedGraphs]
|
|
19 | 23 |
|
20 | 24 |
} |
21 | 25 |
|
... | ... | |
98 | 102 |
String query |
99 | 103 |
|
100 | 104 |
List data = new ArrayList() |
101 |
def results |
|
102 |
def db_sql = new Sql(dataSource) |
|
105 |
data = graphDataService.getGraphData(graphToShow) |
|
103 | 106 |
|
104 |
if(graphToShow.timeFrameType == "day") { |
|
105 |
db_sql.eachRow "select date_trunc('day',ld.date_recieved) dt, " + graphToShow['type'] + "(to_number(ld.reported_data,'9999999999D99999')) vl from logged_data as ld where (device_id = '" + graphToShow['deviceId'] + "' and date_trunc('day',ld.date_recieved) >= '" + graphToShow.timeFrameStart + "' and date_trunc('day',ld.date_recieved) <= '" + graphToShow.timeFrameEnd + "' and date_part('hour',ld.date_recieved) >= " + graphToShow.advHoursTimeFrameStart + " and date_part('hour',ld.date_recieved) <= " + graphToShow.advHoursTimeFrameEnd + " and date_part('day',ld.date_recieved) >= " + graphToShow.advDayTimeFrameStart + " and date_part('day',ld.date_recieved) <= " + graphToShow.advDayTimeFrameEnd + " and date_part('month',ld.date_recieved) >= " + graphToShow.advMonthTimeFrameStart + " and date_part('month',ld.date_recieved) <= " + graphToShow.advMonthTimeFrameEnd + ") group by date_trunc('day',ld.date_recieved) order by date_trunc('day',ld.date_recieved) asc", { |
|
106 |
data << [it.dt.getTime(), it.vl] |
|
107 |
} |
|
108 |
} else if (graphToShow.timeFrameType == "month") { |
|
109 |
db_sql.eachRow "select date_trunc('month',ld.date_recieved) dt, " + graphToShow['type'] + "(to_number(ld.reported_data,'9999999999D99999')) vl from logged_data as ld where (device_id = '" + graphToShow['deviceId'] + "' and date_trunc('month',ld.date_recieved) >= '" + graphToShow.timeFrameStart + "' and date_trunc('month',ld.date_recieved) <= '" + graphToShow.timeFrameEnd + "' and date_part('hour',ld.date_recieved) >= " + graphToShow.advHoursTimeFrameStart + " and date_part('hour',ld.date_recieved) <= " + graphToShow.advHoursTimeFrameEnd + " and date_part('day',ld.date_recieved) >= " + graphToShow.advDayTimeFrameStart + " and date_part('day',ld.date_recieved) <= " + graphToShow.advDayTimeFrameEnd + " and date_part('month',ld.date_recieved) >= " + graphToShow.advMonthTimeFrameStart + " and date_part('month',ld.date_recieved) <= " + graphToShow.advMonthTimeFrameEnd + ") group by date_trunc('month',ld.date_recieved) order by date_trunc('month',ld.date_recieved) asc", { |
|
110 |
data << [it.dt.getTime(), it.vl] |
|
111 |
} |
|
112 |
} else if (graphToShow.timeFrameType == "year") { |
|
113 |
db_sql.eachRow "select date_trunc('year',ld.date_recieved) dt, " + graphToShow['type'] + "(to_number(ld.reported_data,'9999999999D99999')) vl from logged_data as ld where (device_id = '" + graphToShow['deviceId'] + "' and date_trunc('year',ld.date_recieved) >= '" + graphToShow.timeFrameStart + "' and date_trunc('year',ld.date_recieved) <= '" + graphToShow.timeFrameEnd + "' and date_part('hour',ld.date_recieved) >= " + graphToShow.advHoursTimeFrameStart + " and date_part('hour',ld.date_recieved) <= " + graphToShow.advHoursTimeFrameEnd + " and date_part('day',ld.date_recieved) >= " + graphToShow.advDayTimeFrameStart + " and date_part('day',ld.date_recieved) <= " + graphToShow.advDayTimeFrameEnd + " and date_part('month',ld.date_recieved) >= " + graphToShow.advMonthTimeFrameStart + " and date_part('month',ld.date_recieved) <= " + graphToShow.advMonthTimeFrameEnd + ") group by date_trunc('year',ld.date_recieved) order by date_trunc('year',ld.date_recieved) asc", { |
|
114 |
data << [it.dt.getTime(), it.vl] |
|
115 |
} |
|
116 |
} else if (graphToShow.timeFrameType == "custom") { |
|
117 |
def innerTimeFrame = (long)((graphToShow.timeFrameEnd.getTime() - graphToShow.timeFrameStart.getTime()) / graphToShow.innerSections) |
|
118 |
query = "" |
|
119 |
for(int i = 0; i < graphToShow.innerSections;i++) { |
|
120 |
def currDateMillis = graphToShow.timeFrameStart.getTime() + (i*innerTimeFrame) + innerTimeFrame/2 |
|
121 |
def currDate = new Date((long)currDateMillis) |
|
122 |
def currDateStartMillis = graphToShow.timeFrameStart.getTime() + (i*innerTimeFrame) |
|
123 |
def currDateStart = new Date((long)currDateStartMillis) |
|
124 |
def currDateStopMillis = graphToShow.timeFrameStart.getTime() + ((i+1)*innerTimeFrame) |
|
125 |
def currDateStop = new Date((long)currDateStopMillis) |
|
126 |
query += "(select timestamp without time zone '" + currDate.toTimestamp() + "' dt, " + graphToShow['type'] + "(to_number(ld.reported_data,'9999999999D99999')) vl from logged_data as ld where (device_id = '" + graphToShow['deviceId'] + "' and ld.date_recieved >= '" + currDateStart.toTimestamp() + "' and ld.date_recieved <= '" + currDateStop.toTimestamp() + "' and date_part('hour',ld.date_recieved) >= " + graphToShow.advHoursTimeFrameStart + " and date_part('hour',ld.date_recieved) <= " + graphToShow.advHoursTimeFrameEnd + " and date_part('day',ld.date_recieved) >= " + graphToShow.advDayTimeFrameStart + " and date_part('day',ld.date_recieved) <= " + graphToShow.advDayTimeFrameEnd + " and date_part('month',ld.date_recieved) >= " + graphToShow.advMonthTimeFrameStart + " and date_part('month',ld.date_recieved) <= " + graphToShow.advMonthTimeFrameEnd + ")) " |
|
127 |
if (i < (graphToShow.innerSections-1) ) query += "union " |
|
128 |
} |
|
129 |
query += "order by dt asc" |
|
130 |
db_sql.eachRow(query) { |
|
131 |
data << [it.dt.getTime(), it.vl] |
|
132 |
} |
|
133 |
} |
|
134 |
|
|
135 | 107 |
[data:data] |
136 | 108 |
|
137 | 109 |
} |
... | ... | |
178 | 150 |
if(!graphToEdit.validate()) { |
179 | 151 |
errors += "<p>Graph could not be modified - there were some input errors. Please check if all input values are valid.</p>" |
180 | 152 |
flash['errors'] = errors |
181 |
redirect(action:'editGraph') |
|
153 |
redirect(action:'editGraph',params: [id: params.graphId])
|
|
182 | 154 |
} else { |
183 | 155 |
if(graphToEdit.save()){ |
184 | 156 |
flash['confirms'] = "<p>Graph modified succesfully!</p>" |
185 | 157 |
redirect(action:'graphs') |
186 | 158 |
} else { |
187 | 159 |
flash['errors'] = "<p>There was an error while modifying graph.</p>" |
188 |
redirect(action:'editGraph') |
|
160 |
redirect(action:'editGraph',params: [id: params.graphId])
|
|
189 | 161 |
} |
190 | 162 |
} |
191 | 163 |
|
... | ... | |
448 | 420 |
def graphToDelete = EneGraph.get(params['id']) |
449 | 421 |
if(graphToDelete) { |
450 | 422 |
|
423 |
if(graphToDelete.delete()) { |
|
424 |
flash['confirms'] = "<p>Graph deleted successfully.</p>" |
|
425 |
redirect(action:'graphs') |
|
426 |
return true |
|
427 |
} else { |
|
428 |
flash['errors'] = "<p>Cannot remove this graph. This graph is part of a <b>combined</b> graph.</p><p>You should remove the <b>combined</b> graph first.</p>" |
|
429 |
redirect(action:'graphs') |
|
430 |
return false |
|
431 |
} |
|
432 |
|
|
433 |
} else { |
|
434 |
flash['errors'] = "<p>No graph was deleted. Graph ID invalid!</p>" |
|
435 |
redirect(action:'graphs') |
|
436 |
return false |
|
437 |
} |
|
438 |
|
|
439 |
} else { |
|
440 |
|
|
441 |
flash['errors'] = "<p>No graph was deleted. Graph ID not specified!</p>" |
|
442 |
redirect(action:'graphs') |
|
443 |
return false |
|
444 |
|
|
445 |
} |
|
446 |
|
|
447 |
} |
|
448 |
|
|
449 |
def newCombGraph = { |
|
450 |
|
|
451 |
def graphs = EneGraph.list() |
|
452 |
|
|
453 |
[graphs:graphs] |
|
454 |
|
|
455 |
} |
|
456 |
|
|
457 |
def newCombGraphDo = { |
|
458 |
|
|
459 |
List selgrph = new ArrayList() |
|
460 |
selgrph = params.list('graphsToCombine') |
|
461 |
|
|
462 |
if(selgrph.size() < 2) { |
|
463 |
flash.errors = "<p>You have to select at least 2 single device graphs to combine!</p>" |
|
464 |
redirect(action:'newCombGraph') |
|
465 |
return false |
|
466 |
} |
|
467 |
|
|
468 |
CombGraph newOne = new CombGraph( |
|
469 |
name: params.newCombGraphName |
|
470 |
) |
|
471 |
|
|
472 |
selgrph.each { |
|
473 |
newOne.addToGraphs(EneGraph.get(it)) |
|
474 |
} |
|
475 |
|
|
476 |
if(newOne.validate()) { |
|
477 |
newOne.save() |
|
478 |
flash.confirms = "<p>New combined graph added succesfully!</p>" |
|
479 |
redirect(action:'graphs') |
|
480 |
return true |
|
481 |
} else { |
|
482 |
flash.errors = "<p>New graph could not be created. Check if all fields are filled and if values are valid.</p>" |
|
483 |
redirect(action:'newCombGraph') |
|
484 |
return false |
|
485 |
} |
|
486 |
|
|
487 |
} |
|
488 |
|
|
489 |
def deleteCombGraph = { |
|
490 |
|
|
491 |
if(params['id']) { |
|
492 |
|
|
493 |
def graphToDelete = CombGraph.get(params['id']) |
|
494 |
if(graphToDelete) { |
|
495 |
|
|
451 | 496 |
graphToDelete.delete() |
452 | 497 |
flash['confirms'] = "<p>Graph deleted successfully.</p>" |
453 | 498 |
redirect(action:'graphs') |
... | ... | |
465 | 510 |
redirect(action:'graphs') |
466 | 511 |
return false |
467 | 512 |
|
468 |
}
|
|
513 |
} |
|
469 | 514 |
|
470 | 515 |
} |
516 |
|
|
517 |
def editCombGraph = { |
|
518 |
|
|
519 |
CombGraph chosenGraph = CombGraph.get(params['id']) |
|
520 |
List allGraphs = new ArrayList() |
|
521 |
EneGraph.list().each { |
|
522 |
if(chosenGraph.graphs.contains(it)) { |
|
523 |
allGraphs << [gr: it, sl: true] |
|
524 |
} else { |
|
525 |
allGraphs << [gr: it, sl: false] |
|
526 |
} |
|
527 |
} |
|
528 |
|
|
529 |
[chosenGraph: chosenGraph, graphs: allGraphs] |
|
530 |
|
|
531 |
} |
|
532 |
|
|
533 |
def editCombGraphDo = { |
|
534 |
|
|
535 |
CombGraph chosenGraph = CombGraph.get(params['graphId']) |
|
536 |
|
|
537 |
chosenGraph.name = params['editCombGraphName'] |
|
538 |
List newGraphs = new ArrayList() |
|
539 |
newGraphs = params.list('graphsToCombine') |
|
540 |
|
|
541 |
if(newGraphs.size() < 2) { |
|
542 |
flash.errors = "<p>You have to select at least 2 single device graphs to combine!</p>" |
|
543 |
redirect(action:'editCombGraph',params:[id: params.graphId]) |
|
544 |
return false |
|
545 |
} |
|
546 |
|
|
547 |
List graphsToRemove = new ArrayList() |
|
548 |
|
|
549 |
chosenGraph.graphs.each { |
|
550 |
graphsToRemove << it |
|
551 |
} |
|
552 |
|
|
553 |
graphsToRemove.each { |
|
554 |
chosenGraph.removeFromGraphs(it) |
|
555 |
} |
|
556 |
|
|
557 |
newGraphs.each { |
|
558 |
chosenGraph.addToGraphs(EneGraph.get(it)) |
|
559 |
} |
|
560 |
|
|
561 |
if(chosenGraph.validate()) { |
|
562 |
if(chosenGraph.save(flush:true)) { |
|
563 |
flash.confirms = "<p>Graph edited succesfully!</p>" |
|
564 |
redirect(action:'graphs') |
|
565 |
return true |
|
566 |
} else { |
|
567 |
flash.errors = "<p>Graph could not be edited. Check if all fields are filled and if values are valid.</p>" |
|
568 |
redirect(action:'editCombGraph', params:[id: params.graphId]) |
|
569 |
return false |
|
570 |
} |
|
571 |
} else { |
|
572 |
flash.errors = "<p>Graph could not be edited. Check if all fields are filled and if values are valid.</p>" |
|
573 |
redirect(action:'editCombGraph', params:[id: params.graphId]) |
|
574 |
return false |
|
575 |
} |
|
576 |
|
|
577 |
} |
|
578 |
|
|
579 |
def showCombGraph = { |
|
580 |
|
|
581 |
if(params.id) { |
|
582 |
CombGraph chGrph = CombGraph.get(params.id) |
|
583 |
if(chGrph) { |
|
584 |
|
|
585 |
List datas = new ArrayList() |
|
586 |
|
|
587 |
chGrph.graphs.each { |
|
588 |
datas << graphDataService.getGraphData(it) |
|
589 |
} |
|
590 |
|
|
591 |
return [data: datas] |
|
592 |
|
|
593 |
} else { |
|
594 |
flash.errors = "<p>Invalid graph ID!</p>" |
|
595 |
redirect(action:'graphs') |
|
596 |
return false |
|
597 |
} |
|
598 |
} else { |
|
599 |
flash.errors = "<p>Invalid graph ID!</p>" |
|
600 |
redirect(action:'graphs') |
|
601 |
return false |
|
602 |
} |
|
603 |
|
|
604 |
} |
|
605 |
|
|
606 |
def makeCombReport = { |
|
607 |
|
|
608 |
|
|
609 |
|
|
610 |
} |
|
471 | 611 |
|
472 | 612 |
} |
hci/trunk/eneraptor-web-app/grails-app/domain/com/eneraptor/hci/CombGraph.groovy | ||
---|---|---|
1 |
package com.eneraptor.hci |
|
2 |
|
|
3 |
class CombGraph { |
|
4 |
|
|
5 |
String name |
|
6 |
static hasMany = [graphs:EneGraph] |
|
7 |
|
|
8 |
static constraints = { |
|
9 |
|
|
10 |
name(blank:false, unique:true) |
|
11 |
|
|
12 |
} |
|
13 |
|
|
14 |
} |
hci/trunk/eneraptor-web-app/test/unit/com/eneraptor/GraphDataServiceTests.groovy | ||
---|---|---|
1 |
package com.eneraptor |
|
2 |
|
|
3 |
import grails.test.* |
|
4 |
|
|
5 |
class GraphDataServiceTests extends GrailsUnitTestCase { |
|
6 |
protected void setUp() { |
|
7 |
super.setUp() |
|
8 |
} |
|
9 |
|
|
10 |
protected void tearDown() { |
|
11 |
super.tearDown() |
|
12 |
} |
|
13 |
|
|
14 |
void testSomething() { |
|
15 |
|
|
16 |
} |
|
17 |
} |
hci/trunk/eneraptor-web-app/test/unit/com/eneraptor/hci/GraphDataServiceTests.groovy | ||
---|---|---|
1 |
package com.eneraptor.hci |
|
2 |
|
|
3 |
import grails.test.* |
|
4 |
|
|
5 |
class GraphDataServiceTests extends GrailsUnitTestCase { |
|
6 |
protected void setUp() { |
|
7 |
super.setUp() |
|
8 |
} |
|
9 |
|
|
10 |
protected void tearDown() { |
|
11 |
super.tearDown() |
|
12 |
} |
|
13 |
|
|
14 |
void testSomething() { |
|
15 |
|
|
16 |
} |
|
17 |
} |
hci/trunk/eneraptor-web-app/test/unit/com/eneraptor/hci/MultiselectTagLibTests.groovy | ||
---|---|---|
1 |
package com.eneraptor.hci |
|
2 |
|
|
3 |
import grails.test.* |
|
4 |
|
|
5 |
class MultiselectTagLibTests extends TagLibUnitTestCase { |
|
6 |
protected void setUp() { |
|
7 |
super.setUp() |
|
8 |
} |
|
9 |
|
|
10 |
protected void tearDown() { |
|
11 |
super.tearDown() |
|
12 |
} |
|
13 |
|
|
14 |
void testSomething() { |
|
15 |
|
|
16 |
} |
|
17 |
} |
hci/trunk/eneraptor-web-app/test/unit/com/eneraptor/hci/CombGraphTests.groovy | ||
---|---|---|
1 |
package com.eneraptor.hci |
|
2 |
|
|
3 |
import grails.test.* |
|
4 |
|
|
5 |
class CombGraphTests extends GrailsUnitTestCase { |
|
6 |
protected void setUp() { |
|
7 |
super.setUp() |
|
8 |
} |
|
9 |
|
|
10 |
protected void tearDown() { |
|
11 |
super.tearDown() |
|
12 |
} |
|
13 |
|
|
14 |
void testSomething() { |
|
15 |
|
|
16 |
} |
|
17 |
} |
Also available in: Unified diff