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); } }
public static void predict_main(System.Collections.Specialized.StringDictionary args) { flaw f = new flaw(args["input"]); string root = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); System.IO.Directory.CreateDirectory(System.IO.Path.Combine(root, "tmp")); try { string[] keys = load_all_keys(); Dictionary <string, object> d = new Dictionary <string, object>(); foreach (string k in keys) { if (f.Counts.ContainsKey(k)) { d.Add(k, f.Counts[k]); } else { d.Add(k, 0); } } var jss = new System.Web.Script.Serialization.JavaScriptSerializer(); //ret = jss.Deserialize<List<Dictionary<string, object>>>(str); string str = jss.Serialize(d); System.IO.File.WriteAllText(System.IO.Path.Combine(root, "tmp", "test.json"), str); int ret; string[] lines = runExe("dotnet.exe", $@"mlApp1.dll predict --input {System.IO.Path.Combine(root, "tmp", "test.json")}", out ret, systemapp: true, workdir: $@"{System.IO.Path.Combine(root, "publish")}"); System.Console.WriteLine($"{string.Join(System.Environment.NewLine, lines)}"); } catch (Exception) { } }
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()); }
static void test() { string fn = @"C:\Tools\avia\ClassifyLog\classify-8738.txt"; flaw f = new flaw(fn); try { string[] keys = load_all_keys(); Dictionary <string, object> d = new Dictionary <string, object>(); foreach (string k in keys) { if (f.Counts.ContainsKey(k)) { d.Add(k, f.Counts[k]); } else { d.Add(k, 0); } } var jss = new System.Web.Script.Serialization.JavaScriptSerializer(); //ret = jss.Deserialize<List<Dictionary<string, object>>>(str); string str = jss.Serialize(d); System.IO.File.WriteAllText(@"C:\Tools\avia\tmp\test.json", str); int ret; string[] lines = runExe("dotnet.exe", @"mlApp1.dll predict --input C:\Tools\avia\tmp\test.json", out ret, systemapp: true, workdir: @"C:\Users\qa\source\repos\mlApp1\mlApp1\bin\Debug\netcoreapp2.2\publish"); // prepare data //ModelInput mi = new ModelInput(); //foreach (PropertyInfo pi in mi.GetType().GetProperties()) //{ // string name = ""; // foreach(var p in pi.CustomAttributes) // { // if (string.Compare(p.AttributeType.Name, "ColumnNameAttribute") == 0) // { // name = p.ConstructorArguments[0].Value?.ToString(); // break; // } // } // if (string.Compare(name, "VZW")==0) // { // pi.SetValue(mi, Array.IndexOf(gradeing_label, "D")); // } // else // { // name = name.Replace('_', '-'); // if (d.ContainsKey(name)) // { // pi.SetValue(mi, d[name]); // } // else // pi.SetValue(mi, 0); // } //} // load model //MLContext mlContext = new MLContext(); //DataViewSchema modelInputSchema; //ITransformer mlModel = mlContext.Model.Load(@"C:\Users\qa\source\repos\mlApp1\mlApp1ML.Model\MLModel.zip", out modelInputSchema); //var predEngine = mlContext.Model.CreatePredictionEngine<ModelInput, ModelOutput>(mlModel); //ModelOutput result = predEngine.Predict(mi); } catch (Exception) { } }