tonykang22 / hello-world-auto-store

3 stars 1 forks source link

[common] 오마이집 실결제금액 비교 #144

Open tonykang22 opened 1 year ago

tonykang22 commented 1 year ago

오마이집 실결제금액 비교

개요



실 결제 금액과 비교

판매 현황



비교 기준


전체 비교

Product Name Expected Weight Applied Weight (Actual Weight) Weight Difference Expected Price Actual Price Price Difference
로게인 여성 1 LB 1 LB (1.23 LB) 0 LB $ 6.0 $ 6.0 $ 0.0
솔트 마스크 1 LB 1 LB (0.60 LB) 0 LB $ 6.0 $ 6.0 $ 0.0
로게인 남성 2 LB 3 LB (2.50 LB) -1 LB $ 7.6 $ 9.2 $ -1.6
미녹시딜 남성 2 LB 3 LB (2.50 LB) -1 LB $ 7.6 $ 9.2 $ -1.6
파스타 제면기 4 LB 5 LB (4.20 LB) -1 LB $ 10.8 $ 12.4 $ -1.6
아로마 디퓨저 2 LB 3 LB (2.20 LB) -1 LB $ 7.6 $ 9.2 $ -1.6
밀레 세제 2 LB 8 LB (7.20 LB) -6 LB $ 12.4 $ 17.2 $ -4.8
밀키트 5 LB 4 LB (3.20 LB) 1 LB $ 12.4 $ 10.8 $ +1.6


가격 차이의 원인?

Product Name Expected Weight Applied Weight (Actual Weight) Weight Difference Expected Price Actual Price Price Difference
로게인 남성 2 LB 3 LB (2.50 LB) -1 LB $ 7.6 $ 9.2 $ -1.6
미녹시딜 남성 2 LB 3 LB (2.50 LB) -1 LB $ 7.6 $ 9.2 $ -1.6
파스타 제면기 4 LB 5 LB (4.20 LB) -1 LB $ 10.8 $ 12.4 $ -1.6
아로마 디퓨저 2 LB 3 LB (2.20 LB) -1 LB $ 7.6 $ 9.2 $ -1.6
밀레 세제 2 LB 8 LB (7.20 LB) -6 LB $ 12.4 $ 17.2 $ -4.8
밀키트 5 LB 4 LB (3.20 LB) 1 LB $ 12.4 $ 10.8 $ +1.6




상세히 확인해보면...




productWeight: null ??

Help me Google

image

Google search : B082VMG9DT




Help me Rainforest

image

https://app.rainforestapi.com/playground : B082VMG9DT



다른 상품들은?

로게인 남성

 "specifications": [
            {
                "name": "Is Discontinued By Manufacturer",
                "value": "No"
            },
            {
                "name": "Product Dimensions",
                "value": "6 x 4 x 8 inches; 11.68 Ounces"
            }
    ]



미녹시딜 남성

 "specifications": [
            {
                "name": "Is Discontinued By Manufacturer",
                "value": "No"
            },
            {
                "name": "Package Dimensions",
                "value": "6 x 6 x 6 inches; 2.5 Pounds"
            }
    ]



밀키트

 "specifications": [
            {
                "name": "Is Discontinued By Manufacturer",
                "value": "No"
            },
            {
                "name": "Package Dimensions",
                "value": "12.2 x 8.74 x 7.2 inches; 2.93 Pounds"
            }
    ]



중간 결론



PA 구현

Dimensions



Weight





결론

납득할 만한 오차



밀레 세제?


기존 로직 리팩토링


    private Double mapWeight(AmazonProductResponse dto) {
        String originalWeight = dto.getWeight();
        if (originalWeight != null) {
            return Double.parseDouble(originalWeight.replaceAll("[^\\d.]", ""));
        }

        List<AmazonProductResponse.NameValue> specifications = dto.getSpecifications();

        Double poundsWeightByName = getWeightByName(specifications, "pounds");
        if (poundsWeightByName != null) {
            return poundsWeightByName;
        }
        Double ouncesWeightByName = getWeightByName(specifications, "ounces");
        if (ouncesWeightByName != null) {
            return ounceToPound(ouncesWeightByName);
        }
        Double ouncesWeightByValue = getWeightByValue(specifications, "ounces");
        if (ouncesWeightByValue != null) {
            return ounceToPound(ouncesWeightByValue);
        }
        return getWeightByValue(specifications, "pounds");
    }

    private Double getWeightByName(List<AmazonProductResponse.NameValue> specifications, String weightUnit) {
        List<AmazonProductResponse.NameValue> weightEntry = specifications
                .stream()
                .filter(nv -> nv.getName().toLowerCase().contains("weight"))
                .collect(Collectors.toList());
        if (weightEntry.isEmpty()) {
            return null;
        }
        String originalWeight = weightEntry.stream()
                .findFirst()
                .get()
                .getValue();
        return originalWeight.contains(weightUnit) ? Double.parseDouble(originalWeight.replaceAll("[^\\d.]", "")) : null;
    }

    private Double getWeightByValue(List<AmazonProductResponse.NameValue> specifications, String weightUnit) {
        List<AmazonProductResponse.NameValue> weightEntry = specifications.stream()
                .filter(nv -> nv.getValue().toLowerCase().contains(weightUnit))
                .collect(Collectors.toList());
        if (weightEntry.isEmpty()) {
            return null;
        }
        String originalWeight = weightEntry.stream()
                .findFirst()
                .get()
                .getValue();
        String[] splitValue = originalWeight.split(";");
        return Double.parseDouble(splitValue[splitValue.length - 1].replaceAll("[^\\d.]", ""));
    }

    private Double ounceToPound(Double ounce) {
        return ounce * 0.0625;
    }
tonykang22 commented 1 year ago

조치 사항