public static bool CompareRecommendation(DecisionEngineCutoff obj, DecisionEngineCutoff another) { if (ReferenceEquals(obj, another)) { return(true); } if ((obj == null) || (another == null)) { return(false); } if (obj.GetType() != another.GetType()) { return(false); } if (decimal.Compare(obj.recommendation, another.recommendation) == 0 && (obj.cutoff_approve1.HasValue && another.cutoff_approve1.HasValue && decimal.Compare(obj.cutoff_approve1.Value, another.cutoff_approve1.Value) == 0) && (obj.cutoff_approve2.HasValue && another.cutoff_approve2.HasValue && decimal.Compare(obj.cutoff_approve2.Value, another.cutoff_approve2.Value) == 0) && (obj.cutoff_reject1.HasValue && another.cutoff_reject1.HasValue && decimal.Compare(obj.cutoff_reject1.Value, another.cutoff_reject1.Value) == 0) && (obj.cutoff_reject2.HasValue && another.cutoff_reject2.HasValue && decimal.Compare(obj.cutoff_reject2.Value, another.cutoff_reject2.Value) == 0) ) { return(true); } return(false); }
void DecisionEngineTest() { SqlDecisionEngineRepository sqlQ = new SqlDecisionEngineRepository(); for (int p = 0; p < 1000; p++) { List <DecisionEngineCutoff> deA = new List <DecisionEngineCutoff>(); for (int i = 1; i < 251; i++) { DecisionEngineCutoff de1 = new DecisionEngineCutoff { proposal_id = 1, subscriber_id = 2000001305, workspace_id = "w2epgxz8w237gjmqdhxyk5u596mrloj0", recommendation = 0.89m, cutoff_approve1 = 1.00m, cutoff_approve2 = 0.69m, cutoff_reject1 = 1.00m, cutoff_reject2 = 0.68m }; de1.proposal_id = (p * 251 + i); deA.Add(de1); } sqlQ.UpdateProposalRecommendationCutoff(deA); } string sjson1_5 = "{\"xtab_data\":{\"columns\":{\"tree\":{\"index\":{\"4\":[4],\"1\":[1],\"3\":[3],\"0\":[0],\"2\":[2]},\"first\":0,\"last\":4,\"children\":[{\"index\":{},\"first\":0,\"last\":0,\"children\":[],\"type\":\"metric\",\"id\":\"0\"},{\"index\":{},\"first\":1,\"last\":1,\"children\":[],\"type\":\"metric\",\"id\":\"1\"},{\"index\":{},\"first\":2,\"last\":2,\"children\":[],\"type\":\"metric\",\"id\":\"2\"},{\"index\":{},\"first\":3,\"last\":3,\"children\":[],\"type\":\"metric\",\"id\":\"3\"},{\"index\":{},\"first\":4,\"last\":4,\"children\":[],\"type\":\"metric\",\"id\":\"4\"}],\"type\":\"root\",\"id\":null},\"lookups\":[{\"4\":\"cutoff_reject2\",\"1\":\"cutoff_approve1\",\"3\":\"cutoff_reject1\",\"0\":\"recommendation\",\"2\":\"cutoff_approve2\"}]},\"data\":[[\"0.81\",\"0.92\",\"0.45\",\"0.07\",\"0.03\"],[\"0.88\",\"0.92\",\"0.45\",\"0.07\",\"0.03\"],[\"0.88\",\"0.92\",\"0.45\",\"0.07\",\"0.03\"],[\"0.45\",\"0.51\",\"0.51\",\"0.51\",\"0.51\"],[\"0.47\",\"0.51\",\"0.51\",\"0.51\",\"0.51\"]],\"overall_size\":{\"columns\":5,\"rows\":5},\"rows\":{\"tree\":{\"index\":{\"123\":[3],\"134\":[2],\"148\":[0],\"140\":[1],\"126\":[4]},\"first\":0,\"last\":4,\"children\":[{\"index\":{\"129\":[0]},\"first\":0,\"last\":0,\"children\":[{\"index\":{\"83\":[0]},\"first\":0,\"last\":0,\"children\":[{\"index\":{},\"first\":0,\"last\":0,\"children\":[],\"type\":\"normal\",\"id\":\"83\"}],\"type\":\"normal\",\"id\":\"129\"}],\"type\":\"normal\",\"id\":\"148\"},{\"index\":{\"129\":[0]},\"first\":1,\"last\":1,\"children\":[{\"index\":{\"83\":[0]},\"first\":1,\"last\":1,\"children\":[{\"index\":{},\"first\":1,\"last\":1,\"children\":[],\"type\":\"normal\",\"id\":\"83\"}],\"type\":\"normal\",\"id\":\"129\"}],\"type\":\"normal\",\"id\":\"140\"},{\"index\":{\"129\":[0]},\"first\":2,\"last\":2,\"children\":[{\"index\":{\"83\":[0]},\"first\":2,\"last\":2,\"children\":[{\"index\":{},\"first\":2,\"last\":2,\"children\":[],\"type\":\"normal\",\"id\":\"83\"}],\"type\":\"normal\",\"id\":\"129\"}],\"type\":\"normal\",\"id\":\"134\"},{\"index\":{\"124\":[0]},\"first\":3,\"last\":3,\"children\":[{\"index\":{\"125\":[0]},\"first\":3,\"last\":3,\"children\":[{\"index\":{},\"first\":3,\"last\":3,\"children\":[],\"type\":\"normal\",\"id\":\"125\"}],\"type\":\"normal\",\"id\":\"124\"}],\"type\":\"normal\",\"id\":\"123\"},{\"index\":{\"124\":[0]},\"first\":4,\"last\":4,\"children\":[{\"index\":{\"125\":[0]},\"first\":4,\"last\":4,\"children\":[{\"index\":{},\"first\":4,\"last\":4,\"children\":[],\"type\":\"normal\",\"id\":\"125\"}],\"type\":\"normal\",\"id\":\"124\"}],\"type\":\"normal\",\"id\":\"126\"}],\"type\":\"root\",\"id\":null},\"lookups\":[{\"123\":\"5785442\",\"134\":\"5698410\",\"148\":\"5698406\",\"140\":\"5698408\",\"126\":\"5788100\"},{\"124\":\"2014916932\",\"129\":\"2000000482\"},{\"83\":\"wdr14s9mh218mcp2im5oatyhx3rky4f3\",\"125\":\"h3lybctesoqtm6g5q84qrh3ol37n4263\"}]},\"offset\":{\"columns\":0,\"rows\":0},\"size\":{\"columns\":5,\"rows\":5}}}"; var res1_5 = JsonConvert.DeserializeObject <ReportData>(sjson1_5); DecisionEngineProcess clTstF = new DecisionEngineProcess(); clTstF.ConvertToDecisionEngineCutoff(res1_5); }
public IEnumerable <DecisionEngineCutoff> ConvertToDecisionEngineCutoff(ReportData reportData) { List <DecisionEngineCutoff> deCutoffCollection = new List <DecisionEngineCutoff>(); if (reportData == null || reportData.xtab_data == null || reportData.xtab_data.data == null) { throw new Exception(string.Format("GoodData Report Result is Empty")); } if (reportData.xtab_data.rows == null || reportData.xtab_data.rows.lookups.Count() < 3 || reportData.xtab_data.rows.tree.children == null || !reportData.xtab_data.rows.tree.children.Any()) { throw new Exception(string.Format("GoodData Report Result is Empty")); } foreach (var rootChild in reportData.xtab_data.rows.tree.children) { DecisionEngineCutoff deCutoff = new DecisionEngineCutoff(); deCutoff.proposal_id = int.Parse(reportData.xtab_data.rows.lookups[0][rootChild.id]); deCutoff.subscriber_id = int.Parse(reportData.xtab_data.rows.lookups[1][rootChild.children[0].id]); deCutoff.workspace_id = reportData.xtab_data.rows.lookups[2][rootChild.children[0].children[0].id]; if (reportData.xtab_data.data[rootChild.first].Count() == 5) { var recomendationString = reportData.xtab_data.data[rootChild.first].First(); decimal recomendationValue; decimal cutoffApprove1Value; decimal cutoffApprove2Value; decimal cutoffReject1Value; decimal cutoffReject2Value; if (!string.IsNullOrWhiteSpace(recomendationString) && decimal.TryParse(recomendationString, NumberStyles.Float, CultureInfo.InvariantCulture, out recomendationValue) && !string.IsNullOrWhiteSpace(reportData.xtab_data.data[rootChild.first][1]) && decimal.TryParse(reportData.xtab_data.data[rootChild.first][1], NumberStyles.Float, CultureInfo.InvariantCulture, out cutoffApprove1Value) && !string.IsNullOrWhiteSpace(reportData.xtab_data.data[rootChild.first][2]) && decimal.TryParse(reportData.xtab_data.data[rootChild.first][2], NumberStyles.Float, CultureInfo.InvariantCulture, out cutoffApprove2Value) && !string.IsNullOrWhiteSpace(reportData.xtab_data.data[rootChild.first][3]) && decimal.TryParse(reportData.xtab_data.data[rootChild.first][3], NumberStyles.Float, CultureInfo.InvariantCulture, out cutoffReject1Value) && !string.IsNullOrWhiteSpace(reportData.xtab_data.data[rootChild.first][4]) && decimal.TryParse(reportData.xtab_data.data[rootChild.first][4], NumberStyles.Float, CultureInfo.InvariantCulture, out cutoffReject2Value)) { deCutoff.recommendation = recomendationValue; deCutoff.cutoff_approve1 = cutoffApprove1Value; deCutoff.cutoff_approve2 = cutoffApprove2Value; deCutoff.cutoff_reject1 = cutoffReject1Value; deCutoff.cutoff_reject2 = cutoffReject2Value; } } deCutoffCollection.Add(deCutoff); } return(deCutoffCollection); }