123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Metis.AutoAnalysis
- {
- public class AIResultReader
- {
- public string LoadGrainResult(string dir, ref List<string> fileList)
- {
- string filename = dir + "\\report.ai";
- if (File.Exists(filename) == false)
- return "";
- using (System.IO.StreamReader _file = System.IO.File.OpenText(filename))
- {
- using (JsonTextReader reader = new JsonTextReader(_file))
- {
- try
- {
- JObject o = (JObject)JToken.ReadFrom(reader);
- JObject arrList = JObject.Parse(o["file_results"].ToString());
- List<string> gradeList = new List<string>();
- foreach (var item in arrList)
- {
- string name = item.Key.ToString();
- string grade = item.Value.ToString();
- if(gradeList.Contains(grade) == false)
- {
- gradeList.Add(grade);
- }
- }
- //获取每个级别的个数
- List<int> gradeCountList = new List<int>();
- for(int i = 0; i < gradeList.Count; i++)
- {
- gradeCountList.Add(0);
- }
- foreach (var item in arrList)
- {
- string grade = item.Value.ToString();
- int pos = gradeList.IndexOf(grade);
- if (pos >= 0)
- {
- gradeCountList[pos]++;
- }
- }
- int maxPos = -1;
- int maxCount = -10000;
- for (int i = 0;i < gradeCountList.Count; i++)
- {
- int count = gradeCountList[i];
- if (count > maxCount)
- {
- maxCount = count;
- maxPos = i;
- }
- }
- string resultGrade = gradeList[maxPos];
- foreach (var item in arrList)
- {
- string name = item.Key.ToString();
- string grade = item.Value.ToString();
- if (grade == resultGrade)
- {
- fileList.Add(name);
- }
- }
- return resultGrade;
- }
- catch (Exception ex)
- {
- }
- }
- }
- return "";
- }
- /// <summary>
- /// 查找最差级别
- /// </summary>
- /// <param name="dir"></param>
- /// <param name="fileList"></param>
- /// <returns></returns>
- public string LoadOnlyResult(string dir)
- {
- string filename = dir + "\\report.ai";
- if (File.Exists(filename) == false)
- return "";
- using (System.IO.StreamReader _file = System.IO.File.OpenText(filename))
- {
- using (JsonTextReader reader = new JsonTextReader(_file))
- {
- try
- {
- JObject o = (JObject)JToken.ReadFrom(reader);
- JObject arrList = JObject.Parse(o["file_results"].ToString());
- List<double> gradeList = new List<double>();
- foreach (var item in arrList)
- {
- string name = item.Key.ToString();
- double grade = (double)item.Value;
- if (gradeList.Contains(grade) == false)
- {
- gradeList.Add(grade);
- }
- }
- gradeList.Sort();
- string resultGrade = gradeList.Last().ToString();
- return resultGrade;
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- }
- }
- }
- return "";
- }
- }
- }
|