示例#1
0
        /// <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();
        }
示例#2
0
        public void UpdatePosition(PositionRecord record)
        {
            var persistedRecord = GetPosition(record.Id);

            persistedRecord.UpdateFrom(record);
            _positionRepository.Value.Update(persistedRecord);
        }
示例#3
0
 /// <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);
     }
 }
示例#4
0
        public static PositionRecord CreateRecord(this PositionCreateViewModel model)
        {
            var record = new PositionRecord();

            record.InjectFrom(model);
            return(record);
        }
示例#5
0
        /// <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);
        }
示例#6
0
        public static PositionViewModel CreateAvailablePosition(this PositionRecord model)
        {
            var record = new PositionViewModel();

            record.InjectFrom(model);
            return(record);
        }
示例#7
0
 /// <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);
            }
示例#9
0
 /// <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);
     }
 }
示例#10
0
        /// <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);
            }
        }
示例#11
0
        /// <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);
        }
示例#12
0
        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;
            }
        }
示例#13
0
        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);
        }
示例#14
0
        /// <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);
        }
示例#15
0
 /// <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);
 }
示例#16
0
 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;
     }
 }
示例#17
0
 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;
     }
 }
示例#18
0
        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);
        }
示例#19
0
        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);
        }
示例#20
0
        /// <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);
        }
示例#21
0
        // 这里假设已经挂的单子已经是按最优数量进行处理过,目标是直接挂单
        // 目前对前两层做智能开平,后面的全用开仓单
        // 因为后面的使用平仓单,还要处理复杂的大量开挂单的问题。
        // 实际上不能太深,因为深了占用资金
        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);
        }
示例#22
0
 /// <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>();
 }
示例#23
0
 /// <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);
 }
示例#24
0
 public static void UpdateFrom(this PositionRecord targetRecord, PositionRecord sourceRecord)
 {
     targetRecord.InjectFrom <IgnoreIdConvention>(sourceRecord);
 }
示例#25
0
 public void CreatePosition(PositionRecord record)
 {
     _positionRepository.Value.Create(record);
 }
示例#26
0
        public void DeletePosition(PositionRecord record)
        {
            var persistedRecord = GetPosition(record.Id);

            _positionRepository.Value.Delete(persistedRecord);
        }