public static FactorManagerStatItem[] ParseFromFile(string path) { var results = new List <FactorManagerStatItem>(); string[] lines = File.ReadAllLines(path); var idxByName = new Dictionary <string, int>(); int idx = 0; foreach (var line in lines) { idx++; if (string.IsNullOrWhiteSpace(line)) { continue; } string[] blocks = line.ToLower().Split(';'); if (idx == 1) //header { for (int j = 0; j < blocks.Length; j++) { string lname = blocks[j].Trim(); if (!idxByName.ContainsKey(lname)) { idxByName.Add(lname, j); } } continue; } var item = new FactorManagerStatItem(); item.Factor1 = GetStringValue(blocks, "factor1", idxByName); item.Factor2 = GetStringValue(blocks, "factor2", idxByName); item.S1 = GetDoubleValue(blocks, "s1", idxByName); item.S2 = GetDoubleValue(blocks, "s2", idxByName); item.S3 = GetDoubleValue(blocks, "s3", idxByName); item.Chi2 = GetDoubleValue(blocks, "chi2", idxByName); item.Chi2Coeff = GetDoubleValue(blocks, "chi2coeff", idxByName); item.CorrAbs = GetDoubleValue(blocks, "corrabs", idxByName); item.InfValue = GetDoubleValue(blocks, "inf_val", idxByName); results.Add(item); } return(results.ToArray()); }
public static FactorManagerStatItem[] ParseFromFile(string path) { var results = new List<FactorManagerStatItem>(); string[] lines = File.ReadAllLines(path); var idxByName = new Dictionary<string, int>(); var nameByIdx = new Dictionary<int, string>(); int idx = 0; foreach (var line in lines) { idx++; if (string.IsNullOrWhiteSpace(line)) continue; string[] blocks = line.ToLower().Split(';'); if (idx == 1) //header { for (int j = 0; j < blocks.Length; j++) { string lname = blocks[j].Trim(); if (!idxByName.ContainsKey(lname)) idxByName.Add(lname, j); } continue; } var item = new FactorManagerStatItem(); item.Factor1 = GetStringValue(blocks, "factor1", idxByName); item.Factor2 = GetStringValue(blocks, "factor2", idxByName); item.S1 = GetDoubleValue(blocks, "s1", idxByName); item.S2 = GetDoubleValue(blocks, "s2", idxByName); item.S3 = GetDoubleValue(blocks, "s3", idxByName); item.Chi2 = GetDoubleValue(blocks, "chi2", idxByName); item.Chi2Coeff = GetDoubleValue(blocks, "chi2coeff", idxByName); item.CorrAbs = GetDoubleValue(blocks, "corrabs", idxByName); item.InfValue = GetDoubleValue(blocks, "inf_val", idxByName); results.Add(item); } return results.ToArray(); }
public void Load(string path, string target = "target", string measureFiled = "Chi2Coeff") { TargetField = target.ToLower(); MeasureField = measureFiled; Items = FactorManagerStatItem.ParseFromFile(path); FactorDict = new Dictionary <string, Dictionary <string, FactorManagerStatItem> >(); foreach (var item in Items) { double measure = GetMeasureValue(item); if (!FactorDict.ContainsKey(item.Factor1)) { FactorDict.Add(item.Factor1, new Dictionary <string, FactorManagerStatItem>()); } if (!FactorDict[item.Factor1].ContainsKey(item.Factor2)) { FactorDict[item.Factor1].Add(item.Factor2, item); } if (!FactorDict.ContainsKey(item.Factor2)) { FactorDict.Add(item.Factor2, new Dictionary <string, FactorManagerStatItem>()); } if (!FactorDict[item.Factor2].ContainsKey(item.Factor1)) { FactorDict[item.Factor2].Add(item.Factor1, item); } if (item.Factor1 == TargetField || item.Factor2 == TargetField) { if (!_tdList.ContainsKey(measure)) { _tdList.Add(measure, 1); } else { _tdList[measure]++; } } else if (!_pdList.ContainsKey(measure)) { _pdList.Add(measure, 1); } else { _pdList[measure]++; } } if (!FactorDict.ContainsKey(TargetField)) { FactorDict.Add(TargetField, new Dictionary <string, FactorManagerStatItem>()); } if (!FactorDict[TargetField].ContainsKey(TargetField)) { FactorDict[TargetField].Add(TargetField, new FactorManagerStatItem()); } //FactorDict[TargetField][TargetField].Chi2Coeff = 0; SetVisibleFactors(FactorDict.Keys.ToArray()); }