/// <summary> /// Polls for updated data. Because this is an emulator, the next line in the /// record will be used. /// </summary> protected override void pollJointData() { // Clone the current item into this hand, and increase the index Populate(sequence[currentPos++]); // Update the position. PositionRecord pr = PositionParser.GetMatch(this); // Huge ugly if test... // Call the event if this position is recognized, and it's not the same // as the last recognized function. if (pr != null && pr != CurrentPosition && pr != LastPosition) { LastPosition = pr; PositionHasChanged(this, pr); // Check whether any motions have been detected... // There can be multiple matches. List <MotionRecord> matches = MotionParser.GetMatches(pr); foreach (MotionRecord mr in matches) { MotionHasDetected(this, mr); } } CurrentPosition = pr; DataHasUpdated(this); // Check whether we need to stop polling now. checkIfEnded(); }
public void UpdatePosition(PositionRecord record) { var persistedRecord = GetPosition(record.Id); persistedRecord.UpdateFrom(record); _positionRepository.Value.Update(persistedRecord); }
/// <summary> /// Invokes the PositionChanged event. Useful for derived classes. /// </summary> /// <param name="sender">The event's sender. Usually "this".</param> /// <param name="position">The new position.</param> protected void PositionHasChanged(Hand sender, PositionRecord position) { if (PositionChanged != null) { PositionChanged(sender, position); } }
public static PositionRecord CreateRecord(this PositionCreateViewModel model) { var record = new PositionRecord(); record.InjectFrom(model); return(record); }
/// <summary> /// Requests renewed data from the CyberGlove and populates the finger objects with this /// new data. /// </summary> protected virtual void pollJointData() { // Calculate the size of the array. int max = NR_FINGERS * NR_JOINTS + 2; // Create an array of doubles, that will later be filled with joint data. double[] arr = new double[max]; // Poll() fills arr with data and returns the size of the new array. // If that size is not 22, something weird is going on. int size = Poll(this.vhtHand, arr, max); // Fill the hand with data. populate(arr); // Update the position. PositionRecord pr = PositionParser.GetMatch(this); // Huge ugly if test... // Call the event if this position is recognized, and it's not the same // as the last recognized function. if (pr != null && pr != CurrentPosition && pr != LastPosition) { LastPosition = pr; PositionHasChanged(this, pr); // Check whether any motions have been detected... // There can be multiple matches. List <MotionRecord> matches = MotionParser.GetMatches(pr); foreach (MotionRecord mr in matches) { MotionHasDetected(this, mr); } } CurrentPosition = pr; DataHasUpdated(this); }
public static PositionViewModel CreateAvailablePosition(this PositionRecord model) { var record = new PositionViewModel(); record.InjectFrom(model); return(record); }
/// <summary> /// Checks for matches in the entire records list. Matches will invoke events. /// </summary> /// <param name="needle">The PositionRecord that needs to be matched.</param> public static void Match(PositionRecord needle) { foreach (MotionRecord mr in records.Values) { mr.CheckMatched(needle); } }
private static Widget ProcessHeadingClose(Token token, BuilderContext ctx) { var richText = new SelectableText(textSpan: ctx.inline.Pop()); Widget container = null; if (ctx.useNotifyContainer) { var positionRecord = new PositionRecord { title = ctx.title }; container = new NotifyContainer( margin: EdgeInsets.only(top: 40f), child: richText, notifyFn: fn => positionRecord.getPosition = fn ); ctx.positionRecords.Add(positionRecord); } else { container = new Container( margin: EdgeInsets.only(top: 40f), child: richText ); } ctx.Clear(); return(container); }
/// <summary> /// Handler for the hand's PositionChanged event. /// </summary> /// <param name="sender">The hand whose position has changed.</param> /// <param name="position">The newly matched position.</param> private static void positionChanged(Hand sender, PositionRecord position) { if (position.Standalone) { Console.WriteLine("New position: {0}", position.Name); } }
/// <summary> /// Checks whether the positionrecord completes this sequence. /// </summary> /// <param name="current">The current position.</param> /// <returns>Whether this motion has been matched.</returns> public bool CheckMatched(PositionRecord current) { if (current == null) { return(false); } if (Next == current) { this.current++; return(checkEnd()); } else if (this.current == -1) { return(false); } else if (Current.CancelsSequence(current)) { this.current = -1; return(false); } else { return(false); } }
/// <summary> /// Lets the user edit the record in command line. /// </summary> /// <param name="record">The PositionRecord that has been recorded.</param> private static void editRecord(PositionRecord record) { string input = ""; do { Console.WriteLine(record.Name); Console.WriteLine(record.CSV); Console.WriteLine("Anything you still want to do?"); Console.WriteLine(" s : Save record"); Console.WriteLine(" q!: Discard record"); Console.WriteLine(" w: Ignore wrist."); Console.WriteLine(" a: Ignore abductions."); Console.WriteLine(" t: Ignore thumb."); Console.WriteLine(" Enter any number from 0 to 21 to"); Console.WriteLine(" add a joint to the ignore list."); Console.Write(">>> "); input = Console.ReadLine().Trim(); int joint = -1; if (input == "q!") { break; } else if (input == "w") { record.IgnoreWrist(); } else if (input == "t") { record.IgnoreThumb(); } else if (input == "a") { record.IgnoreAbductions(); } else if (input == "s") { PositionParser p = new PositionParser("positions.txt"); Console.WriteLine("Saving record!"); for (int i = 0; i < 22; i++) { Console.WriteLine("[{0,2}]: {1,5} : {2,5}", i, record[i].Value, hand[i].Value); } p.Save(record); break; } else if (Int32.TryParse(input, out joint)) { record.Ignored[joint] = true; } else { Console.WriteLine("Unrecognized command!!"); } } while (true); }
private static IEnumerable <T> GetPositionRecords <T>(IPositionRecordCollection positionRecords) where T : PositionRecord { PositionRecord positionRecord = positionRecords.NextRecord; while (positionRecord != null) { yield return((T)positionRecord); positionRecord = positionRecords.NextRecord; } }
public Navigator() { // start a background task to set the attitude loop // TODO: These attitude & position reader loops should run in the background // Get Heading // NOTE: I'm going to try not using the attitude sensor and rely on the accuracy of the GPS to drive heading changes // attitude.LoopReadPosition(att => lastHeading = att.Heading); // Get Position position.LoopReadPosition(g => gps = g); }
/// <summary> /// Checks for matches based on the current PositionRecord. /// </summary> /// <param name="curr">The current PositionRecord</param> /// <returns>A list of all MotionRecords that have been matched.</returns> public static List <MotionRecord> GetMatches(PositionRecord curr) { List <MotionRecord> rv = new List <MotionRecord>(); foreach (MotionRecord mr in records.Values) { if (mr.CheckMatched(curr)) { rv.Add(mr); } } return(rv); }
/// <summary> /// Whether or not this position would cancel the current sequence. /// </summary> /// <param name="curr">The current position.</param> /// <returns>Whether the sequence's progress will be cancelled by this position's occurrence.</returns> public bool CancelsSequence(PositionRecord curr) { if (this == curr) { return(false); } foreach (PositionRecord pr in transition) { if (pr == curr) { return(false); } } return(true); }
public void StartRewind() { // Debug.Log(previousPositions[previousPositions.Count - 1]); if (previousPositions.Count != 0) { PositionRecord p = previousPositions[previousPositions.Count - 2]; while (previousPositions.Count < 200) { previousPositions.Insert(previousPositions.Count - 1, p); } rigidBody.isKinematic = true; // Debug.Log(previousPositions.Count); isRewinding = true; // rewindStep = 3.0f / previousPositions.Count; // rewindStep = 3.0f / 400; } }
private void Rewind() { if (previousPositions.Count > 0) { PositionRecord p = previousPositions[0]; rigidBody.transform.position = p.position; cameraTransform.rotation = p.rotation; rigidBody.transform.rotation = p.playerRotation; previousPositions.RemoveAt(0); //Debug.Log(previousPositions.Count); } else { Debug.Log("rewind finished"); Debug.Log(previousPositions.Count); isRewinding = false; } }
public void display_date_is_correct(int year, int month, int day, string expectedResult) { DateTime?dt; if (year <= 1) { dt = null; } else { dt = new DateTime(year, month, day); } var classUnderTest = new PositionRecord(); classUnderTest.EndDate = dt; classUnderTest.EndDateDisplay.Should().BeEquivalentTo(expectedResult); }
private async Task <PositionRecord> CreateOrUpdatePositionRecord() { var location = GpsUtilities.GetLocation(); var memberId = _members.Random().Id; var record = await _repository.GetById <PositionRecord>(memberId); if (null == record) { record = new PositionRecord(memberId, location.Latitude, location.Longitude); _loggerFactory.LogInformation($"New Position Record [{memberId}] [{location.Longitude}/{location.Latitude}]"); } else { record.Update(new PositionRecordUpdatedEvent(record.MemberId, location.Latitude, location.Longitude)); _loggerFactory.LogInformation($"Update Position Record [{memberId}] [{location.Longitude}/{location.Latitude}]"); } return(record); }
/// <summary> /// Creates a PositionRecord. /// </summary> /// <param name="p">Parameter, should be the name of the new record.</param> /// <returns></returns> private static bool record(string p) { try { // This requires one parameter that will serve as a name. if (p == null || p == "") { Console.WriteLine("A name for the position in required as parameter."); return(false); } PositionRecord record = new PositionRecord(p); record.CloneData(hand); editRecord(record); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } return(true); }
// 这里假设已经挂的单子已经是按最优数量进行处理过,目标是直接挂单 // 目前对前两层做智能开平,后面的全用开仓单 // 因为后面的使用平仓单,还要处理复杂的大量开挂单的问题。 // 实际上不能太深,因为深了占用资金 public int 单边全面补单(OrderBook_OneSide_Order buy1, OrderBook_OneSide_Size buy2) { int cnt = 0; List <CopyOrder> list = new List <CopyOrder>(); // 方向不对,不可能补单 if (buy1.Side != buy2.Side) { return(cnt); } TextCommon tp = buy1.Side == OrderSide.Buy ? TextParameterBid : TextParameterAsk; PositionRecord LongShort = buy1.Side == OrderSide.Buy ? base.DualPosition.Short : base.DualPosition.Long; lock (this) { int l = 0; // 由于在别的地方做了撤单,在这buy2中的数量是大于等于buy1的 foreach (var b2 in buy2.GridList) { ++l; int level = b2.Key; double size = b2.Value; // 要补单的数量 double leave = size - buy1.SizeByLevel(level); if (leave <= 0) { continue; } double price = PriceHelper.GetPriceByLevel(level); cnt += (int)leave; // 超过两层的全用开仓 if (l > AlwaysOpenIfDepthGreatThan) { tp.OpenClose = EnumOpenClose.OPEN; tp.Text = string.Format("{0}层,开仓补单", l); } else { // 计算开平 double q = CloseTodayHelper.GetCloseAndQty(LongShort, out tp.OpenClose); if (q < leave) { tp.OpenClose = EnumOpenClose.OPEN; tp.Text = string.Format("开仓:可平量{0}<{1}", q, leave); } else { tp.Text = string.Format("平仓:可平量{0}>={1}", q, leave); } } // 入场下单 // 在模拟下,这个地方有可能导致成交回报lock //SendLimitOrder(buy2.Side, leave, price, tp.ToString()); list.Add(new CopyOrder() { Side = buy2.Side, Qty = leave, Price = price, Text = tp.ToString(), }); } } foreach (var o in list) { SendLimitOrder(o.Side, o.Qty, o.Price, o.Text); } return(cnt); }
/// <summary> /// Creates a new SequenceItem with this name. /// </summary> /// <param name="name">The new sequenceitem's name.</param> private SequenceItem(string name) { Position = PositionParser.GetByName(name); transition = new HashSet <PositionRecord>(); leniency = new HashSet <PositionRecord>(); }
/// <summary> /// Adds a position to the transition list. /// </summary> /// <param name="position">The position that's part of the transition from /// this position to the next.</param> public void AddToTransition(PositionRecord position) { transition.Add(position); }
public static void UpdateFrom(this PositionRecord targetRecord, PositionRecord sourceRecord) { targetRecord.InjectFrom <IgnoreIdConvention>(sourceRecord); }
public void CreatePosition(PositionRecord record) { _positionRepository.Value.Create(record); }
public void DeletePosition(PositionRecord record) { var persistedRecord = GetPosition(record.Id); _positionRepository.Value.Delete(persistedRecord); }