//TO DO: hard coded right now for 2 lists, generalize this to take any amount //of lists that coincides with the number of users in the party //NOTE: *** Can be done with use of params[] List<T> then indexing list number in function *** public void Comparator(List <string> Stef, List <string> Chris) { //Creates temporary combined list of songs to be used later in function var FullList = new List <string>(); FullList.AddRange(Stef); FullList.AddRange(Chris); //Creates list of unmatched items: Target0 var Target0 = new List <string>(); var firstNotSecond = Stef.Except(Chris).ToList(); var secondNotFirst = Chris.Except(Stef).ToList(); Target0.AddRange(firstNotSecond); Target0.AddRange(secondNotFirst); var Target1 = FullList.Except(Target0).ToList(); //List of Songs that match(1) and do not match(0) with 1's being first in the list TargetList.AddRange(Target1); TargetList.AddRange(Target0); var partition = Partition <string>(TargetList, 100); //Creates comma separated list of Ids to be used in GetFeatures function foreach (var item in partition) { TargetListIds.Add(string.Join(',', item.Select(e => e))); } //Adds to List of Target values that corresponds with the order of TargetList TargetValues.AddRange(Enumerable.Repeat(1, Target1.Count())); TargetValues.AddRange(Enumerable.Repeat(0, Target0.Count())); }
private void GraphUpdate(EventArgs e) { if (_lastGraphUpdate != null && DateTime.Now - _lastGraphUpdate < TimeSpan.FromSeconds(1)) { return; } var eventArgs = (SerialPortEventArgs)e; var moment = _model.DetermineMoment(eventArgs.Left, eventArgs.Right); var t = (DateTime.Now - _t0).TotalSeconds; MomentValues.Add(new MeasureModel(t, moment)); if (MomentValues.Count > 100) { MomentValues.RemoveAt(0); } _model.Training.GenerateTargetAt(t + 50.0, out double target, out double minTarget, out double maxTarget); TargetValues.Add(new MeasureModel(t + 50.0, target)); UpperTargetValues.Add(new MeasureModel(t + 50.0, maxTarget)); LowerTargetValues.Add(new MeasureModel(t + 50.0, minTarget)); if (UpperTargetValues.Count > 100) { TargetValues.RemoveAt(0); LowerTargetValues.RemoveAt(0); UpperTargetValues.RemoveAt(0); } UpdateAxisLimits(t); _lastGraphUpdate = DateTime.Now; }
public Func <TTarget, TSource, TTarget> GetMapperFunc() { ValidateMapping(); var targetParam = Expression.Parameter(typeof(TTarget)); var sourceParam = Expression.Parameter(typeof(TSource)); var setterActions = TargetValues.OrderBy(x => x.PropertyName) .Zip(SourceValues.OrderBy(x => x.PropertyName), (tgt, src) => tgt.CreateSetter(src.CreateGetter())) .Concat(CustomMappings) .Select(x => EnsureReturnsTarget(x)) .ToArray() ; if (!setterActions.Any()) { return((tgt, src) => tgt); } var accumulatedLambda = Expression.Invoke(setterActions.First(), targetParam, sourceParam); foreach (var setterExpr in setterActions.Skip(1)) { accumulatedLambda = Expression.Invoke(setterExpr, accumulatedLambda, sourceParam); } var mapperFunc = Expression.Lambda <Func <TTarget, TSource, TTarget> >(accumulatedLambda, targetParam, sourceParam); return(mapperFunc.Compile()); }
//void Start() //{ // //Changes buffer size when the buffer percentage changes // InvokeRepeating("ChangeBufferSize", _gameManager.ChangeBufferPercentageTime, _gameManager.ChangeBufferPercentageTime); //} void FindComponents() { Values = this; //Finds Game Manager _gameManager = FindObjectOfType <GameManager>(); _stick = FindObjectOfType <Stick>(); //Finds renderer bounds StickmaxX = MyRenderer.bounds.max.x; StickminX = MyRenderer.bounds.min.x; }
private void ValidateMapping() { var targetNames = TargetValues.Select(x => x.PropertyName); var sourceNames = SourceValues.Select(x => x.PropertyName); var unmatchedTargets = targetNames.Except(sourceNames); foreach (var targetProperty in GetUnmappedTargetValues()) { ThrowUnmatchedTarget(targetProperty); } var unmatchedSources = sourceNames.Except(targetNames); foreach (var sourceProperty in unmatchedSources) { ThrowUnmatchedSource(SourceValues.First(x => x.PropertyName == sourceProperty)); } var mismatchedTypes = SourceValues.OrderBy(x => x.PropertyName) .Zip(TargetValues.OrderBy(x => x.PropertyName), (src, tgt) => new { src, tgt }) .Where(x => !x.tgt.ValueType.IsAssignableFrom(x.src.ValueType)); foreach (var mismatch in mismatchedTypes) { var msg = string.Format( "Cannot map [{0}] from [{1}].", mismatch.tgt.Description, mismatch.src.Description ); throw new Exception(msg); } }
public IEnumerable <SourceValue <TSource> > GetUnmappedSourceValues() { var targetValuesByName = TargetValues.ToDictionary(x => x.PropertyName); return(SourceValues.Where(x => !targetValuesByName.ContainsKey(x.PropertyName))); }
public IEnumerable <ITargetValue <TTarget> > GetUnmappedTargetValues() { var sourcesByName = SourceValues.ToDictionary(x => x.PropertyName); return(TargetValues.Where(x => !sourcesByName.ContainsKey(x.PropertyName))); }
public void StartUpdatingSourceWhenTargetChanges() { // We subscribe to the TargetValues and each time we have a new value, we update the source with it TargetValues.Subscribe(newValue => _sourceEndpoint.Value = newValue); }