ArchievedFileDataSource.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Aitex.UI.Charting.ViewModel;
  6. using DataAnalysisControl.Core;
  7. using Aitex.DataAnalysis.Core;
  8. namespace Aitex.UI.Charting.Model
  9. {
  10. [Serializable]
  11. public class DataItem
  12. {
  13. public string DataName { get; set; }
  14. //public bool IsPreLoaded { get; set; }
  15. public List<DateTime> TimeStamp { get; set; }
  16. public List<float> RawData { get; set; }
  17. }
  18. [Serializable]
  19. public class ArchivedFile
  20. {
  21. public string ChamId { get; set; }
  22. public string Description { get; set; }
  23. public string WaferDisplayIndex { get; set; }
  24. public DateTime BeginTime { get; set; }
  25. public DateTime EndTime { get; set; }
  26. public Dictionary<string, DataItem> Datas { get; set; }
  27. public Dictionary<string, List<string>> AliasList { get; set; }
  28. //public Dictionary<string, DateTime> EventList { get; set; }
  29. public List<KeyValuePair<DateTime, string>> RecipeSteps { get; set; }
  30. }
  31. public class ArchievedFileDataSource : BaseViewModel, IDataSource
  32. {
  33. public ArchievedFileDataSource(string fileName)
  34. {
  35. try
  36. {
  37. _archieved = ObjectSerializer.DeserializeObjectFromBinaryFile<ArchivedFile>(fileName);
  38. System.IO.FileInfo fi = new System.IO.FileInfo(fileName);
  39. Title = fi.Name;
  40. //填充Datas数据集
  41. Datas = new Dictionary<string, DataItem>();
  42. foreach (var item in _archieved.Datas)
  43. {
  44. Datas.Add(item.Key, new DataItem() { DataName = item.Key, TimeStamp = new List<DateTime>(), RawData = new List<float>() });
  45. }
  46. //填充recipe信息
  47. List<RecipeSyncPoint> recipeInfo = new List<RecipeSyncPoint>();
  48. if (_archieved.RecipeSteps != null)
  49. {
  50. foreach (var item in _archieved.RecipeSteps)
  51. {
  52. recipeInfo.Add(new RecipeSyncPoint() { StepTime = item.Key, StepName = item.Value });// Tuple<DateTime, string>(item.Key, item.Value));
  53. }
  54. }
  55. if (recipeInfo.Count == 0)
  56. {
  57. recipeInfo.Add(new RecipeSyncPoint() { StepTime = DateTime.MinValue, StepName = "NULL" });
  58. }
  59. RecipeSteps = recipeInfo;
  60. SyncPoint = RecipeSteps[0];
  61. TimeMove = new TimeSpan(0);
  62. }
  63. catch (Exception ex)
  64. {
  65. CONTEXT.WriteLog(ex);
  66. }
  67. }
  68. ArchivedFile _archieved;
  69. public ArchivedFile ArchivedFile
  70. {
  71. get
  72. {
  73. return _archieved;
  74. }
  75. }
  76. public Dictionary<string, DataItem> Datas
  77. {
  78. get;
  79. set;
  80. }
  81. public string Title
  82. {
  83. get;
  84. set;
  85. }
  86. public string ChamberName
  87. {
  88. get
  89. {
  90. return _archieved.ChamId;
  91. }
  92. set
  93. {
  94. ;
  95. }
  96. }
  97. public string WaferDisplayIndex
  98. {
  99. get
  100. {
  101. return _archieved!=null?_archieved.WaferDisplayIndex:null;
  102. }
  103. set
  104. {
  105. ;
  106. }
  107. }
  108. public string Description
  109. {
  110. get
  111. {
  112. return _archieved.Description;
  113. }
  114. set
  115. {
  116. ;
  117. }
  118. }
  119. public DateTime BeginTime
  120. {
  121. get
  122. {
  123. return _archieved.BeginTime;
  124. }
  125. set
  126. {
  127. ;
  128. }
  129. }
  130. public DateTime EndTime
  131. {
  132. get
  133. {
  134. return _archieved.EndTime;
  135. }
  136. set
  137. {
  138. ;
  139. }
  140. }
  141. public List<RecipeSyncPoint> RecipeSteps
  142. {
  143. get;
  144. set;
  145. }
  146. public bool GetData(string dataName, DateTime beginTime, DateTime endTime, out DataItem returnDataItem)
  147. {
  148. returnDataItem = new DataItem() { DataName = dataName, TimeStamp = new List<DateTime>(), RawData = new List<float>() };
  149. if (!_archieved.Datas.Keys.Contains(dataName))
  150. return false;
  151. var data = _archieved.Datas[dataName];
  152. int beginIndex = int.MaxValue;
  153. int endIndex = int.MinValue;
  154. for (int i = 0; i < data.TimeStamp.Count - 1; i++)
  155. {
  156. if (data.TimeStamp[i] >= beginTime)
  157. {
  158. beginIndex = i;
  159. break;
  160. }
  161. }
  162. for (int i = data.TimeStamp.Count - 1; i>=0 ; i--)
  163. {
  164. if (endTime >= data.TimeStamp[i])
  165. {
  166. endIndex = i;
  167. break;
  168. }
  169. }
  170. if (beginIndex <= endIndex && beginIndex >= 0 && endIndex <= data.TimeStamp.Count - 1)
  171. {
  172. for (int i = beginIndex; i <= endIndex; i++)
  173. {
  174. returnDataItem.TimeStamp.Add(data.TimeStamp[i]);
  175. returnDataItem.RawData.Add(data.RawData[i]);
  176. }
  177. }
  178. return true;
  179. }
  180. /// <summary>
  181. /// get specific datas from archieved files
  182. /// </summary>
  183. /// <param name="dataNames"></param>
  184. /// <param name="beginTime"></param>
  185. /// <param name="endTime"></param>
  186. /// <param name="returnDataItems"></param>
  187. /// <returns></returns>
  188. public bool GetData(List<string> dataNames, DateTime beginTime, DateTime endTime, out List<DataItem> returnDataItems)
  189. {
  190. returnDataItems = new List<DataItem>();
  191. DataItem di;
  192. foreach (var dataName in dataNames)
  193. {
  194. if (GetData(dataName, beginTime, endTime, out di))
  195. returnDataItems.Add(di);
  196. else
  197. {
  198. returnDataItems = new List<DataItem>();
  199. return false;
  200. }
  201. }
  202. return true;
  203. }
  204. public void Dispose()
  205. {
  206. if (Datas != null)
  207. Datas.Clear();
  208. Datas = null;
  209. if (_archieved != null && _archieved.Datas != null)
  210. _archieved.Datas.Clear();
  211. _archieved = null;
  212. }
  213. public TimeSpan TimeMove
  214. {
  215. get;
  216. set;
  217. }
  218. private RecipeSyncPoint _syncPoint;
  219. public RecipeSyncPoint SyncPoint
  220. {
  221. get
  222. {
  223. return _syncPoint;
  224. }
  225. set
  226. {
  227. if (value != _syncPoint)
  228. {
  229. CommonViewModel.Instance.SyncSourceTime(Title, value.StepTime, value.StepName);
  230. _syncPoint = value;
  231. InvokePropertyChanged("SyncPoint");
  232. }
  233. }
  234. }
  235. }
  236. }