private void UpdatePhoneList(List<MobilePhoneRecommendation> PhoneList) { string evalStr = "(get_mobilephone_list)"; MultifieldValue mv = (MultifieldValue)environment.Eval(evalStr); for (int i = 0; i < mv.Count; i++) { FactAddressValue fv = (FactAddressValue)mv[i]; String sModel = "" ; if ((fv.GetFactSlot("model").GetType().ToString()).Equals("Mommosoft.ExpertSystem.SymbolValue")) sModel = (String)(SymbolValue)fv.GetFactSlot("model"); else if ((fv.GetFactSlot("model").GetType().ToString()).Equals("Mommosoft.ExpertSystem.IntegerValue")) sModel = ((int)(IntegerValue)fv.GetFactSlot("model")).ToString(); float fPrice = (float)(FloatValue)fv.GetFactSlot("price"); //Specs String sBrand = (String)(SymbolValue)fv.GetFactSlot("brand"); String sColor = (String)(SymbolValue)fv.GetFactSlot("color"); float fScreen=(float)(FloatValue)fv.GetFactSlot("screen"); float fWeight = (float)(FloatValue)fv.GetFactSlot("weight"); int iMemory = (int)(IntegerValue)fv.GetFactSlot("memory"); //Features String sOS = (String)(SymbolValue)fv.GetFactSlot("os"); String sBluetooth = (String)(SymbolValue)fv.GetFactSlot("bluetooth"); String sWifi = (String)(SymbolValue)fv.GetFactSlot("wifi"); String sFM = (String)(SymbolValue)fv.GetFactSlot("fm"); //camera int iCameraZoom = (int)(IntegerValue)fv.GetFactSlot("zoom"); float fCameraPixel = (float)(FloatValue)fv.GetFactSlot("pixel"); String sFlash = (String)(SymbolValue)fv.GetFactSlot("flash"); String sVideoHD = (String)(SymbolValue)fv.GetFactSlot("videoHD"); float fWeightage = (float)(FloatValue)fv.GetFactSlot("normalizedWeightage"); MobilePhoneRecommendation a = new MobilePhoneRecommendation(); a.sModel = sModel; a.fPrice = fPrice; a.sBrand = sBrand; a.sColor = sColor; a.fScreen = fScreen; a.fWeight = fWeight; a.iMemory = iMemory; a.sOS = sOS; a.sBluetooth = sBluetooth; a.sWifi = sWifi; a.sFM = sFM; a.iZoom = iCameraZoom; a.fPixel = fCameraPixel; a.sFlash = sFlash; a.sVideoHD = sVideoHD; a.fWeightage = fWeightage; String sAttributeModel = "(model " + a.sModel +")"; String sAttributePrice = "(price " + a.fPrice.ToString() + ")"; String sAttributeBrand = "(brand " + a.sBrand + ")"; String sAttributeColor = "(color " + a.sColor + ")"; String sAttributeScreen = "(screen " + a.fScreen.ToString() + ")"; String sAttributeWeight = "(weight " + a.fWeightage.ToString() + ")"; String sAttributeMemory = "(memory " + a.iMemory.ToString() + ")"; String sAttributeOS = "(os " + a.sOS +")"; String sAttributeBluetooth = "(bluetooth " + a.sBluetooth + ")"; String sAttributeWifi = "(wifi " + a.sWifi + ")"; String sAttributeFM = "(fm " + a.sFM + ")"; String sAttributeZoom = "(zoom " + a.iZoom.ToString() + ")"; String sAttributePixel = "(pixel " + a.fPixel.ToString() + ")"; String sAttributeFlash = "(flash " + a.sFlash + ")"; String sAttributeVideoHD = "(videoHD " + a.sVideoHD + ")"; String sAttributeWeightage = "(weightage " + a.fWeightage.ToString() + ")"; String sFact = "(phone " + sAttributeModel + sAttributePrice + sAttributeBrand + sAttributeColor + sAttributeScreen + sAttributeWeight + sAttributeMemory + sAttributeOS + sAttributeBluetooth + sAttributeWifi + sAttributeFM + sAttributeZoom + sAttributePixel + sAttributeFlash + sAttributeVideoHD + sAttributeWeightage + ")"; a.sFact = sFact; } }
public void testDataGrid() { MobilePhoneRecommendation test = new MobilePhoneRecommendation(); test.fPixel = 1; test.fPrice = 1; test.fScreen = 1; test.fWeight = 1; test.fWeightage = 1; test.iMemory = 1; test.iZoom = 1; test.sBluetooth = "test"; test.sBrand = "testbrand"; test.sFlash = "testflash"; test.sFM="testfm"; test.sModel = "testModel"; test.sOS = "testOS"; test.sVideoHD = "testVid"; test.sWifi = "testwifi"; results.Add(test); }
public void UpdatePhoneGrid(String attribute) { string evalStr = "(update_mobilephone_list " + attribute + ")"; // string evalStr = "(get_weightagephone_list)"; MultifieldValue mv = (MultifieldValue)environment.Eval(evalStr); DataTable testdt = new DataTable(); phase3Results.Clear(); for (int i = 0; i < mv.Count; i++) { String sModel = ""; float fWeightage = 0; FactAddressValue fv = (FactAddressValue)mv[i]; /* * Because the function returns a list of weightage_phone and phone facts so getting the fact slot brand * will throw exception for weightage_phone facts, once thrown will catch and actually assign the model and * weightage values * Hence those weightage_phone facts will be shown on the grid instead. * @kwanghock */ try { String sCehck = (String)(SymbolValue)fv.GetFactSlot("brand"); continue; } catch(Exception exception) { if ((fv.GetFactSlot("model").GetType().ToString()).Equals("Mommosoft.ExpertSystem.SymbolValue")) sModel = (String)(SymbolValue)fv.GetFactSlot("model"); else if ((fv.GetFactSlot("model").GetType().ToString()).Equals("Mommosoft.ExpertSystem.IntegerValue")) sModel = ((int)(IntegerValue)fv.GetFactSlot("model")).ToString(); fWeightage = (float)(FloatValue)fv.GetFactSlot("weightage"); } MobilePhoneRecommendation a = new MobilePhoneRecommendation(); a.sModel = sModel; a.fWeightage = fWeightage; String sAttributeModel = "(model " + a.sModel + ")"; String sAttributeWeightage = "(weightage " + a.fWeightage.ToString() + ")"; String sFact = "(weightage_phone " + sAttributeModel + sAttributeWeightage + ")"; MobileResultDisplay addon = new MobileResultDisplay(); addon.fWeightage = a.fWeightage; addon.sModel = a.sModel; phase3Results.Add(addon); } // Debug purpose // MessageBox.Show(phase3Results.Count.ToString()); testDataGrid(); //dataGridView.Refresh(); // for (int i = 0; i < phase3Results.Count; i++) // { // if (phase3Results.ElementAt(i).fWeightage == 0) // phase3Results.RemoveAt(i); // } dataGridView.DataSource = phase3Results; }
public void InitDataGrid() { string evalStr = "(get_weightagephone_list)"; MultifieldValue mv = (MultifieldValue)environment.Eval(evalStr); DataTable testdt = new DataTable(); phase3Results.Clear(); for (int i = 0; i < mv.Count; i++) { String sModel = ""; float fWeightage = 0; FactAddressValue fv = (FactAddressValue)mv[i]; /* * Because the function returns a list of weightage_phone and phone facts so getting the fact slot brand * will throw exception for weightage_phone facts, once thrown will catch and actually assign the model and * weightage values * Hence those weightage_phone facts will be shown on the grid instead. */ try { String sCehck = (String)(SymbolValue)fv.GetFactSlot("brand"); continue; } catch (Exception exception) { if ((fv.GetFactSlot("model").GetType().ToString()).Equals("Mommosoft.ExpertSystem.SymbolValue")) sModel = (String)(SymbolValue)fv.GetFactSlot("model"); else if ((fv.GetFactSlot("model").GetType().ToString()).Equals("Mommosoft.ExpertSystem.IntegerValue")) sModel = ((int)(IntegerValue)fv.GetFactSlot("model")).ToString(); fWeightage = (float)(FloatValue)fv.GetFactSlot("normalizedWeightage"); } MobilePhoneRecommendation a = new MobilePhoneRecommendation(); a.sModel = sModel; a.fWeightage = fWeightage; String sAttributeModel = "(model " + a.sModel + ")"; String sAttributeWeightage = "(weightage " + a.fWeightage.ToString() + ")"; String sFact = "(weightage_phone " + sAttributeModel + sAttributeWeightage + ")"; MobileResultDisplay addon = new MobileResultDisplay(); addon.fWeightage = a.fWeightage; addon.sModel = a.sModel; phase3Results.Add(addon); } //Convert binding list to list. Sort by weightage in descending order. List<MobileResultDisplay> listConvert = phase3Results.ToList(); listConvert = listConvert.OrderByDescending(x => x.fWeightage).ToList(); phase3Results.Clear(); for (int i = 0; i < listConvert.Count; i++) { phase3Results.Add(listConvert.ElementAt(i)); } dataGridView.DataSource = phase3Results; }