summaryrefslogtreecommitdiff
path: root/display_power.html
blob: 78ad4262563c147cbb1481d19ef80aa5d386b52e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<!DOCTYPE html>
<html>
	<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Parsing Large data trace</title>
        <!-- 1. Add JQuery and Highcharts in the head of your page -->
        <script type="text/javascript" src="file:///home/vingu/Tools/Dev/power-tools/jquery-1.11.3.js"></script>
		<script src="file:///home/vingu/Tools/Dev/power-tools/highcharts-custom.js"></script>
         
        <!-- 2. You can add print and export feature by adding this line (now
			    included in custom build above) -->
         
         
        <!-- 3. Add the JavaScript with the Highchart options to initialize the chart -->
		<script type="text/javascript">
            var options = {
                chart: {
					renderTo: 'container',
					zoomType: 'xy',
                    type: 'line'
				},
				navigator: {
					enabled: true
				},
				legend: {
					borderRadius:0,
		            backgroundColor: '#FFFFFF',
				    itemMarginBottom: 7,
		            layout: 'vertical',
				    align: 'left',
		            verticalAlign: 'top',
					enabled: true,
//				    y: 30,
//					x: 2,
		            borderWidth: 0,
//			        width:130,
				    symbolPadding: 10,
					useHTML:true,
					shadow: {
			          color: '#000',
				      width: 3,
					  opacity: 0.15,
				      offsetY: 2,
					  offsetX: 1
				    }
				},
				rangeSelector: {
					enabled: true,
					buttons: [{
						count: 1,
						type: 'millisecond',
						text: '1ms'
					}, {
						count: 100,
						type: 'millisecond',
						text: '100ms'
					}, {
						count: 200,
						type: 'millisecond',
						text: '200ms'
					}, {
						count: 500,
						type: 'millisecond',
						text: '500ms'
					}, {
						count: 1,
						type: 'second',
						text: '1sec'
					}, {
						type: 'all',
						text: 'All'
					}],
				},
				scrollbar: {
					enabled: true
				},
                title: {
                    text: 'Power Consumption or anything else you want to display'                 
                },
                subtitle: {
                    text: 'Current, Watt or whatever the unit'
                },
				yAxis: [{
					title: {
						text : 'Current, Watt or whatever the unit',
					},
				}],
   				xAxis: {
					type: 'datetime',
					labels: {
						formatter: function() {
									   return this.value/1000;
									}
					},
					title: {
						text: 'Time'
					}						   
				},
			//colors: ['#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263',      '#6AF9C4'],
			series: []
			};
			
		var remain = 0;
		var chart = null;

		function drop(e) {

			if (!e) {
			var fichiers = document.getElementById('fileinput').files;
			}
			else {
				var fichiers = e.dataTransfer.files;
			}

			options.series = [];
			options.yAxis = [];
			remain = fichiers.length;

			$.each(fichiers, function(fileNo, file) {
				var reader = new FileReader();
				reader.onerror = function() { console.error('Error reading file');}
				//reader.onload = parse;
				reader.onload = function (event) { 
					return parse(event, fileNo, file.name);
					};
				reader.readAsText(file);
			});


		}

		function parse(event, idx, name){

			var data = event.target.result;			// load file values
            var series = [];
			var stepmode = document.getElementById('step_graph').checked;
			var axismode = document.getElementById('multiple_graph').checked;
			var ext_axismode = document.getElementById('pery_axis_graph').checked;
			var relativemode = document.getElementById('relative_time').checked;
			var decimatemode = document.getElementById('decimate_graph').checked;
			var csvmode = document.getElementById('csv_mode').checked;

			var offset = -1;
			var time_idx = -1;
			var unit_mul = 0;

			if (relativemode == 0)
				offset = 0;

			// Split the lines
            var lines = data.split('\n');
            $.each(lines, function(lineNo, line) {
				if (line.substring(0, 1) == "#")
					return;
				
				var items = [];
				if (csvmode) {
					items = line.split(/,/);
				} else {				
					items = line.split(/  */);
				}
        
                // header line contains names of categories
				if (lineNo == 0) {
					$.each(items, function(itemNo, item) {
						var serie = {
							name : item,
							yAxis : 0,
							step : stepmode,
							data: []
						};

						if (item.match(/time/) != null ) {
							time_idx = itemNo;
							if (item.match(/(uS)/) != null)
								unit_mul = 1;
						}

						if (ext_axismode) {
							// Create an yAxis per chart
							options.yAxis[itemNo] = {
											title: {
												text : item,
											},
											opposite : itemNo % 2 == 1,
										};
							serie.yAxis = itemNo;
						} else if (itemNo == 0)  {
							// Create an yAxis per file
							options.yAxis[idx] = {
											title: {
												text : name,
											},
											opposite : idx % 2 == 1,
							 };

							if (axismode)
								serie.yAxis = idx;
						}

						series.push(serie);
					});
                }
                // the rest of the lines contain data with their name in the first position
				else {
					var Xindex;
					if (decimatemode && ((lineNo % 10) != 0))
						return;
					if (time_idx == -1)
						Xindex = lineNo * 0.0001 * 1000;
					else {
					if (unit_mul == 0)
						Xindex = parseFloat(items[time_idx])*1000;
					else
						Xindex = parseInt(items[time_idx])/1000;
					}
					
					if (offset == -1)
						offset = Xindex;
					
					Xindex = Xindex - offset;

					$.each(items, function(itemNo, item) {
						var Yindex = parseFloat(item);
						if (itemNo == time_idx)
							return;


						var serie = series[itemNo];
						if (isNaN(Yindex) || isNaN(Xindex))
							return;

						var element = [Xindex, Yindex];
						serie.data.push(element);
//						serie.data.push(Yindex);
					});
                }
                     
            });
			
			$.each(series, function(itemNo, item) {
				if (itemNo != time_idx) {
					options.series.push(item);
				} 
			});

			remain--;
			if (remain == 0) {
				display(null);
			}

        };

		function display(e) {
            //putting all together and create the chart
			var chartmode = document.getElementById('stock_graph').checked;
			if (chart)
				chart.destroy();
			if (chartmode) {
				chart = new Highcharts.StockChart(options);
			} else {
				chart = new Highcharts.Chart(options);
			}

		}
		</script>
         
	</head>
	<body>
		<!-- File input filed -->
		<input type='file' name="myFile1" id='fileinput'  onchange='drop()' multiple>
		<input type='checkbox' name="step" value='1' id='step_graph' onchange='drop()'> step
  		<input type='checkbox' name="multiple" value='1' id='multiple_graph' onchange='drop()'> per file Y Axis
  		<input type='checkbox' name="per chart Y-Axis" value='1' id='pery_axis_graph' onchange='drop()'> per chart Y Axis
  		<input type='checkbox' name="decimate" value='1' id='decimate_graph' onchange='drop()'> decimate data
  		<input type='checkbox' name="stock" value='1' id='stock_graph' onchange='drop()'> stock graph
  		<input type='checkbox' name="relative" value='1' id='relative_time' onchange='drop()'> relative time
  		<input type='checkbox' name="csv" value='1' id='csv_mode' onchange='drop()'> csv mode

        <!-- 3. Add the container -->
        <div id="container" style="width: 1800px; height: 1000px; margin: 0 auto"></div>      
                 
    </body>
</html>