// Calculate correlation between the two sets of values
    public void Button1_Click(object sender, EventArgs e)
    {
        // (OS)
        CorrelatorService service = new CorrelatorService();

        List<OCMRawData> rawdata = service.getRawData(int.Parse(SourceDropDown.SelectedValue), CounterDropDown.SelectedValue, int.Parse(ServerDropDown.SelectedValue));
        List<OCMRawData> rawdata2 = service.getRawData(int.Parse(SourceDropDown2.SelectedValue), CounterDropDown2.SelectedValue, int.Parse(ServerDropDown2.SelectedValue));

        // (AM)
        double[] array1 = colData(rawdata);
        double[] array2 = colData(rawdata2);

        // (AM & OS)
        double[] arr = new double[rawdata.Count];
        double[] arr2 = new double[rawdata2.Count];

        // (The following (START-END) is taken from the following website: http://mantascode.com/c-how-to-get-correlation-coefficient-of-two-arrays/ )
        // What is used to work out one- to- one correlation
        double[] array_xy = new double[arr.Length];
        double[] array_xp2 = new double[arr.Length];
        double[] array_yp2 = new double[arr2.Length];

        for (int i = 0; i < arr.Length; i++)
            array_xy[i] = arr[i] * arr2[i];

        for (int i = 0; i < arr.Length; i++)
            array_xp2[i] = Math.Pow(arr[i], 2.0);

        for (int i = 0; i < arr2.Length; i++)
            array_yp2[i] = Math.Pow(arr2[i], 2.0);

        double sum_x = 0;
        double sum_y = 0;

        foreach (double n in arr)
            sum_x += n;

        foreach (double n in arr2)
            sum_y += n;

        double sum_xy = 0;
        foreach (double n in array_xy)
            sum_xy += n;
        double sum_xpow2 = 0;
        foreach (double n in array_xp2)
            sum_xpow2 += n;
        double sum_ypow2 = 0;
        foreach (double n in array_yp2)
            sum_ypow2 += n;
        double Ex2 = Math.Pow(sum_x, 2.00);
        double Ey2 = Math.Pow(sum_y, 2.00);

        // The actual correlation calculation
        double Correl =
        (arr.Length * sum_xy - sum_x * sum_y) /
        Math.Sqrt((arr.Length * sum_xpow2 - Ex2) * (arr.Length * sum_ypow2 - Ey2));

        // Display correlation coefficient of one to one
        correlationtextbox.Text = ("CORREL : "+ Correl);

        // Idea of correlation algorithm before searching online for help..
        // (OS)

        // strongcorrelation = false

        // get 1st entity instance from user, store in variable
        // get second entity instance from user, store in variable
        // get counter from user, store in variable

        // get total (t) value of each array

        // while traversing through 1st array
             //traverse through second.

        // if 2nd array value is > x and 1st array value > x
        // then increment by 1. increments stored in i

        // then we can say if i > (0.75 x t), 3/4 being the threshold of a somewhat 'good' correlation

        // calculate correlation, store value in variable

        // strongcorrelation = true
    }
    // When server (entity) is changed the values in the 1st list box change
    // (OS)
    public void ServerDropDown_SelectedIndexChanged(object sender, EventArgs e)
    {
        CorrelatorService service = new CorrelatorService();
           ResultsListBox.Items.Clear();

           List<OCMRawData> rawdata = service.getRawData(int.Parse(SourceDropDown.SelectedValue), CounterDropDown.SelectedValue, int.Parse(ServerDropDown.SelectedValue));
           //add items to 1st results list
         foreach (OCMRawData rw in rawdata)
            ResultsListBox.Items.Add(new ListItem(rw.value.ToString()));
    }