private Ecodistrict.Messaging.Output.Outputs CalcCheesePriceKpi(Dictionary <string, Input> indata, CExcel exls) { Ecodistrict.Messaging.Output.Outputs outputs = new Ecodistrict.Messaging.Output.Outputs(); try { foreach (var input in indata) { //Set all input values switch (input.Key) { case "Cheddar_Price": //C3 cell exls.SetCellValue("Sheet1", "C3", input.Value); break; case "Gamle_Ole_Price": exls.SetCellValue("Sheet1", "C4", input.Value); break; case "Vasterbotten_Price": exls.SetCellValue("Sheet1", "C5", input.Value); break; case "Edamer_Price": exls.SetCellValue("Sheet1", "C6", input.Value); break; case "Maasdamer_Price": exls.SetCellValue("Sheet1", "C7", input.Value); break; case "Gouda_Price": exls.SetCellValue("Sheet1", "C8", input.Value); break; default: break; } } //Get the Kpi value var kpiValue = exls.GetCellValue("Sheet1", "C17"); //Put it in the calc result outputs.Add(new Ecodistrict.Messaging.Output.Kpi(kpiValue, "Min Cheese price Kpi", "SEK")); return(outputs); } catch (Exception ex) { throw new Exception(string.Format("Could not calculate the cheese price Kpi!\n{0}", ex)); } }
public void ModelResultTest() { try { // arrange Ecodistrict.Messaging.Output.Outputs outputs = new Ecodistrict.Messaging.Output.Outputs(); outputs.Add(new Ecodistrict.Messaging.Output.Kpi(1, "info", "unit")); ModuleResult mResult = new ModuleResult("moduleId", "variantId", "userId", "KpiId", outputs); string str1 = Serialize.ToJsonString(mResult); // act ModuleResult mResult2 = Deserialize <ModuleResult> .JsonString(str1); string str2 = Serialize.ToJsonString(mResult2); // assert Assert.AreEqual(str1, str2, false, "\nNot Json-serialized or deserialized correctly:\n\n" + str1 + "\n\n" + str2); //TODO is unordered => makes comparisson hard. } catch (Exception ex) { Assert.Fail(ex.Message); } }
static void StartModuleResponseExemple() { //This module's id string moduleId = "foo-bar_cheese-Module-v1-0"; //The dashboard message recieved (as a json-string) string message = "{" + "\"type\": \"request\"," + "\"method\": \"startModule\"," + "\"moduleId\": \"foo-bar_cheese-Module-v1-0\"," + "\"variantId\": \"503f191e8fcc19729de860ea\"," + "\"kpiId\": \"cheese-taste-kpi\"," + "\"inputData\": {" + "\"cheese-type\": \"alp-kase\"," + "\"age\": 2.718" + "}" + "}"; //Message reconstructed into a .Net object. StartModuleRequest recievedMessage = Deserialize <StartModuleRequest> .JsonString(message); //Is this message meant for me? if (recievedMessage.moduleId == moduleId) { //For the selected kpi, create a input specification describing what data //the module need in order to calculate the selected kpi. Ecodistrict.Messaging.Output.Outputs outputs = new Ecodistrict.Messaging.Output.Outputs(); if (recievedMessage.kpiId == "cheese-taste-kpi") { //Inform the dashboard that you have started calculating StartModuleResponse mResponse = new StartModuleResponse( moduleId: recievedMessage.moduleId, variantId: recievedMessage.variantId, caseId: recievedMessage.caseId, userId: recievedMessage.userId, kpiId: recievedMessage.kpiId, status: ModuleStatus.Processing); //Send the response message... //Do your calculations... //Add the result in outputs //E.g. Ecodistrict.Messaging.Output.Output otp = new Ecodistrict.Messaging.Output.Kpi( value: 99, info: "Cheese tastiness", unit: "ICQU (International Cheese Quality Units)"); outputs.Add(otp); } else { //... } //Inform the dashboard of your results ModuleResult mResult = new ModuleResult( moduleId: recievedMessage.moduleId, variantId: recievedMessage.variantId, userId: recievedMessage.userId, kpiId: recievedMessage.kpiId, outputs: outputs); //Send the result message... string resMessage = Serialize.ToJsonString(mResult); Console.WriteLine(resMessage); } }