private void btnTest_Click(object sender, EventArgs e) { if (isCBR) { CBR cbr = new CBR(); StringBuilder outputString; try { using (StreamWriter outputFile = new StreamWriter(@"TestOutput.csv")) { double avgPercentage = 0; for (int i = 0; i < testCarList.Count; i++) { outputString = new StringBuilder(); double[] prices = cbr.generatePrice(i, testCarList[i]); avgPercentage += calcPercentage(prices); foreach (string attribute in testCarList[i]) { outputString.Append(attribute + ","); } foreach (double price in prices) { outputString.Append(price.ToString() + ","); } outputFile.WriteLine(outputString + "," + calcPercentage(prices).ToString("f2")); } avgPercentage = avgPercentage / testCarList.Count; outputFile.WriteLine(avgPercentage.ToString("f2")); lblPercentage.Text = "Avg deviation from actual price: " + avgPercentage.ToString("f2") + "%"; } } catch (Exception) { lblPercentage.Text = "File I/O Error Occured"; } } else { double avgPercentage = 0.0; int count = 0; foreach (double[] prices in mAnn.test()) { avgPercentage += calcPercentage(prices); count++; } avgPercentage = avgPercentage / count; lblPercentage.Text = "Avg deviation from actual price: " + avgPercentage.ToString("f2") + "%"; } }
private void btnGetPrice(object sender, EventArgs e) { if (cmbSelect.SelectedItem == null) { return; } if (isCBR) { CBR cbr = new CBR(); double[] prices = cbr.generatePrice(cmbSelect.SelectedIndex, testCarList[cmbSelect.SelectedIndex]); lblPrice.Text = "Price Generated: £" + prices[0].ToString(); lblActPrice.Text = "Actual Price: £" + prices[1].ToString(); lblSinglePercentage.Text = "Percentage difference: " + calcPercentage(prices).ToString("f2") + "%"; } else { double[] prices = mAnn.getPrice(cmbSelect.SelectedIndex); lblPrice.Text = "Price Generated: £" + prices[0].ToString("f2"); lblActPrice.Text = "Actual Price: £" + prices[1].ToString(); lblSinglePercentage.Text = "Percentage difference: " + calcPercentage(prices).ToString("f2") + "%"; } }