Beispiel #1
0
        /// <summary>Registers the label.</summary>
        /// <param name="id">The identifier.</param>
        /// <param name="state">The state.</param>
        /// <param name="year">The year.</param>
        /// <returns>A JSON encoded success indicator</returns>
        public JsonResult RegisterLabel(int id, int state, int year)
        {
            try
            {
                var picolContext = new PicolEntities();

                StateRecord record = new StateRecord();
                record.LabelId  = id;
                record.StateId  = state;
                record.Year     = year;
                record.AgencyId = string.Empty;
                record.Version  = "-1";
                record.Pdf      = DateTime.Now;
                picolContext.StateRecords.Add(record);
                picolContext.SaveChanges();

                return(new JsonNetResult {
                    Data = new { Error = false }, MaxJsonLength = int.MaxValue, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            catch (Exception e)
            {
                // Signal the error to be logged by elmah
                ErrorSignal.FromCurrentContext().Raise(e);
                return(new JsonNetResult {
                    Data = new { Error = true, ErrorMessage = "Failed to update file." }, MaxJsonLength = int.MaxValue, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
        }
        // gets best move AFTER an iteration has been completed
        private UTTTMove GetBestMove()
        {
            StateRecord rec = new StateRecord();

            statesSeen.TryGetValue(startState.GetHashCode(), out rec);
            return(rec.bestMove);
        }
Beispiel #3
0
        /// <param name="parentPath"></param>
        /// <param name="caState"></param>
        /// <param name="lNum">レイヤー番号</param>
        /// <param name="smNum">ステートマシン番号</param>
        /// <param name="sNum">ステート番号</param>
        /// <returns></returns>
        public override bool OnState(string parentPath, ChildAnimatorState caState, int lNum, int smNum, int sNum)
        {
            StateRecord stateRecord = StateRecord.CreateInstance(
                lNum,
                smNum,
                sNum,
                parentPath,
                caState, AconDocument.positions);

            AconDocument.states.Add(stateRecord);

            // モーション・スキャン
            if (null != caState.state.motion)
            {
                Motion motion    = caState.state.motion;
                string assetPath = AssetDatabase.GetAssetPath(motion.GetInstanceID());
                //ebug.Log(" motion.GetType()=[" + motion.GetType().ToString() + "] assetPath=["+ assetPath + "]");

                if (m_motionCounter_.ContainsKey(assetPath))
                {
                    // 既存のモーションを複数回使うことはある。
                    m_motionCounter_[assetPath].CountOfAttachDestination++;
                }
                else
                {
                    m_motionCounter_.Add(assetPath, new MotionRecord.Wrapper(caState.state.motion, 1));
                }
            }

            return(true);
        }
Beispiel #4
0
 /// <summary>
 /// Interpolate between two StateRecords.
 /// </summary>
 /// <param name="A">A.</param>
 /// <param name="B">B.</param>
 /// <param name="t">T, the interpolation factor in range [0..1]</param>
 public static StateRecord Interpolate(StateRecord A, StateRecord B, float t)
 {
     var sr = new StateRecord();
     sr.Position = A.Position + (B.Position - A.Position)*t;
     sr.Rotation = Quaternion.Slerp(A.Rotation, B.Rotation, t);
     sr.GameTime = A.GameTime + (B.GameTime - A.GameTime)*t;
     return sr;
 }
Beispiel #5
0
    /// <summary>
    /// Interpolate between two StateRecords.
    /// </summary>
    /// <param name="A">A.</param>
    /// <param name="B">B.</param>
    /// <param name="t">T, the interpolation factor in range [0..1]</param>
    public static StateRecord Interpolate(StateRecord A, StateRecord B, float t)
    {
        var sr = new StateRecord();

        sr.Position = A.Position + (B.Position - A.Position) * t;
        sr.Rotation = Quaternion.Slerp(A.Rotation, B.Rotation, t);
        sr.GameTime = A.GameTime + (B.GameTime - A.GameTime) * t;
        return(sr);
    }
Beispiel #6
0
    public static StateRecord SerialiseFromString(string text)
    {
        var sr = new StateRecord();
        var sp = text.Split (new char[]{' '});

        sr.Position = new Vector3(float.Parse (sp[0]), float.Parse (sp[1]), float.Parse (sp[2]));
        sr.Rotation = new Quaternion(float.Parse (sp[3]), float.Parse (sp[4]), float.Parse (sp[5]), float.Parse (sp[6]));
        sr.GameTime = float.Parse(sp[7]);

        return sr;
    }
Beispiel #7
0
    public static StateRecord SerialiseFromString(string text)
    {
        var sr = new StateRecord();
        var sp = text.Split(new char[] { ' ' });

        sr.Position = new Vector3(float.Parse(sp[0]), float.Parse(sp[1]), float.Parse(sp[2]));
        sr.Rotation = new Quaternion(float.Parse(sp[3]), float.Parse(sp[4]), float.Parse(sp[5]), float.Parse(sp[6]));
        sr.GameTime = float.Parse(sp[7]);

        return(sr);
    }
Beispiel #8
0
    public void TakeSample(Flow.ITransient sender)
    {
        var sr = new StateRecord (this);
        _samples.Add(sr);

        //		if (MarkerPrefab != null)
        //		{
        //			var marker = (GameObject)Instantiate(MarkerPrefab);
        //			marker.transform.position = sr.Position;
        //			marker.transform.rotation = sr.Rotation;
        //		}
    }
Beispiel #9
0
    public void TakeSample(Flow.ITransient sender)
    {
        var sr = new StateRecord(this);

        _samples.Add(sr);

//		if (MarkerPrefab != null)
//		{
//			var marker = (GameObject)Instantiate(MarkerPrefab);
//			marker.transform.position = sr.Position;
//			marker.transform.rotation = sr.Rotation;
//		}
    }
Beispiel #10
0
    public void CreateFromString(string text)
    {
        var lines = text.Split(new char[] { '\n' });
        var count = int.Parse(lines[0]);
        var list  = new List <StateRecord>();

        for (var n = 1; n < count; ++n)
        {
            list.Add(StateRecord.SerialiseFromString(lines[n]));
        }

        _samples = list;
    }
Beispiel #11
0
        private SerializableTimeSeriesData ReadCurrentTimeSeriesData(string idList)
        {
            try
            {
                // Abort if services is not enabled.
                if (!Enabled)
                {
                    return(null);
                }

                // Ensure that data archive is available.
                if (Archive == null)
                {
                    throw new ArgumentNullException("Archive");
                }

                // Read current time-series data from the archive.
                int         id     = 0;
                byte[]      buffer = null;
                StateRecord state  = null;
                SerializableTimeSeriesData             data   = new SerializableTimeSeriesData();
                List <SerializableTimeSeriesDataPoint> points = new List <SerializableTimeSeriesDataPoint>();
                foreach (string singleID in idList.Split(',', ';'))
                {
                    buffer = Archive.ReadStateData(id = int.Parse(singleID));
                    if ((object)buffer == null)
                    {
                        // ID is invalid.
                        continue;
                    }
                    else
                    {
                        // Add to resultset.
                        state = new StateRecord(id, buffer, 0, buffer.Length);
                        points.Add(new SerializableTimeSeriesDataPoint(state.CurrentData));
                    }
                }
                data.TimeSeriesDataPoints = points.ToArray();

                return(data);
            }
            catch (Exception ex)
            {
                // Notify about the encountered processing exception.
                OnServiceProcessException(ex);
                throw;
            }
        }
Beispiel #12
0
    void SetGhostPlayerTransform(StateRecord prev, StateRecord next)
    {
        var p = next.Position;
        var r = next.Rotation;
        if (prev != null)
        {
            var dt = next.GameTime - prev.GameTime;
            var a = (GameTime - prev.GameTime)/dt;

            p = prev.Position + (next.Position - prev.Position)*a;
            r = Quaternion.Slerp(prev.Rotation, next.Rotation, a);
        }

        transform.position = p;
        transform.rotation = r;
    }
        /// <param name="parentPath"></param>
        /// <param name="caState"></param>
        /// <param name="lNum">レイヤー番号</param>
        /// <param name="smNum">ステートマシン番号</param>
        /// <param name="sNum">ステート番号</param>
        /// <returns></returns>
        public override bool OnState(string parentPath, ChildAnimatorState caState, int lNum, int smNum, int sNum)
        {
            StateRecord stateRecord = StateRecord.CreateInstance(
                lNum,
                smNum,
                sNum,
                parentPath,
                caState, AconDocument.positions);

            AconDocument.states.Add(stateRecord);

            // モーション・スキャン
            motionScanner.OnState(caState);

            return(true);
        }
Beispiel #14
0
    void SetGhostPlayerTransform(StateRecord prev, StateRecord next)
    {
        var p = next.Position;
        var r = next.Rotation;

        if (prev != null)
        {
            var dt = next.GameTime - prev.GameTime;
            var a  = (GameTime - prev.GameTime) / dt;

            p = prev.Position + (next.Position - prev.Position) * a;
            r = Quaternion.Slerp(prev.Rotation, next.Rotation, a);
        }

        transform.position = p;
        transform.rotation = r;
    }
Beispiel #15
0
        private StateRecord ReadStateDataRecord(int historianID)
        {
            StateRecord record = new StateRecord(historianID);

            // TODO: Just doing this to get latest value until API supports this
            IEnumerable <IDataPoint> dataPoints;
            Ticks stopTime  = DateTime.UtcNow.Ticks;
            Ticks startTime = stopTime - Ticks.PerSecond * 2;

            dataPoints = ReadDataStream(m_clientDatabase.Read((ulong)(long)startTime, (ulong)(long)stopTime, new[] { (ulong)historianID }));

            StateRecordDataPoint dataPoint = new StateRecordDataPoint(dataPoints.Last());

            record.CurrentData  = dataPoint;
            record.PreviousData = dataPoint;
            record.ArchivedData = dataPoint;

            return(record);
        }
        public async Task SaveStateRecordAsync(StateRecordDTO request)
        {
            StateRecord stateRecord = new StateRecord
            {
                TeamMemberId = request.TeamMemberId,
                TrainingId   = request.TrainingId,
                HeartRate    = request.HeartRate,
                Temperature  = request.Temperature
            };

            try
            {
                await stateRecords.CreateAsync(stateRecord);
            }
            catch (SqlException ex)
            {
                if (ex.Number == SqlErrorCodes.INVALID_TRAINING)
                {
                    throw new BadRequestException("Training id is invalid or outdated!");
                }
                throw ex;
            }
        }
Beispiel #17
0
    override protected void Tick()
    {
        base.Tick();

        var t = GameTime;

        // find prev and next records that bracket the current game time
        StateRecord prev = null, next = null;

        foreach (var s in _playBack.Samples)
        {
            prev = next;
            next = s;
            if (next.GameTime >= t)
            {
                break;
            }
        }

        if (next != null && (prev != null && prev.GameTime < t))
        {
            SetGhostPlayerTransform(prev, next);
        }
    }
        // state        : The root of the (sub)-tree this search expands
        // alpha        : Value used for AlphaBeta pruning - maximum value maximizing player can definitely get
        // beta         : Value used for AlphaBeta pruning - minimum value minimizing player can definitely get
        // depthLeft    : How many more depths we are allowed to explore
        private double AlphaBetaSearch(UTTTState state, double alpha, double beta, int depthLeft)
        {
            // throw an exception if our player is forced to stop
            if (sw.ElapsedMilliseconds > msGiven)
            {
                throw new OutOfTimeException();
            }

            // if final depth reached, then return the value of this leaf
            if (depthLeft == 0 || state.IsFinal())
            {
                return(state.Evaluate());
            }

            // if not final depth, then generate all possible branches
            List <UTTTMove> moves = state.GetPossibleMoves();

            //
            if (moves.Count == 0)
            {
                throw new OutOfTimeException();
            }

            // if only a single move is possible, don't decrease depth
            if (moves.Count == 1)
            {
                depthLeft++;
            }

            // if the state has been seen before, then continue
            // tracing the best move of the previous iteration by putting the old move
            // in the first position to be evaluated. This leads to better pruning.
            StateRecord rec = null;

            statesSeen.TryGetValue(state.GetHashCode(), out rec);
            if (rec != null)
            {
                if (rec.iteration == iteration)
                {
                    return(rec.value);
                }
                if (rec.bestMove != null)
                {
                    FindCopyAndSwap(rec.bestMove, moves, moves.First());
                }
                statesSeen.Remove(state.GetHashCode());
            }
            else
            {
                rec = new StateRecord();
            }

            // keep track of the best move
            // update the StateRecord in the dictionary after we have finished analyzing the state
            Boolean  min      = state.MinimizingHasTurn();
            UTTTMove bestMove = null;

            foreach (UTTTMove move in moves)
            {
                state.DoMove(move);
                double result = AlphaBetaSearch(state, alpha, beta, depthLeft - 1);
                state.UndoMove(move);
                if ((min && result < beta) || (!min && result > alpha))
                {
                    bestMove = move;
                    if (min)
                    {
                        beta = result;
                    }
                    else
                    {
                        alpha = result;
                    }
                }
                if (alpha >= beta)
                {
                    // update record and return
                    double res = (alpha + beta) / 2;
                    rec.Update(res, bestMove, state, statesSeen, iteration);
                    return(res);
                }
            }
            // update record and return
            if (min)
            {
                rec.Update(beta, bestMove, state, statesSeen, iteration);
                return(beta);
            }
            else
            {
                rec.Update(alpha, bestMove, state, statesSeen, iteration);
                return(alpha);
            }
        }
        private void StateLoader_ProcessRecord(GenericLoader g, int index, IRecordLoader r, ShapeUtilities.BaseShapeRecord shape)
        {
            StateRecord state = (StateRecord)r;

            state.FipsId = state.STATEFP + zeropad;
        }