Revision 42

View differences:

hci/trunk/eneraptor-web-app/grails-app/domain/com/eneraptor/hci/EneGraph.groovy
1
package com.eneraptor.hci
2

  
3
class EneGraph {
4

  
5
	String name
6
	String type
7
	String timeFrameType
8
	Date timeFrameStart
9
	Date timeFrameEnd
10
	int innerSections
11
	int advHoursTimeFrameStart
12
	int advHoursTimeFrameEnd
13
	int advDayTimeFrameStart
14
	int advDayTimeFrameEnd
15
	int advMonthTimeFrameStart
16
	int advMonthTimeFrameEnd
17
	String deviceId
18
	
19
    static constraints = {
20
		
21
		name(blank:false, unique:true)
22
		type(blank:false, inList:["max","min","avg","sum"])
23
		timeFrameType(blank:false, inList:["day","month","year","custom"])
24
		timeFrameStart(blank:false)
25
		timeFrameEnd(blank:false)
26
		innerSections(blank:false,min:(int)1)
27
		advHoursTimeFrameStart(nullable:true)
28
		advHoursTimeFrameEnd(nullable:true)
29
		advDayTimeFrameStart(nullable:true)
30
		advDayTimeFrameEnd(nullable:true)
31
		advMonthTimeFrameStart(nullable:true)
32
		advMonthTimeFrameEnd(nullable:true)
33
		deviceId(blank:false)
34
		
35
    }
36
	
37
}
hci/trunk/eneraptor-web-app/grails-app/views/actions/main.gsp
1 1
<html>
2 2

  
3 3
<head>
4
	<title>Actions</title>
4
	<title>Scenarios</title>
5 5
	<meta name="layout" content="main" />
6 6
</head>
7 7

  
8 8
<body>
9
	<p>Deluje!</p>
9
	
10
	<erptr:box title="Scenarios">
11
		<p>TODO</p>
12
	</erptr:box>
13

  
10 14
</body>
11 15

  
12 16
</html>
hci/trunk/eneraptor-web-app/grails-app/views/actions/add.gsp
1
<html>
2

  
3
<head>
4
	<title>Scenarios</title>
5
	<meta name="layout" content="main" />
6
</head>
7

  
8
<body>
9
	
10
	<erptr:box title="Add a new scenario">
11
		<p>TODO</p>
12
	</erptr:box>
13

  
14
</body>
15

  
16
</html>
hci/trunk/eneraptor-web-app/grails-app/views/actions/view.gsp
1
<html>
2

  
3
<head>
4
	<title>Scenarios</title>
5
	<meta name="layout" content="main" />
6
</head>
7

  
8
<body>
9
	
10
	<erptr:box title="View scenarios">
11
		<p>TODO</p>
12
	</erptr:box>
13

  
14
</body>
15

  
16
</html>
hci/trunk/eneraptor-web-app/grails-app/views/layouts/main.gsp
15 15
<body onload="onLoadDo();">
16 16
	<div id="container">
17 17
		<img style="position:absolute;top:-0px;" src="${g.resource(dir: 'img/', file: 'logo.jpg')}" />
18
		
19
		<!-- Energy saved -->
20
		<div style="position:absolute;top:10px;">
21
			<div style="position:absolute;left:250px;color:white;">
22
				<center style="width:150px;">
23
					<p style="font-size:75%;">From start</p>
24
					<p><b>1243432.45</b> kWh</p>
25
					<p style="font-size:75%;">of energy saved</p>
26
				</center>
27
			</div>
28
			<div style="position:absolute;left:400px;color:white;">
29
				<center style="width:150px;">
30
					<p style="font-size:75%;">Last year</p>
31
					<p><b>87329.84</b> kWh</p>
32
					<p style="font-size:75%;">of energy saved</p>
33
				</center>
34
			</div>
35
			<div style="position:absolute;left:550px;color:white;">
36
				<center style="width:150px;">
37
					<p style="font-size:75%;">Last month</p>
38
					<p><b>5644.56</b> kWh</p>
39
					<p style="font-size:75%;">of energy saved</p>
40
				</center>
41
			</div>
42
			<div style="position:absolute;left:700px;color:white;">
43
				<center style="width:150px;">
44
					<p style="font-size:75%;">Last week</p>
45
					<p><b>453.00</b> kWh</p>
46
					<p style="font-size:75%;">of energy saved</p>
47
				</center>
48
			</div>
49
			<div style="position:absolute;left:850px;color:white;">
50
				<center style="width:150px;">
51
					<p style="font-size:75%;">Last day</p>
52
					<p><b>23.28</b> kWh</p>
53
					<p style="font-size:75%;">of energy saved</p>
54
				</center>
55
		</div>
56
		</div>
57
		<!-- / Energy saved -->
58
		
18 59
		<div id="header">
19 60
   			<h2>&nbsp;</h2>
20 61
			<div id="topmenu">
hci/trunk/eneraptor-web-app/grails-app/views/sysLog/browse.gsp
7 7

  
8 8
<body>
9 9
	
10
	<erptr:box title="Select device and interval">
11
		<p>Please, select which devices to show / ignore:</p>
12
		
13
		<form id="browseForm" action="browse">			
14
				<g:each in="${devicesForCheckBox}" var="deviceForCheckBox">
15
					<label for="cb_${deviceForCheckBox.deviceId}">&nbsp;</label>
16
					<g:checkBox name="cb_${deviceForCheckBox.deviceId}" value="${params['cb_' + deviceForCheckBox.deviceId]}"/>
17
					<span>${deviceForCheckBox.friendlyName}</span>
18
					<br />
19
				</g:each>
20
				<label for="all_cb">&nbsp;</label>
21
				<g:checkBox name="all_cb" value="${params['all_cb']}" />
22
				<span><b>All devices (including <i>unknown devices</i>)</b></span>
23
			<br /><br />
24
			<label for="fromDate">From</label>
25
			<g:datePicker name="fromDate" value="${params.fromDate}" />
26
			<br /><br />
27
			<label for="tillDate">Till</label>
28
			<g:datePicker name="tillDate" value="${params.tillDate}" />
29
			<br /><br />
30
			<g:submitButton name="submitButton" value="Show" />
31
		</form>
32
		
33
	</erptr:box>
34
	
10 35
	<erptr:box title="Browse log">
11 36
	
12 37
		<table width="100%">
......
47 72
		
48 73
	</erptr:box>
49 74
	
75
	<js:checkBoxToggle />
76
	
50 77
</body>
51 78

  
52 79
</html>
hci/trunk/eneraptor-web-app/grails-app/views/sysLog/export.gsp
1
<html>
2

  
3
<head>
4
	<title>Log &raquo; Browsing</title>
5
	<meta name="layout" content="main" />
6
</head>
7

  
8
<body>
9
	
10
	<erptr:box title="Export log entries">
11
		<p>Devices to include / ignore:</p>
12
		
13
		<form id="browseForm" action="exportDo" target="_blank">			
14
				<g:each in="${devicesForCheckBox}" var="deviceForCheckBox">
15
					<label for="cb_${deviceForCheckBox.deviceId}">&nbsp;</label>
16
					<g:checkBox name="cb_${deviceForCheckBox.deviceId}" value="${params['cb_' + deviceForCheckBox.deviceId]}"/>
17
					<span>${deviceForCheckBox.friendlyName}</span>
18
					<br />
19
				</g:each>
20
				<label for="all_cb">&nbsp;</label>
21
				<g:checkBox name="all_cb" value="${params['all_cb']}" />
22
				<span><b>All devices (including <i>unknown devices</i>)</b></span>
23
			<br /><br />
24
			<label for="fromDate">From</label>
25
			<g:datePicker name="fromDate" value="${params.fromDate}" />
26
			<br /><br />
27
			<label for="tillDate">Till</label>
28
			<g:datePicker name="tillDate" value="${params.tillDate}" />
29
			<br /><br />
30
			<p>Options:</p>
31
			<label for="format">Output format</label>
32
			<g:select name="format" from="['Plain text (.txt)','PostgreSQL script (.sql)','Extensible Markup Language (.xml)']" />
33
			<br /><br />
34
			<g:submitButton name="submit" value="Export" />
35
		</form>
36
		
37
	</erptr:box>
38
	
39
</body>
40

  
41
</html>
hci/trunk/eneraptor-web-app/grails-app/views/sysLog/main.gsp
8 8
<body>
9 9
	
10 10
	<erptr:box title="Log">
11
		<p>TODO: Some information about log.</p>
11
		<p>Log holds any information logged by input and output devices.</p>
12
		<p>You can <g:link action="browse">browse</g:link> log entries manually, but be aware, that large intervals may take much time to process.</p>
13
		<p>Eneraptor's storage space is limited, so you should <g:link action="clear">clear</g:link> the log entries when running out of space. To save old log entries you may use the <g:link action="export">export</g:link> function.</p>
14
		<p>Log entries'' numeric data may be <g:link action="graph">viewed graphically</g:link> directly. If you want better and quicker results, you should use tools in the <g:link controller="statistics" action="main">Statistics</g:link> section instead.</p>
12 15
	</erptr:box>
13 16
	
14 17
	<!-- DISK USAGE - ONLY IF ENERAPOTR HCI IS SUPERUSER
hci/trunk/eneraptor-web-app/grails-app/views/sysLog/clear.gsp
1
<html>
2

  
3
<head>
4
	<title>Log &raquo; Browsing</title>
5
	<meta name="layout" content="main" />
6
</head>
7

  
8
<body>
9
	
10
	<erptr:box title="Clear log entries">
11
		<p>Devices to include / ignore:</p>
12
		
13
		<form id="clearForm" action="clearDo">			
14
				<g:each in="${devicesForCheckBox}" var="deviceForCheckBox">
15
					<label for="cb_${deviceForCheckBox.deviceId}">&nbsp;</label>
16
					<g:checkBox name="cb_${deviceForCheckBox.deviceId}" value="${params['cb_' + deviceForCheckBox.deviceId]}"/>
17
					<span>${deviceForCheckBox.friendlyName}</span>
18
					<br />
19
				</g:each>
20
				<label for="all_cb">&nbsp;</label>
21
				<g:checkBox name="all_cb" value="${params['all_cb']}" />
22
				<span><b>All devices (including <i>unknown devices</i>)</b></span>
23
			<br /><br />
24
			<label for="fromDate">From</label>
25
			<g:datePicker name="fromDate" value="${params.fromDate}" />
26
			<br /><br />
27
			<label for="tillDate">Till</label>
28
			<g:datePicker name="tillDate" value="${params.tillDate}" />
29
			<br /><br />
30
			<g:submitButton name="submit" value="Clear" />
31
		</form>
32
		
33
	</erptr:box>
34
	
35
</body>
36

  
37
</html>
hci/trunk/eneraptor-web-app/grails-app/views/statistics/showGraph.gsp
1
<html>
2

  
3
<head>
4
	<title>Statistics &raquo; 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
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="Saved graphs">
11
		
12
		<table>
13
			<thead>
14
				<tr>
15
					<th><p>Graph name (short description)</p></th>
16
					<th><p>For device</p></th>
17
					<th><p>Type</p></th>
18
					<th><p>Options</p></th>
19
				</tr>
20
			</thead>
21
			<tbody>
22
				<g:each in="${savedGraphs}" var="savedGraph">
23
					<tr>
24
						<td><p><erptr:icon w="chart_curve" /><g:link action="showGraph" params="[graphId: savedGraph.id]">${savedGraph.name}</g:link></p></td>
25
						<td><p>${savedGraph.deviceId}</p></td>
26
						<td><p>${savedGraph.type}</p></td>
27
						<td><p>TODO</p></td>
28
					</tr>
29
				</g:each>
30
			</tbody>
31
		</table>
32
		<g:if test="${savedGraphs.size == 0}">
33
			<center><p><i>There are no saved graphs.</i></p></center>
34
		</g:if>
35

  
36
	</erptr:box>
37
	
38
	<erptr:box title="Create a new graph">
39
		<p>To create a new graph, select one of the graph types below:</p>
40
			<table style="text-align:center;border:none;">
41
				<tr>
42
					<td style="border:none;"><img src="${resource(dir:'img/',file:'min.png')}" /></td>
43
					<td style="border:none;"><img src="${resource(dir:'img/',file:'max.png')}" /></td>
44
					<td style="border:none;"><img src="${resource(dir:'img/',file:'avg.png')}" /></td>
45
					<td style="border:none;"><img src="${resource(dir:'img/',file:'sum.png')}" /></td>
46
				</tr>
47
				<tr>
48
					<td style="border:none;"><p><g:link action="newGraph" params="[graphType:'min']">Create a minimum value graph</g:link></p></td>
49
					<td style="border:none;"><p><g:link action="newGraph" params="[graphType:'max']">Create a maximum value graph</g:link></p></td>
50
					<td style="border:none;"><p><g:link action="newGraph" params="[graphType:'avg']">Create a average value graph</g:link></p></td>
51
					<td style="border:none;"><p><g:link action="newGraph" params="[graphType:'sum']">Create a cumulative graph</g:link></p></td>
52
				</tr>
53
			</table>
54
	</erptr:box>
55

  
56
</body>
57

  
58
</html>
hci/trunk/eneraptor-web-app/grails-app/views/statistics/main.gsp
6 6
</head>
7 7

  
8 8
<body>
9
	<p>Deluje!</p>
9
	
10
	<erptr:box title="Statistics">
11
		<p>TODO</p>
12
	</erptr:box>
13

  
10 14
</body>
11 15

  
12 16
</html>
hci/trunk/eneraptor-web-app/grails-app/views/statistics/newGraph.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 graph">
11
		
12
		<form name="newGraphForm" action="newGraphDo">
13
		
14
			<fieldset>
15
				<legend>General information</legend>
16
				<label for="graphName">Graph name (short description)</label>
17
				<g:textField name="graphName" style="width:500px;" />
18
				<br /><br />
19
				<label for="deviceId">Device</label>
20
				<g:select name="deviceId" from="${devicesFriendly}" keys="${devices}" />
21
			</fieldset>
22
		
23
			<fieldset>
24
				<legend>Graph type</legend>
25
			
26
				<label for="graphType">Calculation type</label>
27
				<g:select from="${graphTypesFriendly}" value="${params.graphType}" name="graphType" keys="${graphTypes}" />
28
				<br /><br />
29
			
30
				<label for="timeFrameType">Time frame type</label>
31
				<select name="timeFrameType" id="timeFrameType" >
32
					<option onclick="changeTimeFrameType('day')" value="day" selected="${timeFrameType == 'day'}">Daily</option>
33
					<option onclick="changeTimeFrameType('month')" value="month" selected="${timeFrameType == 'month'}">Monthly</option>
34
					<option onclick="changeTimeFrameType('year')" value="year" selected="${timeFrameType == 'year'}">Yearly</option>
35
					<option onclick="changeTimeFrameType('custom')" value="custom" selected="${timeFrameType == 'custom'}">Custom</option>
36
				</select>
37
				<br />
38
				
39
				<label for="timeFrameTypeDesc">&nbsp;</label>
40
				<p name="timeFrameTypeDesc" id="timeFrameTypeDesc">&nbsp;&nbsp;<i>Calculations will be made for custom inner time intervals separately.</i></p>
41
				
42
			</fieldset>
43
			
44
			<fieldset>
45
				<legend>Main time frame</legend>
46
				<div style="display:none;" id="dayMainTimeFrame" name="dayMainTimeFrame">
47
					<label for="dayMainTimeFrameStart">From</label>
48
					<g:datePicker name="dayMainTimeFrameStart" precision="day" />
49
					<br /><br />
50
					<label for="dayMainTimeFrameEnd">From</label>
51
					<g:datePicker name="dayMainTimeFrameEnd" precision="day" />
52
					<br /><br />
53
				</div>
54
				<div style="display:none;" id="monthMainTimeFrame" name="monthMainTimeFrame">
55
					<label for="monthMainTimeFrameStart">From</label>
56
					<g:datePicker name="monthMainTimeFrameStart" precision="month" />
57
					<br /><br />
58
					<label for="monthMainTimeFrameEnd">From</label>
59
					<g:datePicker name="monthMainTimeFrameEnd" precision="month" />
60
					<br /><br />
61
				</div>
62
				<div style="display:none;" id="yearMainTimeFrame" name="yearMainTimeFrame">
63
					<label for="yearMainTimeFrameStart">From</label>
64
					<g:datePicker name="yearMainTimeFrameStart" precision="year" />
65
					<br /><br />
66
					<label for="yearMainTimeFrameEnd">From</label>
67
					<g:datePicker name="yearMainTimeFrameEnd" precision="year" />
68
					<br /><br />
69
				</div>
70
				<div id="customMainTimeFrame" name="customMainTimeFrame">
71
					<label for="customMainTimeFrameStart">From</label>
72
					<g:datePicker name="customMainTimeFrameStart" />
73
					<br /><br />
74
					<label for="customMainTimeFrameEnd">From</label>
75
					<g:datePicker name="customMainTimeFrameEnd" />
76
					<br /><br />
77
					<label for="customMainTimeFrameInnerSections">Number of inner intervals</label>
78
					<input onkeyup="checkInnerSections();" type="text" id="customMainTimeFrameInnerSections" name="customMainTimeFrameInnerSections" value="1" />
79
					<br /><br />
80
				</div>
81
			</fieldset>
82
			
83
			<fieldset>
84
				<legend>Advanced options</legend>
85
				<a name="advOptionsExp" id="advOptionsExp" href="#" onclick="$('advOptions').show();$('advOptionsExp').hide();return false;"><erptr:icon w="bullet_arrow_down" />Show advanced options</a>
86
				<div name="advOptions" id="advOptions" style="display:none;">
87
					<label for="advHoursStart">Include only hours from</label>
88
					<g:select name="advHoursStart" from="${0..23}" value="0" />
89
					<span> to </span>
90
					<g:select name="advHoursEnd" from="${0..23}" value="23" />
91
					<br /><br />
92
					<label for="advDayStart">Include only days from</label>
93
					<g:select name="advDayStart" from="${1..31}" value="1" />
94
					<span> to </span>
95
					<g:select name="advDayEnd" from="${1..31}" value="31" />
96
					<br /><br />
97
					<label for="advMonthStart">Include only months from</label>
98
					<g:select name="advMonthStart" from="${1..12}" value="1" />
99
					<span> to </span>
100
					<g:select name="advMonthEnd" from="${1..12}" value="12" />
101
					<br /><br />
102
				</div>
103
			</fieldset>
104
		
105
		<g:submitButton name="newGraphSubmit" value="Save & show" />&nbsp;&nbsp;
106
		<g:actionSubmit name="newGraphShowOnly" action="showGraph" value="Show (without saving)" />&nbsp;&nbsp;
107
		<g:actionSubmit name="newGraphCancel" action="newGraph" value="Cancel" />
108
		
109
		</form>
110
		
111
	</erptr:box>
112
	
113
	<g:javascript>
114
		function changeTimeFrameType(toType) {
115
			if(toType == 'day') {
116
				$('timeFrameTypeDesc').innerHTML = "&nbsp;&nbsp;<i>Calculations will be made for each day separately.</i>";
117
				$('dayMainTimeFrame').show();
118
				$('monthMainTimeFrame').hide();
119
				$('yearMainTimeFrame').hide();
120
				$('customMainTimeFrame').hide();
121
			} else if(toType == 'month') {
122
				$('timeFrameTypeDesc').innerHTML = "&nbsp;&nbsp;<i>Calculations will be made for each month separately.</i>";
123
				$('dayMainTimeFrame').hide();
124
				$('monthMainTimeFrame').show();
125
				$('yearMainTimeFrame').hide();
126
				$('customMainTimeFrame').hide();
127
			} else if(toType == 'year') {
128
				$('timeFrameTypeDesc').innerHTML = "&nbsp;&nbsp;<i>Calculations will be made for each year separately.</i>";
129
				$('dayMainTimeFrame').hide();
130
				$('monthMainTimeFrame').hide();
131
				$('yearMainTimeFrame').show();
132
				$('customMainTimeFrame').hide();
133
			} else if(toType == 'custom') {
134
				$('timeFrameTypeDesc').innerHTML = "&nbsp;&nbsp;<i>Calculations will be made for custom inner time intervals separately.</i>";
135
				$('dayMainTimeFrame').hide();
136
				$('monthMainTimeFrame').hide();
137
				$('yearMainTimeFrame').hide();
138
				$('customMainTimeFrame').show();
139
			}
140
		}
141
		function checkInnerSections() {
142
			var sText = $('customMainTimeFrameInnerSections').value;
143
			var validChars = "0123456789";
144
			var isNumber = true;
145
			var currChar;
146
					 
147
			for (i = 0; i < sText.length; i++) { 
148
				currChar = sText.charAt(i); 
149
				if (validChars.indexOf(currChar) == -1) {
150
					isNumber = false;
151
					break;
152
				}
153
			}
154
			
155
			if(isNumber == false) {
156
				$('customMainTimeFrameInnerSections').value = sText.substring(0,(sText.length)-1)
157
			}
158
			
159
		}
160
	</g:javascript>
161

  
162
</body>
163

  
164
</html>
hci/trunk/eneraptor-web-app/grails-app/views/statistics/reports.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="Saved reports">
11
		<p>TODO</p>
12
	</erptr:box>
13
	
14
	<erptr:box title="Create a new report">
15
		<p>TODO</p>
16
	</erptr:box>
17

  
18
</body>
19

  
20
</html>
hci/trunk/eneraptor-web-app/grails-app/services/com/eneraptor/hci/MainMenuService.groovy
26 26
		mainMenuItems.add(new MenuItem("System state" ,"sysState"  ,"main"))
27 27
		mainMenuItems.add(new MenuItem("Log"          ,"sysLog"    ,"main"))
28 28
		mainMenuItems.add(new MenuItem("Statistics"   ,"statistics","main"))
29
		mainMenuItems.add(new MenuItem("Actions"      ,"actions"   ,"main"))
29
		mainMenuItems.add(new MenuItem("Scenarios"      ,"actions"   ,"main"))
30 30
		mainMenuItems.add(new MenuItem("Configuration","config"    ,"main"))
31 31
		
32 32
		sysStateSubMenu = new ArrayList()
......
38 38
		sysLogSubMenu.add(new MenuItem("Overview","sysLog","main"))
39 39
		sysLogSubMenu.add(new MenuItem("Browse","sysLog","browse"))
40 40
		sysLogSubMenu.add(new MenuItem("View logged data graphically","sysLog","graph"))
41
		sysLogSubMenu.add(new MenuItem("Export","sysLog","export"))
42
		sysLogSubMenu.add(new MenuItem("Clear","sysLog","clear"))
41 43
		
44
		statisticsSubMenu = new ArrayList()
45
		statisticsSubMenu.add(new MenuItem("Overview","statistics","main"))
46
		statisticsSubMenu.add(new MenuItem("Graphs","statistics","graphs"))
47
		statisticsSubMenu.add(new MenuItem("Reports","statistics","reports"))
48
		
49
		actionsSubMenu = new ArrayList()
50
		actionsSubMenu.add(new MenuItem("Overview","actions","main"))
51
		actionsSubMenu.add(new MenuItem("View and edit","actions","view"))
52
		actionsSubMenu.add(new MenuItem("Create new","actions","add"))
53
		
42 54
		configSubMenu = new ArrayList()
43 55
		configSubMenu.add(new MenuItem("Overview","config","main"))
44 56
		configSubMenu.add(new MenuItem("Configure HCI","config","hci"))
hci/trunk/eneraptor-web-app/grails-app/controllers/com/eneraptor/hci/StatisticsController.groovy
1

  
1 2
package com.eneraptor.hci
2 3

  
4
import groovy.sql.Sql
5

  
3 6
class StatisticsController {
4

  
7

  
8
	def dataSource
9
	
5 10
    def main = { }
11
	
12
	def graphs = {
13
	
14
		List savedGraphs = new ArrayList()
15
		
16
		savedGraphs = EneGraph.list()
17
			
18
		[savedGraphs: savedGraphs]
19
			
20
	}
21
	
22
	def reports = { }
23
	
24
	def newGraph = {
25
		
26
		List graphTypes = ["min","max","avg","sum"]
27
		List graphTypesFriendly = ["Minimum value","Maximum value","Average value","Cumulative"]
28
		
29
		List devices = new ArrayList()
30
		List devicesFriendly = new ArrayList()
31
		
32
		DeviceInfo.list().each {
33
			devices << it.deviceId
34
			devicesFriendly << it.friendlyName
35
		}
36
		
37
		[graphTypes:graphTypes,graphTypesFriendly:graphTypesFriendly, devices:devices, devicesFriendly:devicesFriendly]
38
		
39
	}
40
	
41
	def newGraphDo = {
42
		
43
		String errors = ""
44
		Date chosenTimeFrameStart = null
45
		Date chosenTimeFrameEnd = null
46
		
47
		if(params['timeFrameType'] == "day") {
48
			chosenTimeFrameStart = params['dayMainTimeFrameStart']
49
			chosenTimeFrameEnd = params['dayMainTimeFrameEnd']
50
		} else if(params['timeFrameType'] == "month") {
51
			chosenTimeFrameStart = params['monthMainTimeFrameStart']
52
			chosenTimeFrameEnd = params['monthMainTimeFrameEnd']
53
		} else if(params['timeFrameType'] == "year") {
54
			chosenTimeFrameStart = params['yearMainTimeFrameStart']
55
			chosenTimeFrameEnd = params['yearMainTimeFrameEnd']
56
		} else if(params['timeFrameType'] == "custom") {
57
			chosenTimeFrameStart = params['customMainTimeFrameStart']
58
			chosenTimeFrameEnd = params['customMainTimeFrameEnd']
59
		} else {
60
			errors += "<p>Time frame type invalid!</p>"
61
		}
62
		
63
		def newEneGraph = new EneGraph(
64
			name: params['graphName'],
65
			type: params['graphType'],
66
			timeFrameType: params['timeFrameType'],
67
			timeFrameStart: chosenTimeFrameStart,
68
			timeFrameEnd: chosenTimeFrameEnd,
69
			innerSections: params['customMainTimeFrameInnerSections'],
70
			advHoursTimeFrameStart: params['advHoursStart'],
71
			advHoursTimeFrameEnd: params['advHoursEnd'],
72
			advDayTimeFrameStart: params['advDayStart'],
73
			advDayTimeFrameEnd: params['advDayEnd'],
74
			advMonthTimeFrameStart: params['advMonthStart'],
75
			advMonthTimeFrameEnd: params['advMonthEnd'],
76
			deviceId: params['deviceId']
77
		)
78
		
79
		if(!newEneGraph.validate()) {
80
			errors += "<p>Graph could not be created - there were some input errors. Please check if all input values are valid.</p>"
81
			flash['errors'] = errors
82
			redirect(action:'newGraph')
83
		} else {
84
			if(newEneGraph.save()){
85
				flash['confirms'] = "<p>Graph created succesfully!</p>"
86
				redirect(action:'newGraph')
87
			} else {
88
				flash['errors'] = "<p>There was an error while saving graph.</p>"
89
				redirect(action:'newGraph')
90
			}
91
		}
92
		
93
		return true
94
		
95
	}
96
	
97
	def showGraph = {
98
		
99
		def graphToShow = EneGraph.get(params['graphId'])
100
		
101
		List data = new ArrayList()
102
		def results
103
		def db_sql = new Sql(dataSource)
104
		
105
		if(graphToShow.timeFrameType == "day") {
106
			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 (date_trunc('day',ld.date_recieved) >= '" + graphToShow.timeFrameStart + "' and date_trunc('day',ld.date_recieved) <= '" + graphToShow.timeFrameEnd + "') group by date_trunc('day',ld.date_recieved) order by date_trunc('day',ld.date_recieved) asc", {
107
				data << [it.dt.getTime(), it.vl]
108
			}
109
		} else if (graphToShow.timeFrameType == "month") {
110
			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 (date_trunc('month',ld.date_recieved) >= '" + graphToShow.timeFrameStart + "' and date_trunc('month',ld.date_recieved) <= '" + graphToShow.timeFrameEnd + "') group by date_trunc('month',ld.date_recieved) order by date_trunc('month',ld.date_recieved) asc", {
111
				data << [it.dt.getTime(), it.vl]
112
			}
113
		} else if (graphToShow.timeFrameType == "year") {
114
			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 (date_trunc('year',ld.date_recieved) >= '" + graphToShow.timeFrameStart + "' and date_trunc('year',ld.date_recieved) <= '" + graphToShow.timeFrameEnd + "') group by date_trunc('year',ld.date_recieved) order by date_trunc('year',ld.date_recieved) asc", {
115
				data << [it.dt.getTime(), it.vl]
116
			}
117
		}
118
		
119
		[data:data]
120
		
121
	}
6 122
	
7 123
}
hci/trunk/eneraptor-web-app/grails-app/controllers/com/eneraptor/hci/ActionsController.groovy
3 3
class ActionsController {
4 4

  
5 5
    def main = { }
6
	
7
	def view = { }
8
	
9
	def add = { }
6 10
	
7 11
}
hci/trunk/eneraptor-web-app/grails-app/controllers/com/eneraptor/hci/SysLogController.groovy
40 40
		
41 41
		flash['warnings'] = null
42 42
		
43
		def entries = LoggedData.list()
43
		List devicesForCheckBox = new ArrayList()
44
		DeviceInfo.findAllByInputDeviceOrOutputDevice(true,true).each {
45
			devicesForCheckBox << it
46
		}
47
		
48
		def entries = new ArrayList()
49
		
50
		List checkedDevices = new ArrayList()
51
		devicesForCheckBox.each {
52
			if(params['cb_' + it.deviceId]) {
53
				checkedDevices << it.deviceId
54
			}
55
		}
56
		
57
		if(params['fromDate'] && params['tillDate']) {
58
			if(params['all_cb']) {
59
				def c = LoggedData.createCriteria()
60
				entries = c {
61
					and {
62
						between("dateRecieved",params['fromDate'],params['tillDate'])
63
					}
64
					order("dateRecieved","asc")
65
				}
66
			} else {
67
				if(checkedDevices.size > 0) {
68
					def c = LoggedData.createCriteria()
69
					entries = c {
70
						and {
71
							between("dateRecieved",params['fromDate'],params['tillDate'])
72
							'in'("deviceId",checkedDevices)
73
						}
74
						order("dateRecieved","asc")
75
					}
76
				}
77
			}
78
		}
79

  
44 80
		Map devices = new HashMap()
45 81
		Map icons   = new HashMap()
46 82
		List unknownDevices = new ArrayList()
......
62 98
			flash['warnings'] += "<p>There was found at least one log entry for a device with id <b>${it}</b>, which is <b>unknown</b> to HCI. You should <b>add this device</b> by <b>" + g.link(controller: 'config', action: 'addDevice', params: ['deviceId' : it], "clicking here") + "</b>.</p>"
63 99
		}
64 100
		
65
		[data: entries, devices: devices, icons: icons]
101
		[data: entries, devices: devices, icons: icons, devicesForCheckBox:devicesForCheckBox]
66 102
		
67 103
	}
68 104
	
......
122 158
		[data: data, devices: devices, params:params]
123 159
		
124 160
	}
161
	
162
	def export = {
163
		
164
		List devicesForCheckBox = new ArrayList()
165
		DeviceInfo.findAllByInputDeviceOrOutputDevice(true,true).each {
166
			devicesForCheckBox << it
167
		}
168
		
169
		[devicesForCheckBox: devicesForCheckBox]
170
		
171
	}
172
	
173
	def exportDo = {
174
		
175
		List devicesForCheckBox = new ArrayList()
176
		DeviceInfo.findAllByInputDeviceOrOutputDevice(true,true).each {
177
			devicesForCheckBox << it
178
		}
179
		
180
		List checkedDevices = new ArrayList()
181
		devicesForCheckBox.each {
182
			if(params['cb_' + it.deviceId]) {
183
				checkedDevices << it.deviceId
184
			}
185
		}
186
		
187
		List entries = new ArrayList()
188
		def cont = ""
189
		
190
		if(params['all_cb']) {
191
			def c = LoggedData.createCriteria()
192
			entries = c {
193
				and {
194
					between("dateRecieved",params['fromDate'],params['tillDate'])
195
				}
196
				order("dateRecieved","asc")
197
			}
198
		} else {
199
			if(checkedDevices.size > 0) {
200
				def c = LoggedData.createCriteria()
201
				entries = c {
202
					and {
203
						between("dateRecieved",params['fromDate'],params['tillDate'])
204
						'in'("deviceId",checkedDevices)
205
					}
206
					order("dateRecieved","asc")
207
				}
208
			}
209
		}
210
		
211
		if(entries.size == 0) {
212
			flash['errors'] = "<p>Nothing to export!</p><p>There are no log entries for selected devices in the time interval specified.</p>"
213
			redirect(action:'export')
214
		}
215
		else if(params['format'] == "Plain text (.txt)") {
216
			entries.each {
217
				cont += it.dateRecieved.toString() + " " + it.deviceId + " " + it.reportedData + "\n"
218
			}
219
			render(text: cont,contentType:"text/plain",encoding:"UTF-8")
220
		} else if(params['format'] == "PostgreSQL script (.sql)") {
221
			entries.each {
222
				cont += "INSERT INTO logged_data(id, \"version\", date_recieved, device_id, reported_data) VALUES (nextval('hibernate_sequence'), 0, '" + it.dateRecieved.toString() + "', '" + it.deviceId + "', '" + it.reportedData + "');\n";
223
			}
224
			render(text: cont,contentType:"text/plain",encoding:"UTF-8")
225
		} else {
226
			cont += "<log>\n"
227
			entries.each {
228
				cont += "\t<entry>\n"
229
				cont += "\t\t<device>" + it.deviceId + "</device>\n"
230
				cont += "\t\t<time>" + it.dateRecieved.toString() + "</time>\n"
231
				cont += "\t\t<data>\n"
232
				cont += "\t\t\t" + it.reportedData + "\n"
233
				cont += "\t\t</data>\n"
234
				cont += "\t</entry>\n"
235
			}
236
			cont += "</log>"
237
			render(text: cont,contentType:"text/xml",encoding:"UTF-8")
238
		}
239
	}
240
	
241
	def clear = {
242
		
243
		List devicesForCheckBox = new ArrayList()
244
		DeviceInfo.findAllByInputDeviceOrOutputDevice(true,true).each {
245
			devicesForCheckBox << it
246
		}
247
		
248
		[devicesForCheckBox: devicesForCheckBox]
249
		
250
	}
251
	
252
	def clearDo = {
253
		
254
		List devicesForCheckBox = new ArrayList()
255
		DeviceInfo.findAllByInputDeviceOrOutputDevice(true,true).each {
256
			devicesForCheckBox << it
257
		}
258
		
259
		List checkedDevices = new ArrayList()
260
		devicesForCheckBox.each {
261
			if(params['cb_' + it.deviceId]) {
262
				checkedDevices << it.deviceId
263
			}
264
		}
265
		
266
		List entries = new ArrayList()
267
		def cont = ""
268
		
269
		if(params['all_cb']) {
270
			def c = LoggedData.createCriteria()
271
			entries = c {
272
				and {
273
					between("dateRecieved",params['fromDate'],params['tillDate'])
274
				}
275
				order("dateRecieved","asc")
276
			}
277
		} else {
278
			if(checkedDevices.size > 0) {
279
				def c = LoggedData.createCriteria()
280
				entries = c {
281
					and {
282
						between("dateRecieved",params['fromDate'],params['tillDate'])
283
						'in'("deviceId",checkedDevices)
284
					}
285
					order("dateRecieved","asc")
286
				}
287
			}
288
		}
289
		
290
		if(entries.size == 0) {
291
			flash['errors'] = "<p>Nothing to clear!</p><p>There are no log entries for selected devices in the time interval specified.</p>"
292
		} else {
293
			def entCleared = 0
294
			entries.each {
295
				it.delete()
296
				entCleared++
297
			}
298
			flash['confirms'] = "<p>" + entCleared + " log entries succesfully cleared!</p>"
299
		}
300
		redirect(action:'clear')
301
		
302
	}
125 303
	
126 304
}
hci/trunk/eneraptor-web-app/test/unit/com/eneraptor/EneGraphTests.groovy
1
package com.eneraptor
2

  
3
import grails.test.*
4

  
5
class EneGraphTests 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/EneGraphTests.groovy
1
package com.eneraptor.hci
2

  
3
import grails.test.*
4

  
5
class EneGraphTests 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/target/test-reports/TESTS-TestSuites.xml
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<testsuites>
3
  <testsuite errors="0" failures="0" hostname="Alex-Laptop" id="0" name="BasicTests" package="com.eneraptor.hci" tests="1" time="0.152" timestamp="2010-12-27T10:08:39">
4
      <properties />
5

  
6
      <testcase classname="com.eneraptor.hci.BasicTests" name="testSomething" time="0.151" />
7

  
8
      <system-out><![CDATA[--Output from testSomething--
9
]]></system-out>
10

  
11
      <system-err><![CDATA[--Output from testSomething--
12
]]></system-err>
13

  
14
  </testsuite>
15
  <testsuite errors="0" failures="0" hostname="Alex-Laptop" id="1" name="ErptrTagLibTests" package="com.eneraptor.hci" tests="1" time="0.692" timestamp="2010-12-27T10:08:26">
16
      <properties />
17

  
18
      <testcase classname="com.eneraptor.hci.ErptrTagLibTests" name="testSomething" time="0.607" />
19

  
20
      <system-out><![CDATA[--Output from testSomething--
21
]]></system-out>
22

  
23
      <system-err><![CDATA[--Output from testSomething--
24
]]></system-err>
25

  
26
  </testsuite>
27
  <testsuite errors="0" failures="0" hostname="Alex-Laptop" id="2" name="InternalConfigControllerTests" package="com.eneraptor.hci" tests="1" time="0.181" timestamp="2010-12-27T10:08:27">
28
      <properties />
29

  
30
      <testcase classname="com.eneraptor.hci.InternalConfigControllerTests" name="testSomething" time="0.176" />
31

  
32
      <system-out><![CDATA[--Output from testSomething--
33
]]></system-out>
34

  
35
      <system-err><![CDATA[--Output from testSomething--
36
]]></system-err>
37

  
38
  </testsuite>
39
  <testsuite errors="0" failures="0" hostname="Alex-Laptop" id="3" name="InternalConfigTests" package="com.eneraptor.hci" tests="1" time="0.018" timestamp="2010-12-27T10:08:27">
40
      <properties />
41

  
42
      <testcase classname="com.eneraptor.hci.InternalConfigTests" name="testConstructor" time="0.013" />
43

  
44
      <system-out><![CDATA[--Output from testConstructor--
45
]]></system-out>
46

  
47
      <system-err><![CDATA[--Output from testConstructor--
48
]]></system-err>
49

  
50
  </testsuite>
51
  <testsuite errors="1" failures="0" hostname="Alex-Laptop" id="4" name="MainMenuServiceTests" package="com.eneraptor.hci" tests="1" time="0.026" timestamp="2010-12-27T10:08:27">
52
      <properties />
53

  
54
      <testcase classname="com.eneraptor.hci.MainMenuServiceTests" name="testSomething" time="0.021">
55
          <error message="Cannot invoke method getMainMenu() on null object" type="java.lang.NullPointerException">java.lang.NullPointerException: Cannot invoke method getMainMenu() on null object
56
	at com.eneraptor.hci.MainMenuServiceTests.testSomething(MainMenuServiceTests.groovy:19)
57
</error>
58

  
59
      </testcase>
60

  
61
      <system-out><![CDATA[--Output from testSomething--
62
]]></system-out>
63

  
64
      <system-err><![CDATA[--Output from testSomething--
65
]]></system-err>
66

  
67
  </testsuite>
68
  <testsuite errors="0" failures="0" hostname="Alex-Laptop" id="5" name="MenuProviderControllerTests" package="com.eneraptor.hci" tests="1" time="0.019" timestamp="2010-12-27T10:08:27">
69
      <properties />
70

  
71
      <testcase classname="com.eneraptor.hci.MenuProviderControllerTests" name="testSomething" time="0.016" />
72

  
73
      <system-out><![CDATA[--Output from testSomething--
74
]]></system-out>
75

  
76
      <system-err><![CDATA[--Output from testSomething--
77
]]></system-err>
78

  
79
  </testsuite>
80
</testsuites>
hci/trunk/eneraptor-web-app/web-app/css/style.css
408 408
.sysLog-main{background:transparent url(../img/icons/eye.png) no-repeat left;}
409 409
.sysLog-browse{background:transparent url(../img/icons/magnifier.png) no-repeat left;}
410 410
.sysLog-graph{background:transparent url(../img/icons/chart_curve.png) no-repeat left;}
411
.sysLog-export{background:transparent url(../img/icons/disk_multiple.png) no-repeat left;}
412
.sysLog-clear{background:transparent url(../img/icons/bin.png) no-repeat left;}
411 413

  
414
.statistics-main{background:transparent url(../img/icons/eye.png) no-repeat left;}
415
.statistics-graphs{background:transparent url(../img/icons/chart_curve.png) no-repeat left;}
416
.statistics-reports{background:transparent url(../img/icons/report.png) no-repeat left;}
417

  
418
.actions-main{background:transparent url(../img/icons/eye.png) no-repeat left;}
419
.actions-view{background:transparent url(../img/icons/script.png) no-repeat left;}
420
.actions-add{background:transparent url(../img/icons/script_add.png) no-repeat left;}
421

  
412 422
.config-main{background:transparent url(../img/icons/eye.png) no-repeat left;}
413 423
.config-hci{background:transparent url(../img/icons/application.png) no-repeat left;}
414 424
.config-logic{background:transparent url(../img/icons/cog.png) no-repeat left;}

Also available in: Unified diff