package examples.extractor;


import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class RankExtractorUserFeatureV2 {
    public static Map<String, String> getUserRateFeature(Map<String, String> maps) {

        double d;
        Map<String, Double> result = new HashMap<>();
        d = ExtractorUtils.division("u_1day_exp_cnt", "u_1day_click_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_1day_ctr",d);
        }
        d = ExtractorUtils.division("u_1day_exp_cnt", "u_1day_share_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_1day_str",d);
        }
        d = ExtractorUtils.division("u_1day_exp_cnt", "u_1day_return_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_1day_rov",d);
        }
        d = ExtractorUtils.division("u_1day_share_cnt", "u_1day_return_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_1day_ros",d);
        }

        d = ExtractorUtils.division("u_3day_exp_cnt", "u_3day_click_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_3day_ctr",d);
        }
        d = ExtractorUtils.division("u_3day_exp_cnt", "u_3day_share_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_3day_str",d);
        }
        d = ExtractorUtils.division("u_3day_exp_cnt", "u_3day_return_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_3day_rov",d);
        }
        d = ExtractorUtils.division("u_3day_share_cnt", "u_3day_return_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_3day_ros",d);
        }

        d = ExtractorUtils.division("u_7day_exp_cnt", "u_7day_click_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_7day_ctr",d);
        }
        d = ExtractorUtils.division("u_7day_exp_cnt", "u_7day_share_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_7day_str",d);
        }
        d = ExtractorUtils.division("u_7day_exp_cnt", "u_7day_return_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_7day_rov",d);
        }
        d = ExtractorUtils.division("u_7day_share_cnt", "u_7day_return_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_7day_ros",d);
        }

        d = ExtractorUtils.division("u_3month_exp_cnt", "u_3month_click_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_3month_ctr",d);
        }
        d = ExtractorUtils.division("u_3month_exp_cnt", "u_3month_share_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_3month_str",d);
        }
        d = ExtractorUtils.division("u_3month_exp_cnt", "u_3month_return_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_3month_rov",d);
        }
        d = ExtractorUtils.division("u_3month_share_cnt", "u_3month_return_cnt", maps);
        if (!ExtractorUtils.isDoubleEqualToZero(d)){
            result.put("u_3month_ros",d);
        }
        Map<String, String> result2 = new HashMap<>();
        for (Map.Entry<String, Double> entry : result.entrySet()){
            result2.put(entry.getKey(), String.valueOf(entry.getValue()));
        }

        return result2;
    }


    public static Map<String, String> rateFeatureChange(Map<String, Double> maps){
        Map<String, String> result = new HashMap<>();
        for (Map.Entry<String, Double> entry : maps.entrySet()){
            int value = ExtractorUtils.ceilLogRate(entry.getValue());
            result.put(entry.getKey(), String.valueOf(value));
        }
        return result;
    }

    public static Map<String, String> cntFeatureChange(Map<String, String> maps, Set<String> names){
        Map<String, String> result = new HashMap<>();
        for (Map.Entry<String, String> entry : maps.entrySet()){
            if (!names.contains(entry.getKey())){
                continue;
            }
            int value = ExtractorUtils.bucketCnt(Double.valueOf(entry.getValue()));
            result.put(entry.getKey(), String.valueOf(value));
        }
        return result;
    }

}
