static Dictionary <string, object>[] prep(string folder, System.Collections.Specialized.StringDictionary[] vdata) { List <Dictionary <string, object> > ret = new List <Dictionary <string, object> >(); System.Text.RegularExpressions.Regex r = new Regex(@"classify-(\d{4}).txt"); string root = folder; foreach (string fn in System.IO.Directory.GetFiles(root)) { Match m = r.Match(fn); if (m.Success && m.Groups.Count > 1) { Dictionary <string, object> report = new Dictionary <string, object>(); StringDictionary vd = find_device(vdata, m.Groups[1].Value); System.Console.WriteLine("======================================="); Program.logIt($"Prep device data: imei={vd?["imei"]}, model={vd?["Model"]}, color={vd?["Color"]}"); Program.logIt($"Load device flaws from: {fn}"); flaw f = new flaw(fn); string sdump = f.dump(); // save data in report report.Add("imei", vd?["imei"]); report.Add("model", vd?["Model"]); report.Add("color", vd?["Color"]); report.Add("XPO", vd?["XPO"]); report.Add("VZW", vd?["VZW"]); report.Add("OE", f.Grade); report.Add("dump", sdump); #if false { string[] keys = GradeChecker.Properties.Resources.grade_keys.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); foreach (string k in keys) { int c = 0; if (f.Counts.ContainsKey(k)) { c = f.Counts[k]; } report.Add(k, c.ToString()); } } #else foreach (KeyValuePair <string, Tuple <int, int> > kvp in f.Counts) { report.Add(kvp.Key, kvp.Value.Item1); } #endif ret.Add(report); } } // save //try //{ // var jss = new System.Web.Script.Serialization.JavaScriptSerializer(); // string s = jss.Serialize(ret); // System.IO.File.WriteAllText("samples.json", s); //} //catch (Exception) { } return(ret.ToArray()); }
static Dictionary <string, Tuple <int, int> >[] load_counts_from_folder(string folder) { //string folder = @"C:\Tools\avia\ClassifyLog"; List <Dictionary <string, Tuple <int, int> > > db = new List <Dictionary <string, Tuple <int, int> > >(); foreach (string fn in System.IO.Directory.GetFiles(folder, "*.txt")) { //flaw f = new flaw(@"C:\projects\avia\logfiles\classify-0083.txt"); flaw f = new flaw(fn); f.dump(); //f.recount(); // _counts to json // get last-4-digit string s = System.IO.Path.GetFileNameWithoutExtension(fn); s = s.Substring(s.Length - 4); f.Counts.Add("id", new Tuple <int, int>(Int32.Parse(s), Array.IndexOf(gradeing_label, f.Grade))); db.Add(f.Counts); } return(db.ToArray()); }