static void grade_samples(Dictionary <string, object>[] samples, classify spec) { List <Dictionary <string, object> > report = new List <Dictionary <string, object> >(); foreach (Dictionary <string, object> s in samples) { string g = grade_one_sample(s, spec); //Console.WriteLine($"imei={s["imei"]}, VZW={s["VZW"]}, FD={g}"); if (string.Compare(s["VZW"].ToString(), g) != 0) { s["FD"] = g; report.Add(s); } } // summary Program.logIt($"match rate: {1.0 - 1.0 * report.Count / samples.Length:P2} (total: {samples.Length})"); foreach (Dictionary <string, object> s in report) { Program.logIt($"imei={s["imei"]}, VZW={s["VZW"]}, FD={s["FD"]}"); } }
static string grade_one_sample(Dictionary <string, object> sample, classify spec) { string ret = ""; Program.logIt($"======================> Start grading for device {sample["imei"]} {sample["model"]} {sample["color"]}"); Program.logIt(sample["dump"].ToString()); foreach (string g in grade_level) { Program.logIt($"checking grading for {g}"); grade_item gi = standard.get_grade_item_by_grade(spec, g); if (gi.max_flaws > 0) { if (sample.ContainsKey("all-all-all")) { if ((int)sample["all-all-all"] > gi.max_flaws) { Program.logIt($"Fail to grading for {g}, due to all-all-all={sample["all-all-all"]} > {gi.max_flaws}"); continue; } } } if (gi.max_major_flaws > 0) { if (sample.ContainsKey("all-major-all")) { if ((int)sample["all-major-all"] > gi.max_flaws) { Program.logIt($"Fail to grading for {g}, due to all-major-all={sample["all-major-all"]} > {gi.max_major_flaws}"); continue; } } } if (gi.max_region_flaws > 0) { if (sample.ContainsKey("AA-region-all")) { if ((int)sample["AA-region-all"] > gi.max_flaws) { Program.logIt($"Fail to grading for {g}, due to AA-region-all={sample["AA-region-all"]} > {gi.max_region_flaws}"); continue; } } } foreach (surface_item si in gi.surface) { Program.logIt($"check surface {si.surface} for {g}"); if (si.max_flaws > 0) { if (sample.ContainsKey($"{si.surface}-all-all")) { if ((int)sample[$"{si.surface}-all-all"] > si.max_flaws) { Program.logIt($"Fail to grading for {g}, due to {si.surface}-all-all={sample[$"{si.surface}-all-all"]} > {si.max_flaws}"); break; } } } if (si.max_major_flaws > 0) { if (sample.ContainsKey($"{si.surface}-major-all")) { if ((int)sample[$"{si.surface}-major-all"] > si.max_major_flaws) { Program.logIt($"Fail to grading for {g}, due to {si.surface}-major-all={sample[$"{si.surface}-major-all"]} > {si.max_major_flaws}"); break; } } } if (si.max_region_flaws > 0) { if (sample.ContainsKey($"{si.surface}-region-all")) { if ((int)sample[$"{si.surface}-region-all"] > si.max_region_flaws) { Program.logIt($"Fail to grading for {g}, due to {si.surface}-region-all={sample[$"{si.surface}-region-all"]} > {si.max_region_flaws}"); break; } } } bool all_meet = true; foreach (flaw_allow_item ff in si.flaw_allow) { if (sample.ContainsKey(ff.flaw)) { if ((int)sample[ff.flaw] > ff.allow) { // Program.logIt($"Fail to grading for {g}, due to {si.surface} {ff.flaw}={sample[ff.flaw]} > {ff.allow}"); all_meet = false; } } } if (all_meet) { ret = g; } break; } if (!string.IsNullOrEmpty(ret)) { break; } } if (string.IsNullOrEmpty(ret)) { ret = "D"; } Program.logIt($"======================> Complete grading for device {sample["imei"]}, VZW={sample["VZW"]}, FD={ret}"); return(ret); }