123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Aitex.UI.Charting.ViewModel;
- using DataAnalysisControl.Core;
- using Aitex.DataAnalysis.Core;
- namespace Aitex.UI.Charting.Model
- {
- [Serializable]
- public class DataItem
- {
- public string DataName { get; set; }
- //public bool IsPreLoaded { get; set; }
- public List<DateTime> TimeStamp { get; set; }
- public List<float> RawData { get; set; }
- }
- [Serializable]
- public class ArchivedFile
- {
- public string ChamId { get; set; }
- public string Description { get; set; }
- public string WaferDisplayIndex { get; set; }
- public DateTime BeginTime { get; set; }
- public DateTime EndTime { get; set; }
- public Dictionary<string, DataItem> Datas { get; set; }
- public Dictionary<string, List<string>> AliasList { get; set; }
- //public Dictionary<string, DateTime> EventList { get; set; }
- public List<KeyValuePair<DateTime, string>> RecipeSteps { get; set; }
- }
- public class ArchievedFileDataSource : BaseViewModel, IDataSource
- {
- public ArchievedFileDataSource(string fileName)
- {
- try
- {
- _archieved = ObjectSerializer.DeserializeObjectFromBinaryFile<ArchivedFile>(fileName);
- System.IO.FileInfo fi = new System.IO.FileInfo(fileName);
- Title = fi.Name;
- //填充Datas数据集
- Datas = new Dictionary<string, DataItem>();
- foreach (var item in _archieved.Datas)
- {
- Datas.Add(item.Key, new DataItem() { DataName = item.Key, TimeStamp = new List<DateTime>(), RawData = new List<float>() });
- }
- //填充recipe信息
- List<RecipeSyncPoint> recipeInfo = new List<RecipeSyncPoint>();
- if (_archieved.RecipeSteps != null)
- {
- foreach (var item in _archieved.RecipeSteps)
- {
- recipeInfo.Add(new RecipeSyncPoint() { StepTime = item.Key, StepName = item.Value });// Tuple<DateTime, string>(item.Key, item.Value));
- }
- }
- if (recipeInfo.Count == 0)
- {
- recipeInfo.Add(new RecipeSyncPoint() { StepTime = DateTime.MinValue, StepName = "NULL" });
- }
- RecipeSteps = recipeInfo;
- SyncPoint = RecipeSteps[0];
- TimeMove = new TimeSpan(0);
- }
- catch (Exception ex)
- {
- CONTEXT.WriteLog(ex);
- }
- }
- ArchivedFile _archieved;
- public ArchivedFile ArchivedFile
- {
- get
- {
- return _archieved;
- }
- }
- public Dictionary<string, DataItem> Datas
- {
- get;
- set;
- }
- public string Title
- {
- get;
- set;
- }
- public string ChamberName
- {
- get
- {
- return _archieved.ChamId;
- }
- set
- {
- ;
- }
- }
- public string WaferDisplayIndex
- {
- get
- {
- return _archieved!=null?_archieved.WaferDisplayIndex:null;
- }
- set
- {
- ;
- }
- }
- public string Description
- {
- get
- {
- return _archieved.Description;
- }
- set
- {
- ;
- }
- }
- public DateTime BeginTime
- {
- get
- {
- return _archieved.BeginTime;
- }
- set
- {
- ;
- }
- }
- public DateTime EndTime
- {
- get
- {
- return _archieved.EndTime;
- }
- set
- {
- ;
- }
- }
- public List<RecipeSyncPoint> RecipeSteps
- {
- get;
- set;
- }
- public bool GetData(string dataName, DateTime beginTime, DateTime endTime, out DataItem returnDataItem)
- {
- returnDataItem = new DataItem() { DataName = dataName, TimeStamp = new List<DateTime>(), RawData = new List<float>() };
- if (!_archieved.Datas.Keys.Contains(dataName))
- return false;
- var data = _archieved.Datas[dataName];
- int beginIndex = int.MaxValue;
- int endIndex = int.MinValue;
- for (int i = 0; i < data.TimeStamp.Count - 1; i++)
- {
- if (data.TimeStamp[i] >= beginTime)
- {
- beginIndex = i;
- break;
- }
- }
- for (int i = data.TimeStamp.Count - 1; i>=0 ; i--)
- {
- if (endTime >= data.TimeStamp[i])
- {
- endIndex = i;
- break;
- }
- }
- if (beginIndex <= endIndex && beginIndex >= 0 && endIndex <= data.TimeStamp.Count - 1)
- {
- for (int i = beginIndex; i <= endIndex; i++)
- {
- returnDataItem.TimeStamp.Add(data.TimeStamp[i]);
- returnDataItem.RawData.Add(data.RawData[i]);
- }
- }
- return true;
- }
- /// <summary>
- /// get specific datas from archieved files
- /// </summary>
- /// <param name="dataNames"></param>
- /// <param name="beginTime"></param>
- /// <param name="endTime"></param>
- /// <param name="returnDataItems"></param>
- /// <returns></returns>
- public bool GetData(List<string> dataNames, DateTime beginTime, DateTime endTime, out List<DataItem> returnDataItems)
- {
- returnDataItems = new List<DataItem>();
- DataItem di;
- foreach (var dataName in dataNames)
- {
- if (GetData(dataName, beginTime, endTime, out di))
- returnDataItems.Add(di);
- else
- {
- returnDataItems = new List<DataItem>();
- return false;
- }
- }
- return true;
- }
- public void Dispose()
- {
- if (Datas != null)
- Datas.Clear();
- Datas = null;
- if (_archieved != null && _archieved.Datas != null)
- _archieved.Datas.Clear();
- _archieved = null;
- }
- public TimeSpan TimeMove
- {
- get;
- set;
- }
- private RecipeSyncPoint _syncPoint;
- public RecipeSyncPoint SyncPoint
- {
- get
- {
- return _syncPoint;
- }
- set
- {
- if (value != _syncPoint)
- {
- CommonViewModel.Instance.SyncSourceTime(Title, value.StepTime, value.StepName);
- _syncPoint = value;
- InvokePropertyChanged("SyncPoint");
- }
- }
- }
- }
- }
|