Revision 70

View differences:

hci/trunk/eneraptor-web-app/grails-app/controllers/com/eneraptor/hci/SysLogController.groovy
357 357
		
358 358
		if(params['deviceId'] && params['timeSpan']) {
359 359
			
360
			System.out.println("[LiveGraph] Getting for " + params.deviceId + ", time span " + params.timeSpan);
361
			
362 360
			java.util.Date beforeNMinutes = new java.util.Date(
363 361
				now.time - (60000 * (params.timeSpan as int))
364 362
			)
......
376 374
				data << [it.dateRecieved.getTime(),it.reportedData]
377 375
			}
378 376
			
379
			System.out.println(data);
380
			
381 377
		}
382 378
		
383 379
		[params:params, data:data]
hci/trunk/eneraptor-web-app/grails-app/controllers/com/eneraptor/hci/StatisticsController.groovy
617 617
			if(chGrph) {
618 618
				
619 619
				List datas = new ArrayList()
620
				List datasList = new ArrayList()
620 621
				
621 622
				chGrph.graphs.each {
622
					datas << "{label: '" + it.name + "', data: " + graphDataService.getGraphData(it).toString() + "}"
623
					def grphData = graphDataService.getGraphData(it)
624
					datasList << grphData
625
					datas << "{label: '" + it.name + "', data: " + grphData.toString() + "}"
623 626
				}
624 627
				
625
				return [data: datas]
628
				if(!params.outputDevice) params.outputDevice = 'none'
626 629
				
630
				List outputDevices = new ArrayList()
631
				
632
				def crit1 = DeviceInfo.createCriteria()
633
				outputDevices = crit1 {
634
					and {
635
						eq("outputDevice",true)
636
						eq("hwSet",session.hwSet)
637
					}
638
					order("friendlyName","asc")
639
				}
640
				
641
				// Fetch action logged data if needed
642
				List actionLog = new ArrayList()
643
				if(params.outputDevice != 'none') {
644
					
645
					// Find time span
646
					long min = Long.MAX_VALUE
647
					long max = 0
648
					datasList.each { series ->
649
						series.each {
650
							if(it[0] < min) min = it[0]
651
							if(it[0] > max) max = it[0]
652
						}
653
					}
654
					
655
					def crit2 = LoggedData.createCriteria()
656
					actionLog = crit2 {
657
						and {
658
							eq("deviceId",params.outputDevice)
659
							between("dateRecieved",new java.util.Date(min),new java.util.Date(max))
660
						}
661
						order("dateRecieved","asc")
662
					}
663
				}
664
				
665
				return [data: datas,actionLog:actionLog,outputDevices:outputDevices]
666
				
627 667
			} else {
628 668
				flash.errors = "<p>Invalid graph ID!</p>"
629 669
				redirect(action:'graphs')
hci/trunk/eneraptor-web-app/grails-app/domain/com/eneraptor/hci/EneGraph.groovy
1 1
package com.eneraptor.hci
2 2

  
3
class EneGraph {
3
class EneGraph { 
4 4

  
5 5
	String name
6 6
	String type
hci/trunk/eneraptor-web-app/grails-app/views/statistics/showGraph.gsp
10 10

  
11 11
	<erptr:box title="Graph">
12 12
		<g:javascript>
13
			var plot;
13 14
			var data = [${data}];
14 15
			var options = {
15 16
				lines: { show: true },
......
30 31
				}
31 32
			};
32 33
		</g:javascript>
34
		
33 35
		<div class="chart">
34
			<flot:plot id="placeholder" style="width: 900px; height: 300px; padding:5px;" data="data" options="options" />
36
			<div id='placeholder' style='width: 900px; height: 300px; padding:5px;'></div>
37
			<script type='text/javascript'>
38
			jQuery(function (){ 
39
				plot = jQuery.plot(jQuery("#placeholder"),data, options);
40
			});
41
			</script>
35 42
		</div>
43
		
36 44
		<br />
37 45
		<p>Legend:</p>
38 46
		<div id="legendHolder" name="legendHolder"></div>
39
		<br />
47
		
48
		<table>
49
			<g:set var="al2num" value="0" />
50
			<g:each in="${actionLog}" var="al2">
51
				<tr>
52
					<td style="width:20px;"><p style="color:red;font-size:smaller;">${++al2num}</p></td>
53
					<td style="width:150px;">${al2.dateRecieved}</td>
54
					<td>${al2.reportedData}</td>
55
				</tr>
56
			</g:each>
57
		</table>
58
		
40 59
		<p>Display actions:</p>
41 60
		<g:form action="showGraph" method="GET">
42 61
			<g:hiddenField name="id" value="${params.id}" />
......
47 66
		<br />
48 67
		
49 68
	</erptr:box>
69
	
70
	<g:javascript>
71
	jQuery( function () {
72
		var o;
73
		var num = 1;
74
		var placeholder = plot.getPlaceholder();
75
		var vertica = getMax(plot.getData()[0].datapoints.points);
76
		<g:each in="${actionLog}" var="al1">
77
			o = plot.pointOffset({ x: ${al1.dateRecieved.time}, y: vertica});
78
			placeholder.append("<div style=\"position:absolute;left:" + (o.left + 10) + "px;top:" + o.top + "px;color:red;font-size:smaller\"><a href=\"#\" onclick=\"return false;\" title=\"${al1.reportedData}\">" + num + "</a></div>");
79
			num++;
80
		</g:each>
81
	});
82
	function getMax(points) {
83
		var max = points[1];
84
		for(i = 1; i < points.length; i += 2) {
85
			if(points[i] > max) max = points[i];
86
		}
87
		return max;
88
	}
89
	</g:javascript>
50 90

  
51 91
</body>
52 92

  
hci/trunk/eneraptor-web-app/grails-app/views/statistics/showCombGraph.gsp
10 10

  
11 11
	<erptr:box title="Graph">
12 12
		<g:javascript>
13
			var plot;
13 14
			var data = ${data};
14 15
			var options = {
15 16
				lines: { show: true },
16 17
				points: { show: true },
17 18
				xaxis: { mode: "time", timeformat: "%y/%m/%d %H:%M" },
18
				legend: { container: '#legendHolder' }
19
				legend: { container: '#legendHolder' },
20
				grid: {
21
					markings: [
22
						<g:each in="${actionLog}" var="al">
23
							<g:if test="${al == actionLog[-1]}">
24
								{ color: 'red', lineWidth: 1, xaxis: { from: ${al.dateRecieved.time}, to: ${al.dateRecieved.time} } }
25
							</g:if>
26
							<g:else>
27
								{ color: 'red', lineWidth: 1, xaxis: { from: ${al.dateRecieved.time}, to: ${al.dateRecieved.time} } },
28
							</g:else>
29
						</g:each>
30
					]
31
				}
19 32
			};
20 33
		</g:javascript>
34
		
21 35
		<div class="chart">
22
			<flot:plot id="placeholder" style="width: 900px; height: 300px; padding:5px;" data="data" options="options" />
36
			<div id='placeholder' style='width: 900px; height: 300px; padding:5px;'></div>
37
			<script type='text/javascript'>
38
			jQuery(function (){ 
39
				plot = jQuery.plot(jQuery("#placeholder"),data, options);
40
			});
41
			</script>
23 42
		</div>
43
		
24 44
		<br />
25 45
		<p>Legend:</p>
26 46
		<div id="legendHolder" name="legendHolder"></div>
27 47
		
48
		<table>
49
			<g:set var="al2num" value="0" />
50
			<g:each in="${actionLog}" var="al2">
51
				<tr>
52
					<td style="width:20px;"><p style="color:red;font-size:smaller;">${++al2num}</p></td>
53
					<td style="width:150px;">${al2.dateRecieved}</td>
54
					<td>${al2.reportedData}</td>
55
				</tr>
56
			</g:each>
57
		</table>
58
		
59
		<p>Display actions:</p>
60
		<g:form action="showCombGraph" method="GET">
61
			<g:hiddenField name="id" value="${params.id}" />
62
			<g:select name="outputDevice" from="${outputDevices}" optionKey="deviceId" optionValue="friendlyName" noSelection="['none':'- None -']" style="width:350px;" value="${params.outputDevice}" />
63
			&nbsp;&nbsp;&nbsp;
64
			<g:submitButton name="outputDeviceSubmit" value="Update" />
65
		</g:form>
66
		<br />
67
		
28 68
	</erptr:box>
69
	
70
	<g:javascript>
71
	jQuery( function () {
72
		var o;
73
		var num = 1;
74
		var placeholder = plot.getPlaceholder();
75
		var vertica = getMax(plot.getData()[0].datapoints.points);
76
		<g:each in="${actionLog}" var="al1">
77
			o = plot.pointOffset({ x: ${al1.dateRecieved.time}, y: vertica});
78
			placeholder.append("<div style=\"position:absolute;left:" + (o.left + 10) + "px;top:" + o.top + "px;color:red;font-size:smaller\"><a href=\"#\" onclick=\"return false;\" title=\"${al1.reportedData}\">" + num + "</a></div>");
79
			num++;
80
		</g:each>
81
	});
82
	function getMax(points) {
83
		var max = points[1];
84
		for(i = 1; i < points.length; i += 2) {
85
			if(points[i] > max) max = points[i];
86
		}
87
		return max;
88
	}
89
	</g:javascript>
29 90

  
30 91
</body>
31 92

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff