-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwaveformmatch.java
More file actions
332 lines (262 loc) · 9.29 KB
/
waveformmatch.java
File metadata and controls
332 lines (262 loc) · 9.29 KB
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
package com.ge.lotus.automation.util;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.TimerTask;
import javax.imageio.ImageIO;
public class WaveformVerify {
TimerTask t;
public boolean verifyFhrListVSC(List<Integer> inputfhrList,String parameterBlocck) {
boolean isfhrListplotted = false;
try {
// Step2: Capture the screen shot ADB Bridge
Thread.currentThread().sleep(30000);
captureTheScreenShot();
Thread.currentThread().sleep(10000);
// Step3: Crop the Image only for VSC Chart
cropImage();
// Step4 Verify the Plotted values Against to the input values
isfhrListplotted = verifyFHRValues(inputfhrList,parameterBlocck);
} catch (Exception e) {
isfhrListplotted = false;
// TODO Auto-generated catch block
e.printStackTrace();
}
return isfhrListplotted;
}
public static void captureTheScreenShot() throws IOException {
try {
Process p = Runtime.getRuntime()
.exec("cmd /c adb shell screencap -p /sdcard/screencap.png && adb pull /sdcard/screencap.png");
} catch (IOException e1) {
System.out.println("Exception Occured while capturing the screenshot");
e1.printStackTrace();
}
System.out.println("ScreenshotCaptured");
}
public static void cropImage() throws IOException {
try{
System.out.println("Cropping ScreenShot");
BufferedImage image = ImageIO.read(new File("screencap.png"));
// create a cropped image from the original image
BufferedImage croppedImage = image.getSubimage(30, 70, 870, 368);
File outputfile = new File("CroppedImage.png");
ImageIO.write(croppedImage, "png", outputfile);
System.out.println("Screenshot cropped with vercites 30, 70, 894, 368");
}catch(IOException ie){
System.out.println("Unable to Crop the image");
ie.printStackTrace();
throw ie;
}
}
public static boolean compareImage(File fileA, File fileB) {
try {
// take buffer data from botm image files //
BufferedImage biA = ImageIO.read(fileA);
DataBuffer dbA = biA.getData().getDataBuffer();
int sizeA = dbA.getSize();
BufferedImage biB = ImageIO.read(fileB);
DataBuffer dbB = biB.getData().getDataBuffer();
int sizeB = dbB.getSize();
// compare data-buffer objects //
int i = 0;
if (sizeA == sizeB) {
for (; i < sizeA; i++) {
if (dbA.getElem(i) != dbB.getElem(i)) {
return false;
}
}
System.out.println("" + ((i / sizeA) * 100));
return true;
} else {
return false;
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("Failed to compare image files ...");
return false;
}
}
public static boolean verifyFHRValues(List<Integer> inputfhrList,String parameterBlocck) throws Exception {
boolean isfhrListplotted = false;
List<Integer> plottedFHRList = null;
BufferedImage image;
int width;
int height;
try {
File input = new File("CroppedImage.png");
image = ImageIO.read(input);
width = image.getWidth();
height = image.getHeight();
System.out.println("RED " + new Color(image.getRGB(798, 54)).getRed());
int inputListIndex = 0;
int stabiliseTime = 60;
Color c = null;
boolean isFirstInputFound = false;
DecimalFormat df = new DecimalFormat("#.00");
double pixelsPerFhr = (double)height/210;
for (int i = 0; i < width; i++) {
plottedFHRList = new ArrayList<Integer>();
for (int j = 0; j < height; j++) {
c = new Color(image.getRGB(i, j));
// System.out.println(c.getRGB())
if(c.getRed() == 0 && c.getBlue() == 0 && c.getGreen() == 0){
}
//US1 Parameter Block
if(parameterBlocck.equals("US1")){
if (Arrays.asList(-16221837, -15959179, -15959435, -15959692, -15959435, -15762057, -15696521,
-15762571, -15565961, -15499912).contains(c.getRGB()) || (c.getRed() <= 50)) {
// System.out.println("RED"+c.getRed()+" Blue
// :"+c.getBlue());
int fhr = (int) ((height - j) / (Double)df.parse( df.format(pixelsPerFhr))) + 30;
plottedFHRList.add(fhr);
}
}else if (parameterBlocck.equals("US2")){
if (c.getBlue() <=20) {
// System.out.println("RED"+c.getRed()+" Blue
// :"+c.getBlue());
Double pixelPerFHRinDouble = (Double)df.parse( df.format(pixelsPerFhr));
int fhr = (int) ((height - j) / pixelPerFHRinDouble) + 30;
plottedFHRList.add(fhr);
}
}
}
int firstFHR =0;
int lastFhr =0;
if (!plottedFHRList.isEmpty()) {
firstFHR = plottedFHRList.get(0);
lastFhr = plottedFHRList.get(plottedFHRList.size() - 1);
if (firstFHR <= (inputfhrList.get(inputListIndex) + 5) && firstFHR >= (inputfhrList.get(inputListIndex) - 5)) {
System.out.println("INPUT VALUE : " + inputfhrList.get(inputListIndex) + " MY TESTCASE PASSED (" + firstFHR + ", " + lastFhr + ")");
stabiliseTime = 0;
if(inputListIndex == 0){
isFirstInputFound = true;
}
if (lastFhr != inputfhrList.get(inputListIndex)) {
if(inputListIndex!= (inputfhrList.size()-1)){
inputListIndex++;
}
}
} else if (lastFhr <= (inputfhrList.get(inputListIndex) + 5)
&& lastFhr >= (inputfhrList.get(inputListIndex) - 5)) {
System.out.println("INPUT VALUE : " + inputfhrList.get(inputListIndex) + " MY TESTCASE PASSED ("
+ firstFHR + ", " + lastFhr + ")");
stabiliseTime = 0;
if(inputListIndex == 0){
isFirstInputFound = true;
}
if(inputListIndex!= (inputfhrList.size()-1)){
inputListIndex++;
}
}else {
if(isFirstInputFound == false)
continue;
if (firstFHR <= (inputfhrList.get(inputListIndex-1) + 5)
&& firstFHR >= (inputfhrList.get(inputListIndex) - 5)) {
stabiliseTime = 0;
continue;
} else if (lastFhr <= (inputfhrList.get(inputListIndex-1) + 5)
&& lastFhr >= (inputfhrList.get(inputListIndex) - 5)) {
stabiliseTime = 0;
continue;
} else if(stabiliseTime <= 52){
stabiliseTime++;
continue;
}else if (stabiliseTime > 52) {
System.out.println("TestCase Failed due to stabilizing time more than 20 Seconds ");
System.out.println("---------------------------------------------------------------");
System.out.println("Input FHR VALUE is : "+inputfhrList.get(inputListIndex));
System.out.println("First FHR VALUE is : "+ firstFHR);
System.out.println("Last FHR VALUE is : "+lastFhr);
System.out.println("---------------------------------------------------------------");
isfhrListplotted =false;
break;
}
}
stabiliseTime++;
isfhrListplotted = true;
} else {
if(isFirstInputFound == false)
continue;
isfhrListplotted = false;
System.out.println("TestCase Failed Because Pen Lift");
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return isfhrListplotted;
}
public void moveFilesToBackup(boolean testCaseResult,List<String> screenShotNames ){
InputStream inStream = null;
OutputStream outStream = null;
Date dNow = new Date( );
SimpleDateFormat ft =
new SimpleDateFormat ("yyyyMMddhhmm");
String time = ft.format(dNow);
final String curDir = System.getProperty("user.dir");
try{
File dir = new File(curDir+"/"+time);
dir.mkdir();
System.out.println(dir);
System.out.println("FolderName : "+dir.getName());
for(String inputFile:screenShotNames){
File afile =new File(inputFile);
File bfile =new File(dir.getName()+"/"+time+""+inputFile);
inStream = new FileInputStream(afile);
outStream = new FileOutputStream(bfile);
byte[] buffer = new byte[1024];
int length;
//copy the file content in bytes
while ((length = inStream.read(buffer)) > 0){
outStream.write(buffer, 0, length);
}
inStream.close();
outStream.close();
//delete the original file
afile.delete();
System.out.println("File is copied successful!");
}
}catch(IOException e){
e.printStackTrace();
}
}
public void writePlottedFHRValuestoFile(String path,String content){
content = content.concat("List of plotted FHR Values : ");
content = content.concat(content.toString()+"\r");
try {
File file = new File(path);
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw;
fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
System.out.println("Done");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
cropImage();
}
}