Subversion Repositories SmartDukaan

Rev

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

Rev 34681 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 CheckRealmeWarrantyTask {
31
public class CheckRealmeWarrantyTask {
32
 
32
 
33
 
-
 
34
    private static final Logger LOGGER = LogManager.getLogger(CheckRealmeWarrantyTask.class);
33
    private static final Logger LOGGER = LogManager.getLogger(CheckRealmeWarrantyTask.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 207... Line 207...
207
                    }
207
                    }
208
                    driver.get("https://www.realme.com/in/support/phonecheck");
208
                    driver.get("https://www.realme.com/in/support/phonecheck");
209
                }
209
                }
210
                mainCount++;
210
                mainCount++;
211
                remainingImeis = imeis.stream().filter(x -> !dateMap.containsKey(x)).collect(Collectors.toList());
211
                remainingImeis = imeis.stream().filter(x -> !dateMap.containsKey(x)).collect(Collectors.toList());
-
 
212
                if (remainingImeis.isEmpty()) break;
212
            } while (mainCount < 5);
213
            } while (mainCount < 5);
213
        } finally {
214
        } finally {
214
            if (driver != null) {
215
            if (driver != null) {
215
                try {
216
                try {
216
                    driver.quit();  // Always shuts everything down
217
                    driver.quit();  // Always shuts everything down
Line 300... Line 301...
300
        FileUtils.copyFile(screenshot, screenshotLocation);
301
        FileUtils.copyFile(screenshot, screenshotLocation);
301
 
302
 
302
        Mat src = Imgcodecs.imread(fileName);
303
        Mat src = Imgcodecs.imread(fileName);
303
        if (src.empty()) {
304
        if (src.empty()) {
304
            System.err.println("Cannot read image: " + fileName);
305
            System.err.println("Cannot read image: " + fileName);
-
 
306
            new File(fileName).delete();
305
            return null;
307
            return null;
306
        }
308
        }
307
 
309
 
308
        Mat gray = new Mat();
310
        Mat gray = new Mat();
309
        Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
311
        Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
Line 313... Line 315...
313
        Imgproc.HoughCircles(gray, circles, Imgproc.HOUGH_GRADIENT, 1.0,
315
        Imgproc.HoughCircles(gray, circles, Imgproc.HOUGH_GRADIENT, 1.0,
314
                20, // min distance between centers
316
                20, // min distance between centers
315
                100, 20, // param1 (Canny high threshold), param2 (accumulator threshold)
317
                100, 20, // param1 (Canny high threshold), param2 (accumulator threshold)
316
                10, 50); // minRadius, maxRadius (adjust as needed)
318
                10, 50); // minRadius, maxRadius (adjust as needed)
317
 
319
 
318
        if (circles.cols() < 2) return null;
320
        if (circles.cols() < 2) {
-
 
321
            new File(fileName).delete();
-
 
322
            return null;
-
 
323
        }
319
 
324
 
320
        for (int i = 0; i < circles.cols(); i++) {
325
        for (int i = 0; i < circles.cols(); i++) {
321
            double[] c1 = circles.get(0, i);
326
            double[] c1 = circles.get(0, i);
322
            for (int j = i + 1; j < circles.cols(); j++) {
327
            for (int j = i + 1; j < circles.cols(); j++) {
323
                double[] c2 = circles.get(0, j);
328
                double[] c2 = circles.get(0, j);
324
                if (Math.abs(c1[2] - c2[2]) < 3) { // check similar radius
329
                if (Math.abs(c1[2] - c2[2]) < 3) { // check similar radius
-
 
330
                    new File(fileName).delete();
325
                    return new double[] {
331
                    return new double[] {
326
                            c1[0], c2[0] // x-coordinates
332
                            c1[0], c2[0] // x-coordinates
327
                    };
333
                    };
328
                }
334
                }
329
            }
335
            }
330
        }
336
        }
331
 
337
 
-
 
338
        new File(fileName).delete();
332
        return null;
339
        return null;
333
    }
340
    }
334
 
341
 
335
 
342
 
336
}
343
}