Subversion Repositories SmartDukaan

Rev

Rev 34680 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34680 Rev 36253
Line 28... Line 28...
28
import java.util.stream.Collectors;
28
import java.util.stream.Collectors;
29
 
29
 
30
@Component
30
@Component
31
public class CheckOppoWarrantyTask {
31
public class CheckOppoWarrantyTask {
32
 
32
 
33
 
-
 
34
    private static final Logger LOGGER = LogManager.getLogger(CheckOppoWarrantyTask.class);
33
    private static final Logger LOGGER = LogManager.getLogger(CheckOppoWarrantyTask.class);
35
 
34
 
-
 
35
    static {
-
 
36
        OpenCV.loadShared();
-
 
37
    }
-
 
38
 
36
    public Map<String, LocalDate> checkWarranty(List<String> imeis) {
39
    public Map<String, LocalDate> checkWarranty(List<String> imeis) {
37
        Map<String, LocalDate> dateMap = new HashMap<>();
40
        Map<String, LocalDate> dateMap = new HashMap<>();
38
        //System.out.println(System.getProperty("os.name"));
-
 
39
        //System.out.println(System.getProperty("os.arch"));
-
 
40
        OpenCV.loadShared();
-
 
41
        LOGGER.info("Initiating webdriver...");
41
        LOGGER.info("Initiating webdriver...");
42
 
42
 
43
        Map<String, Object> prefsMap = new HashMap<>();
43
        Map<String, Object> prefsMap = new HashMap<>();
44
        prefsMap.put("profile.default_content_settings.popups", 0);
44
        prefsMap.put("profile.default_content_settings.popups", 0);
45
        prefsMap.put("download.prompt", false);
45
        prefsMap.put("download.prompt", false);
Line 189... Line 189...
189
                    }
189
                    }
190
                    driver.get("https://support.oppo.com/in/warranty-check/");
190
                    driver.get("https://support.oppo.com/in/warranty-check/");
191
                }
191
                }
192
                mainCount++;
192
                mainCount++;
193
                remainingImeis = imeis.stream().filter(x -> !dateMap.containsKey(x)).collect(Collectors.toList());
193
                remainingImeis = imeis.stream().filter(x -> !dateMap.containsKey(x)).collect(Collectors.toList());
-
 
194
                if (remainingImeis.isEmpty()) break;
194
            } while (mainCount < 5);
195
            } while (mainCount < 5);
195
        } finally {
196
        } finally {
196
            if (driver != null) {
197
            if (driver != null) {
197
                try {
198
                try {
198
                    driver.quit(); //Ensures cleanup even on return or error
199
                    driver.quit(); //Ensures cleanup even on return or error
Line 282... Line 283...
282
        FileUtils.copyFile(screenshot, screenshotLocation);
283
        FileUtils.copyFile(screenshot, screenshotLocation);
283
 
284
 
284
        Mat src = Imgcodecs.imread(fileName);
285
        Mat src = Imgcodecs.imread(fileName);
285
        if (src.empty()) {
286
        if (src.empty()) {
286
            System.err.println("Cannot read image: " + fileName);
287
            System.err.println("Cannot read image: " + fileName);
-
 
288
            new File(fileName).delete();
287
            return null;
289
            return null;
288
        }
290
        }
289
 
291
 
290
        Mat gray = new Mat();
292
        Mat gray = new Mat();
291
        Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
293
        Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
Line 295... Line 297...
295
        Imgproc.HoughCircles(gray, circles, Imgproc.HOUGH_GRADIENT, 1.0,
297
        Imgproc.HoughCircles(gray, circles, Imgproc.HOUGH_GRADIENT, 1.0,
296
                20, // min distance between centers
298
                20, // min distance between centers
297
                100, 20, // param1 (Canny high threshold), param2 (accumulator threshold)
299
                100, 20, // param1 (Canny high threshold), param2 (accumulator threshold)
298
                10, 50); // minRadius, maxRadius (adjust as needed)
300
                10, 50); // minRadius, maxRadius (adjust as needed)
299
 
301
 
300
        if (circles.cols() < 2) return null;
302
        if (circles.cols() < 2) {
-
 
303
            new File(fileName).delete();
-
 
304
            return null;
-
 
305
        }
301
 
306
 
302
        for (int i = 0; i < circles.cols(); i++) {
307
        for (int i = 0; i < circles.cols(); i++) {
303
            double[] c1 = circles.get(0, i);
308
            double[] c1 = circles.get(0, i);
304
            for (int j = i + 1; j < circles.cols(); j++) {
309
            for (int j = i + 1; j < circles.cols(); j++) {
305
                double[] c2 = circles.get(0, j);
310
                double[] c2 = circles.get(0, j);
306
                if (Math.abs(c1[2] - c2[2]) < 3) { // check similar radius
311
                if (Math.abs(c1[2] - c2[2]) < 3) { // check similar radius
-
 
312
                    new File(fileName).delete();
307
                    return new double[] {
313
                    return new double[] {
308
                            c1[0], c2[0] // x-coordinates
314
                            c1[0], c2[0] // x-coordinates
309
                    };
315
                    };
310
                }
316
                }
311
            }
317
            }
312
        }
318
        }
313
 
319
 
-
 
320
        new File(fileName).delete();
314
        return null;
321
        return null;
315
    }
322
    }
316
 
323
 
317
 
324
 
318
}
325
}