
package com.uwetrottmann.shopr.algorithm.model;

import com.uwetrottmann.shopr.algorithm.model.Attributes.AttributeValue;

import java.math.BigDecimal;
import java.util.Arrays;

public class Price extends GenericAttribute {

    public static final String ID = "price";

    public enum Value implements AttributeValue {
        SUB_25("less than 25 €"),
        BETWEEN_25_50("25 to 50 €"),
        BETWEEN_50_100("50 to 100 €"),
        ABOVE_100("more than 100 €");

        private String mDescriptor;

        Value(String descriptor) {
            mDescriptor = descriptor;
        }

        @Override
        public String descriptor() {
            return mDescriptor;
        }

        @Override
        public int index() {
            return ordinal();
        }

    }

    public Price() {
        int numValues = Value.values().length;
        mValueWeights = new double[numValues];
        Arrays.fill(mValueWeights, 1.0 / numValues);
    }

    public Price(BigDecimal price) {
        mValueWeights = new double[Value.values().length];
        Arrays.fill(mValueWeights, 0.0);

        // determine price range
        Value value;
        if (price.doubleValue() < 25.0) {
            value = Value.SUB_25;
        } else if (price.doubleValue() < 50.0) {
            value = Value.BETWEEN_25_50;
        } else if (price.doubleValue() < 100.0) {
            value = Value.BETWEEN_50_100;
        } else {
            value = Value.ABOVE_100;
        }

        mValueWeights[value.ordinal()] = 1.0;
        currentValue(value);
    }

    @Override
    public String id() {
        return ID;
    }

    @Override
    public AttributeValue[] getValueSymbols() {
        return Value.values();
    }

    /**
     * Changes the behavior to also increase the weight of neighboring weights.
     * E.g. a user might like items priced in a little more expensive or a
     * little cheaper based on the price range he liked.
     */
    @Override
    public void likeValue(int valueIndex, double[] weights) {
        // TODO Auto-generated method stub
        super.likeValue(valueIndex, weights);
    }

}

@@ -409,15 +409,52 @@
 _50_
+75(%2250 to 75 %E2%82%AC%22),%0A        BETWEEN_75_
 100(%22
+7
 5
-0
  to 
@@ -474,34 +474,114 @@
     
-ABOVE_100(%22more than 100 %E2%82%AC
+BETWEEN_100_150(%22100 to 150 %E2%82%AC%22),%0A        BETWEEN_150_200(%22150 to 200 %E2%82%AC%22),%0A        ABOVE_200(%22200 %E2%82%AC or more
 %22);%0A
@@ -1473,55 +1473,331 @@
 ) %3C 
-100.0) %7B%0A            value = Value.BETWEEN_50_1
+75.0) %7B%0A            value = Value.BETWEEN_50_75;%0A        %7D else if (price.doubleValue() %3C 100.0) %7B%0A            value = Value.BETWEEN_75_100;%0A        %7D else if (price.doubleValue() %3C 150.0) %7B%0A            value = Value.BETWEEN_100_150;%0A        %7D else if (price.doubleValue() %3C 200.0) %7B%0A            value = Value.BETWEEN_150_2
 00;%0A
@@ -1845,17 +1845,17 @@
 e.ABOVE_
-1
+2
 00;%0A    

Add more price regions.