/** * Adds a boolean Profile to the state with the given key. If no Profile exists, a new Profile is created * with the corresponding key. If a Profile exists with that key, the Profile is appended onto the end of the Profile. * @param key The key corresponding to the state variable. * @param profIn The Profile to be added to the boolean Profile. */ public void addValue(StateVarKey <Matrix <double> > key, HSFProfile <Matrix <double> > profIn) { HSFProfile <Matrix <double> > valueOut; if (!Mdata.TryGetValue(key, out valueOut)) // If there's no Profile matching that key, insert a new one. { Mdata.Add(key, profIn); } else // Otherwise, add this data point to the existing Profile. { valueOut.Add(profIn); } }
/** * Returns the Mastrix Profile matching the key given. If no Profile is found, it goes back one Event * and checks again until it gets to the initial state. * @param key The Matrix state variable key that is being looked up. * @return The Profile saved in the state. */ public HSFProfile <Matrix <double> > getProfile(StateVarKey <Matrix <double> > key) { HSFProfile <Matrix <double> > valueOut; if (Mdata.Count != 0) { // Are there any Profiles in there? if (Mdata.TryGetValue(key, out valueOut)) //see if our key is in there { return(valueOut); } } return(Previous.getProfile(key)); // This isn't the right profile, go back one and try it out! }
/** * Gets the Matrix value of the state at a certain time. If the exact time is not found, the data is * assumed to be on a zero-order hold, and the last value set is found. * @param key The Matrix state variable key that is being looked up. * @param time The time the value is looked up at. * @return A pair containing the last time the variable was set, and the matrix value. */ public KeyValuePair <double, Matrix <double> > getValueAtTime(StateVarKey <Matrix <double> > key, double time) { HSFProfile <Matrix <double> > valueOut; if (Mdata.Count != 0) { // Are there any Profiles in there? if (Mdata.TryGetValue(key, out valueOut)) //see if our key is in there { return(valueOut.DataAtTime(time)); } } return(Previous.getValueAtTime(key, time)); //either no profiles or none that match our keys, try finding it in the previous one }
/** * Gets the last Matrix value set for the given state variable key in the state. If no value is found * it checks the previous state, continuing all the way to the initial state. * @param key The Matrix state variable key that is being looked up. * @return A pair containing the last time the variable was set, and the Matrix value. */ public KeyValuePair <double, Matrix <double> > getLastValue(StateVarKey <Matrix <double> > key) { HSFProfile <Matrix <double> > valueOut; if (Mdata.Count != 0) { // Are there any Profiles in there? if (Mdata.TryGetValue(key, out valueOut)) //see if our key is in there { return(valueOut.Last()); //found it, return it TODO: return last value or pair? } } return(Previous.getLastValue(key)); //either no profiles or none that match our keys, try finding it in the previous one }
/** * Adds a Matrix Profile value pair to the state with the given key. If no Profile exists, a new Profile is created * with the corresponding key. If a Profile exists with that key, the pair is appended onto the end of the Profile. * Ensure that the Profile is still time ordered if this is the case. * @param key The key corresponding to the state variable. * @param pairIn The pair to be added to the matrix Profile. */ public void addValue(StateVarKey <Matrix <double> > key, KeyValuePair <double, Matrix <double> > pairIn) { HSFProfile <Matrix <double> > valueIn = new HSFProfile <Matrix <double> >(pairIn); HSFProfile <Matrix <double> > valueOut; if (!Mdata.TryGetValue(key, out valueOut)) // If there's no Profile matching that key, insert a new one. { Mdata.Add(key, valueIn); } else // Otherwise, add this data point to the existing Profile. { valueOut.Add(pairIn); //TODO: make sure this is ok. was formally iterator.second.data } }
/** * Sets the Matrix Profile in the state with its matching key. If a Profile is found already under * that key, this will overwrite the old Profile. * @param key The Matrix state variable key that is being set.\ * @param profIn The Matrix Profile being saved. */ public void setProfile(StateVarKey <Matrix <double> > key, HSFProfile <Matrix <double> > profIn) { HSFProfile <Matrix <double> > valueOut; if (!Mdata.TryGetValue(key, out valueOut)) // If there's no Profile matching that key, insert a new one. { Mdata.Add(key, profIn); } else // Otherwise, erase whatever is there, and insert a new one. { Mdata.Remove(key); Mdata.Add(key, profIn); } }
/* * Returns the Matrix Profile for this state and all previous states merged into one Profile * @param key The Matrix state variable key that is being looked up. * @return The full Profile */ public HSFProfile <Matrix <double> > getFullProfile(StateVarKey <Matrix <double> > key) { HSFProfile <Matrix <double> > valueOut = new HSFProfile <Matrix <double> >(); if (Mdata.Count != 0) { // Are there any Profiles in there? if (Mdata.TryGetValue(key, out valueOut)) { //see if our key is in there if (Previous != null) // Check whether we are at the first state { return(HSFProfile <Matrix <double> > .MergeProfiles(valueOut, Previous.getFullProfile(key))); } return(valueOut); } } if (Previous != null) { return(Previous.getFullProfile(key)); // If no data, return profile from previous states } return(valueOut); //return empty profile }
/// <summary> /// Returns the integer Profile matching the key given. If no Profile is found, it goes back one Event /// and checks again until it gets to the initial state. /// </summary> /// <typeparam name="T">The type of the profile we are getting</typeparam> /// <param name="_key">The state variable key that is being looked up.</param> /// <returns>Profile saved in the state.</returns> public HSFProfile <T> GetProfile <T>(StateVarKey <T> _key) { if (_key.GetType() == typeof(StateVarKey <int>)) { HSFProfile <int> valueOut; if (Idata.Count != 0) { // Are there any Profiles in there? if (Idata.TryGetValue(_key, out valueOut)) //see if our key is in there { return((dynamic)valueOut); } } return(Previous.GetProfile(_key)); // This isn't the right profile, go back one and try it out! } else if (_key.GetType() == typeof(StateVarKey <double>)) { HSFProfile <double> valueOut; if (Ddata.Count != 0) { // Are there any Profiles in there? if (Ddata.TryGetValue(_key, out valueOut)) //see if our key is in there { return((dynamic)valueOut); } } return(Previous.GetProfile(_key)); // This isn't the right profile, go back one and try it out! } else if (_key.GetType() == typeof(StateVarKey <bool>)) { HSFProfile <bool> valueOut; if (Ddata.Count != 0) { // Are there any Profiles in there? if (Bdata.TryGetValue(_key, out valueOut)) //see if our key is in there { return((dynamic)valueOut); } } return(Previous.GetProfile(_key)); // This isn't the right profile, go back one and try it out! } else if (_key.GetType() == typeof(StateVarKey <Matrix <double> >)) { HSFProfile <Matrix <double> > valueOut; if (Ddata.Count != 0) { // Are there any Profiles in there? if (Mdata.TryGetValue(_key, out valueOut)) //see if our key is in there { return((dynamic)valueOut); } } return(Previous.GetProfile(_key)); // This isn't the right profile, go back one and try it out! } else if (_key.GetType() == typeof(StateVarKey <Quat>)) { HSFProfile <Quat> valueOut; if (Ddata.Count != 0) { // Are there any Profiles in there? if (Qdata.TryGetValue(_key, out valueOut)) //see if our key is in there { return((dynamic)valueOut); } } return(Previous.GetProfile(_key)); // This isn't the right profile, go back one and try it out! } throw new ArgumentException("Profile Type Not Found"); }