Ejemplo n.º 1
0
 internal ActivityViewModel GetActivityByName(string name, bool AddIfNotFound = false, bool cascadeIfNotFound = false)
 {
     if (name == "")
     {
         return(ActivityViewModel.NullActivity);
     }
     if (!_activityViewModelDict.TryGetValue(name, out ActivityViewModel activityViewModel))
     {
         if (AddIfNotFound)
         {
             appLog.Warn(GetType().ToString(),
                         string.Format("Activity {0} not found. Add temporarily to dataset.", name));
             Activity activity;
             if (cascadeIfNotFound)
             {
                 activity = Dataset.GetActivity(name, true);
             }
             else
             {
                 activity = new Activity()
                 {
                     Name      = name,
                     Color     = Colors.Gray.ToString(),
                     IsIgnored = false,
                     IsNoise   = false
                 };
             }
             activityViewModel = new ActivityViewModel(activity);
             _activityViewModelDict.Add(name, activityViewModel);
         }
         else
         {
             appLog.Warn(GetType().ToString(),
                         string.Format("Activity {0} not found. Return Null Activity.", name));
             activityViewModel = ActivityViewModel.NullActivity;
         }
     }
     return(activityViewModel);
 }
Ejemplo n.º 2
0
 public DatasetEventsViewModel(Dataset dataset)
 {
     Dataset             = dataset;
     EventViewFilter     = new EventViewFilter();
     EventsInView        = new AdvancedCollectionView(_allEventsInView);
     EventsInView.Filter = x => !FilterEvent((SensorEventViewModel)x);
     // Populate Sensor, Resident and Activity Lookup Dictionary
     foreach (Sensor sensor in dataset.Site.Sensors)
     {
         SensorViewModel sensorViewModel = new SensorViewModel(sensor);
         _sensorViewModelDict.Add(sensor.Name, sensorViewModel);
         if (sensorViewModel.SensorCategories.Intersect(activeSensorCategories).Count() > 0)
         {
             _activeSensors.Add(sensorViewModel);
         }
     }
     foreach (Activity activity in dataset.Activities)
     {
         ActivityViewModel activityViewModel = new ActivityViewModel(activity);
         _activityViewModelDict.Add(activity.Name, activityViewModel);
         Activities.Add(activityViewModel);
     }
     Activities.Sort(delegate(ActivityViewModel x, ActivityViewModel y)
     {
         return(x.Name.CompareTo(y.Name));
     });
     foreach (Resident resident in dataset.Residents)
     {
         ResidentViewModel residentViewModel = new ResidentViewModel(resident);
         _residentViewModelDict.Add(resident.Name, residentViewModel);
         Residents.Add(residentViewModel);
     }
     Residents.Sort(delegate(ResidentViewModel x, ResidentViewModel y)
     {
         return(x.Name.CompareTo(y.Name));
     });
     dispatcher = Windows.ApplicationModel.Core.CoreApplication.GetCurrentView().CoreWindow.Dispatcher;
 }
Ejemplo n.º 3
0
 internal async Task RemoveActivityAsync(ActivityViewModel activityViewModel)
 {
     ActivityCollection.Remove(activityViewModel);
     This.Activities.Remove(activityViewModel);
     await This.WriteMetadataToFolderAsync();
 }
Ejemplo n.º 4
0
 internal async Task AddNewActivityAsync(ActivityViewModel activityViewModel)
 {
     ActivityCollectionView.Add(activityViewModel);
     This.Activities.Add(activityViewModel);
     await This.WriteMetadataToFolderAsync();
 }
Ejemplo n.º 5
0
 public async Task ImportAnnotationAsync(StorageFile annotationFile)
 {
     using (var inputStream = await annotationFile.OpenReadAsync())
         using (var classicStream = inputStream.AsStreamForRead())
             using (var streamReader = new StreamReader(classicStream))
             {
                 int      lineNo  = 0;
                 int      idEvent = 0;
                 string[] tokenList;
                 // Make sure Other_Activity exists in dataset metadata.
                 ActivityViewModel curActivity      = GetActivityByName("Other_Activity", true, true);
                 string            curAnnotationTag = "";
                 // Add Other Activity to activity list
                 while (streamReader.Peek() >= 0)
                 {
                     string curEventString = streamReader.ReadLine();
                     if (string.IsNullOrWhiteSpace(curEventString))
                     {
                         continue;
                     }
                     tokenList = curEventString.Split(new char[] { ' ', '\t', ',' });
                     // Get the Date of the String and add to dictionary
                     DateTime curEventTimeTag = DateTime.Parse(tokenList[0] + ' ' + tokenList[1]);
                     // Check the activity label of current event
                     if (tokenList.Length > 4 && !string.IsNullOrWhiteSpace(tokenList[4]))
                     {
                         // Process annotation tag
                         string[] subTokenList = tokenList[4].Split(new char[] { '=' });
                         curActivity = GetActivityByName(subTokenList[0], true, true);
                         // In case the ="begin" part is missing in the annotation
                         if (subTokenList.Length < 2)
                         {
                             if (curAnnotationTag == "\"begin\"")
                             {
                                 curAnnotationTag = "\"end\"";
                             }
                             else
                             {
                                 curAnnotationTag = "\"begin\"";
                             }
                         }
                         else
                         {
                             curAnnotationTag = subTokenList[1];
                         }
                     }
                     // Append Activity
                     while (idEvent < _eventStringList.Count)
                     {
                         // Check datetime of current event
                         SensorEventViewModel sensorEvent = ParseSensorEventFromString(_eventStringList[idEvent]);
                         if (sensorEvent.TimeTag.DateTime <= curEventTimeTag)
                         {
                             sensorEvent.Activity      = curActivity;
                             _eventStringList[idEvent] = sensorEvent.ToString();
                             idEvent++;
                         }
                         else
                         {
                             break;
                         }
                     }
                     // If activity end, update annotation token to OtherActivity
                     if (curAnnotationTag == "\"end\"")
                     {
                         curActivity      = GetActivityByName("Other_Activity");;
                         curAnnotationTag = "";
                     }
                     // Log Token
                     lineNo++;
                 }
             }
     this.IsDatasetModified = true;
     this.IsEventsModified  = true;
 }
Ejemplo n.º 6
0
 public void RemoveActivity(ActivityViewModel activityViewModel)
 {
     _activityCollection.Remove(activityViewModel);
     _Dataset.RemoveActivity(activityViewModel.activity);
 }
Ejemplo n.º 7
0
 public void AddActivity(ActivityViewModel activityViewModel)
 {
     _activityCollection.Add(activityViewModel);
     _Dataset.AddActivity(activityViewModel.activity);
 }