static void test_2() { Dictionary <string, object> all_flaws = new Dictionary <string, object>(); string root = @"C:\Tools\avia\ClassifyLog"; // @"C:\Tools\avia\ClassifyLog"; standard spec = standard.LoadSpec(@"C:\Tools\avia\classify.xml"); Dictionary <string, object> specs = spec.ToDictionary(); foreach (string fn in System.IO.Directory.GetFiles(root, "*.txt")) { flaw df = new flaw(fn); foreach (Dictionary <string, string> f in df.Flaws) { string surface = f["surface"]; string sort = f["sort"]; string k = $"{sort}_{surface}"; if (!all_flaws.ContainsKey(k)) { all_flaws.Add(k, new List <Dictionary <string, object> >()); } List <Dictionary <string, object> > kv = (List <Dictionary <string, object> >)all_flaws[k]; kv.Add(f.ToDictionary(pair => pair.Key, pair => (object)pair.Value)); } } // save json { var jss = new System.Web.Script.Serialization.JavaScriptSerializer(); string s = jss.Serialize(all_flaws); System.IO.File.WriteAllText("all_flaws.json", s); } }
static void ana_A_B() { string sample_folder = @"C:\tools\avia\records"; standard spec = standard.LoadSpec(@"C:\tools\avia\classify_0523_mod.xml"); System.Collections.Specialized.StringDictionary[] vdata = Program.read_verizon_data(); Dictionary <string, object>[] all_data = prep(sample_folder, vdata); var selected_data = from i in all_data where string.Compare(i["VZW"].ToString(), "A") == 0 // || string.Compare(i["VZW"].ToString(), "A+") == 0 select i; /* * int match = 0; * int over = 0; * int under = 0; * foreach(Dictionary<string,object> d in selected_data) * { * string fd = grade_one_sample(d, standard.TheClassify); * int v = Array.IndexOf(grade_level, d["VZW"] as string); * int f = Array.IndexOf(grade_level, fd); * if (v == f) match++; * else if (v > f) over++; * else under++; * } * Program.logIt($"Tested {selected_data.Count()} devices, matching rate={1.0 * match / selected_data.Count():P2}"); * Program.logIt($"OverGrading: {1.0 * over / selected_data.Count():P2}"); * Program.logIt($"UnderGrading: {1.0 * under / selected_data.Count():P2}"); */ //query.Cast<MyEntityType>().ToArray(); grade_samples(selected_data.Cast <Dictionary <string, object> >().ToArray(), standard.TheClassify); }
static void gen_train_data(System.Collections.Specialized.StringDictionary args) { List <Dictionary <string, object> > ret = new List <Dictionary <string, object> >(); string specfn = args.ContainsKey("spec") ? args["spec"] : @"data\classify.xml"; standard spec = standard.LoadSpec(specfn); Dictionary <string, Tuple <int, int> >[] device_data = load_counts_from_folder(args["folder"]); System.Collections.Specialized.StringDictionary[] vdata = read_verizon_data(); string[] keys = load_all_keys(); foreach (Dictionary <string, Tuple <int, int> > r in device_data) { System.Collections.Specialized.StringDictionary v = find_verizon_data_by_last_4_digit(vdata, $"{r["id"].Item1:D4}"); if (v != null && v.ContainsKey("VZW")) { string fd = "Fail"; try { fd = gradeing_label[r["id"].Item2]; } catch (Exception) { } Dictionary <string, object> d = new Dictionary <string, object>(); //d.Add("VZW", Array.IndexOf(gradeing_label, v["VZW"])); d.Add("VZW", v["VZW"]); d.Add("FD", fd); foreach (string k in keys) { if (r.ContainsKey(k)) { d.Add(k, r[k].Item1); } else { d.Add(k, 0); } } ret.Add(d); } } try { var jss = new System.Web.Script.Serialization.JavaScriptSerializer(); //ret = jss.Deserialize<List<Dictionary<string, object>>>(str); string str = jss.Serialize(ret); System.IO.File.WriteAllText(args["output"], str); } catch (Exception) { } }
static void test_1() { System.Collections.Specialized.StringDictionary[] vdata = Program.read_verizon_data(); standard spec = standard.LoadSpec(@"C:\Tools\avia\classify.xml"); Dictionary <string, object> specs = spec.ToDictionary(); //Dictionary<string, object>[] ddata = Program.prep(@"C:\Tools\avia\test", vdata); Dictionary <string, object>[] ddata = Program.prep(@"C:\Tools\avia\ClassifyLog", vdata); // save json { var jss = new System.Web.Script.Serialization.JavaScriptSerializer(); string s = jss.Serialize(ddata); System.IO.File.WriteAllText("temp.json", s); } List <string> keys = new List <string>(); foreach (Dictionary <string, object> d in ddata) { foreach (KeyValuePair <string, object> kvp in d) { if (kvp.Key.StartsWith("Score_")) { if (!keys.Contains(kvp.Key)) { keys.Add(kvp.Key); } } } } List <Dictionary <string, object> > report = new List <Dictionary <string, object> >(); foreach (Dictionary <string, object> d in ddata) { Dictionary <string, object> r = new Dictionary <string, object>(); //r.Add("imei", d["imei"]); //r.Add("VZW", d["VZW"]); r.Add("VZW", Array.IndexOf(gradeing_label, d["VZW"])); foreach (string k in keys) { if (d.ContainsKey(k)) { r.Add(k, d[k]); } else { r.Add(k, 0); } } report.Add(r); } // save json { var jss = new System.Web.Script.Serialization.JavaScriptSerializer(); string s = jss.Serialize(report); System.IO.File.WriteAllText("temp_1.json", s); } // dump foreach (Dictionary <string, object> d in ddata) { StringBuilder sb = new StringBuilder(); sb.Append($"imei={d["imei"]},"); sb.Append($"VZW={d["VZW"]},"); foreach (KeyValuePair <string, object> kvp in d) { if (kvp.Key.StartsWith("Score_")) { sb.Append($"{kvp.Key}={kvp.Value},"); } } System.Console.WriteLine(sb.ToString()); } }