<commit_before>start_date = '13-01-14';
$(function () {
    var chart;
    var current_view = "weekly";
    //TODO Remove this line when the method is fixed
    response.start_of_year = '2013-01-01';

    weekly_view_chart = new ReportChart(current_view);
    cumulative_view_chart = new ReportChart("cumulative");
    inventory_positions = response.inventory_positions;
    default_series = [inventory_chart_object(inventory_positions)];
    date_date = '17-01-14';
    series = {"weekly":[
        {
            name:'Weekly Forecast',
            <%#color: '#FF33CC',%>
            type:'line',
            yAxis:0,
            data:response.weekly_revenue
        },
        {
            name:'Weekly Margin',
            <%#color: '#0033CC',%>
            type:'line',
            yAxis:0,
            data:response.weekly_margin
        },
        {
            name:'Sales Last Year',
            color:'#8B2500',
            type:'line',
            yAxis:0,
            data:response.weekly_last_year_revenue
        },
        {
            name:'Weekly Target Revenue',
            <%#color: '#003333',%>
            type:'line',
            yAxis:0,
            data:response.weekly_target_revenue

        }
    ],
        "cumulative":[
            {
                name:'Target Sale for Period',
                color:'#89A54E',
                type:'line',
                yAxis:0,
                data:[response.sum_target_revenue, response.sum_target_revenue, response.sum_target_revenue, response.sum_target_revenue, response.sum_target_revenue, response.sum_target_revenue]
            },
            {
                name:'Sales Last Year',
                color:'#8B2500',
                type:'line',
                yAxis:0,
                data:response.cumulative_last_year_revenue
            },
            {
                name:'Margin',
                color:'#CC0033',
                type:'line',
                yAxis:0,
                data:response.cumulative_weekly_margin
            },
            {
                name:'Forecast',
                color:'#A54E89',
                type:'line',
                yAxis:0,
                data:response.cumulative_weekly_revenue

    }]
    };

    $('#toggle').buttonset();
    $('#back-forward').buttonset();
    $('#simulate-button').buttonset();

    $('#weekly_view').click(weekly_view);
    $('#cumulative_view').click(cumulative_view);
    $("#simulate").click(function(){

      var promotion_data=[];
      var h = $("#slider").children();
      h.each(function(index, value) {
        start_class = h[index].className=="date-start";
        end_class = h[index].className=="date-end";
        if(start_class)
          {
           date_data = {};
           start_date = h[index].textContent;
           date_data.start_date = get_date(start_date);
          }
        else if(end_class)
          {
            end_date= h[index].textContent;
            console.log("end_date" + end_date);
            date_data.end_date = get_date(end_date);
            promotion_type = $("#promotion_type"+end_date).val();
            date_data.promotion_type = promotion_type ;
            promotion_percentage =  $("#promotion_percentage"+end_date).val();
            date_data.promotion_percentage = get_promotion_percentage(promotion_type,promotion_percentage);
            promotion_data.push(date_data);
          }
      });
            console.log(promotion_data);

            var send_data = {
            forecast_date: response.date_of_forecast,
            product_id: response.product_id,
            promotion_data: promotion_data
        };
console.log(send_data);

        $.ajax({
            url: "/admin/promotion_simulator/simulate/",
            dataType: 'json',
            type: 'GET',
            data: send_data,
            success: function(response) {
                show_sales_statistics(response.stats_report);
                if(current_view == "cumulative"){
                    weekly_view_chart.create_or_replace("Simulated Sales", response.weekly_simulated_revenue);
                    weekly_view_chart.create_or_replace("Simulated Margin", response.weekly_simulated_margin);
                    cumulative_view_chart.create_or_replace("Cumulative Simulated Sales", response.cumulative_simulated_revenue);
                    cumulative_view_chart.create_or_replace("Cumulative Simulated Margin", response.cumulative_simulated_margin);
                    set_inventory_data(response.simulated_inventory_positions,cumulative_view_chart);
                }
                else if(current_view == "weekly"){
                    cumulative_view_chart.create_or_replace("Cumulative Simulated Sales", response.cumulative_simulated_revenue);
                    cumulative_view_chart.create_or_replace("Cumulative Simulated Margin", response.cumulative_simulated_margin);
                    weekly_view_chart.create_or_replace("Simulated Sales", response.weekly_simulated_revenue);
                    weekly_view_chart.create_or_replace("Simulated Margin", response.weekly_simulated_margin);
                    set_inventory_data(response.simulated_inventory_positions,weekly_view_chart);
                }
                else
                    {
                        console.log("Invalid View!!");
                    }
            }
        });
    });

    set_inventory_data = function(positions,chart_type){
        chart_type.create_or_replace("Inventory",positions);
    }
    function inventory_chart_object(inventory_positions){
        return { name: 'Inventory', type: 'column', yAxis: 0, data: weekly_view_chart.inventory_chart_object(inventory_positions)};
    }

    get_date = function(day){
      var a = convert_day_to_date(day, response.date_of_forecast);
      b = new Date(a);
      c = b.format("yy-mm-dd");
      return c;
    }

    convert_day_to_date = function(day, start_date){
      date1 = new Date(start_date);
      e = date1.getDate();
      y = parseInt(e) + parseInt(day);
      g = date1.setDate(y);
      return g;
    };

    get_promotion_percentage = function(type,value){
      if(type=="P")
        return value;
      else if(type=="Q"){
        return 50;
      }
    };
<commit_msg>Accounting to replenishments in simulate get request<commit_after>start_date = '13-01-14';
$(function () {
    var chart;
    var current_view = "weekly";
    //TODO Remove this line when the method is fixed
    response.start_of_year = '2013-01-01';

    weekly_view_chart = new ReportChart(current_view);
    cumulative_view_chart = new ReportChart("cumulative");
    inventory_positions = response.inventory_positions;
    default_series = [inventory_chart_object(inventory_positions)];
    date_date = '17-01-14';
    series = {"weekly":[
        {
        name:'Weekly Forecast',
        <%#color: '#FF33CC',%>
        type:'line',
        yAxis:0,
        data:response.weekly_revenue
    },
    {
        name:'Weekly Margin',
        <%#color: '#0033CC',%>
        type:'line',
        yAxis:0,
        data:response.weekly_margin
    },
    {
        name:'Sales Last Year',
        color:'#8B2500',
        type:'line',
        yAxis:0,
        data:response.weekly_last_year_revenue
    },
    {
        name:'Weekly Target Revenue',
        <%#color: '#003333',%>
        type:'line',
        yAxis:0,
        data:response.weekly_target_revenue

    }
    ],
    "cumulative":[
        {
        name:'Target Sale for Period',
        color:'#89A54E',
        type:'line',
        yAxis:0,
        data:[response.sum_target_revenue, response.sum_target_revenue, response.sum_target_revenue, response.sum_target_revenue, response.sum_target_revenue, response.sum_target_revenue]
    },
    {
        name:'Sales Last Year',
        color:'#8B2500',
        type:'line',
        yAxis:0,
        data:response.cumulative_last_year_revenue
    },
    {
        name:'Margin',
        color:'#CC0033',
        type:'line',
        yAxis:0,
        data:response.cumulative_weekly_margin
    },
    {
        name:'Forecast',
        color:'#A54E89',
        type:'line',
        yAxis:0,
        data:response.cumulative_weekly_revenue

    }]
    };

    $('#toggle').buttonset();
    $('#back-forward').buttonset();
    $('#simulate-button').buttonset();

    $('#weekly_view').click(weekly_view);
    $('#cumulative_view').click(cumulative_view);
    $("#simulate").click(function(){

        var promotion_data=[];
        var h = $("#slider").children();
        h.each(function(index, value) {
            start_class = h[index].className=="date-start";
            end_class = h[index].className=="date-end";
            if(start_class)
                {
                    date_data = {};
                    start_date = h[index].textContent;
                    date_data.start_date = get_date(start_date);
                }
                else if(end_class)
                    {
                        end_date= h[index].textContent;
                        console.log("end_date" + end_date);
                        date_data.end_date = get_date(end_date);
                        promotion_type = $("#promotion_type"+end_date).val();
                        date_data.promotion_type = promotion_type ;
                        promotion_percentage =  $("#promotion_percentage"+end_date).val();
                        date_data.promotion_percentage = get_promotion_percentage(promotion_type,promotion_percentage);
                        promotion_data.push(date_data);
                    }
        });
        var replenishment = [];
        slider_replenishments = $('.replenishment-select-box').children();
        for(i in slider_replenishments){
            replenishment.push(slider_replenishments[i].value);
        }
        console.log(promotion_data);
        var send_data = {
            forecast_date: response.date_of_forecast,
            product_id: response.product_id,
            promotion_data: promotion_data,
            replenishment: replenishment
        };
        console.log(send_data);

        $.ajax({
            url: "/admin/promotion_simulator/simulate/",
            dataType: 'json',
            type: 'GET',
            data: send_data,
            success: function(response) {
                show_sales_statistics(response.stats_report);
                if(current_view == "cumulative"){
                    weekly_view_chart.create_or_replace("Simulated Sales", response.weekly_simulated_revenue);
                    weekly_view_chart.create_or_replace("Simulated Margin", response.weekly_simulated_margin);
                    cumulative_view_chart.create_or_replace("Cumulative Simulated Sales", response.cumulative_simulated_revenue);
                    cumulative_view_chart.create_or_replace("Cumulative Simulated Margin", response.cumulative_simulated_margin);
                    set_inventory_data(response.simulated_inventory_positions,cumulative_view_chart);
                }
                else if(current_view == "weekly"){
                    cumulative_view_chart.create_or_replace("Cumulative Simulated Sales", response.cumulative_simulated_revenue);
                    cumulative_view_chart.create_or_replace("Cumulative Simulated Margin", response.cumulative_simulated_margin);
                    weekly_view_chart.create_or_replace("Simulated Sales", response.weekly_simulated_revenue);
                    weekly_view_chart.create_or_replace("Simulated Margin", response.weekly_simulated_margin);
                    set_inventory_data(response.simulated_inventory_positions,weekly_view_chart);
                }
                else
                    {
                        console.log("Invalid View!!");
                    }
            }
        });
    });

    set_inventory_data = function(positions,chart_type){
        chart_type.create_or_replace("Inventory",positions);
    }
    function inventory_chart_object(inventory_positions){
        return { name: 'Inventory', type: 'column', yAxis: 0, data: weekly_view_chart.inventory_chart_object(inventory_positions)};
    }

    get_date = function(day){
        var a = convert_day_to_date(day, response.date_of_forecast);
        b = new Date(a);
        c = b.format("yy-mm-dd");
        return c;
    }

    convert_day_to_date = function(day, start_date){
        date1 = new Date(start_date);
        e = date1.getDate();
        y = parseInt(e) + parseInt(day);
        g = date1.setDate(y);
        return g;
    };

    get_promotion_percentage = function(type,value){
        if(type=="P")
            return value;
        else if(type=="Q"){
            return 50;
        }
    };

{'fraction_non_alphanumeric': 0.11299079392556456, 'fraction_numerical': 0.010701077976237311, 'mean_word_length': 2.0413974635080163, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1367624', 'n_tokens_mistral': 3820, 'n_tokens_neox': 3615, 'n_words': 504}