示例#1
0
        public CurveDetail Add(CurveDetail parent)
        {
            // there is no hierarchy so parent can be safely ignored
            CurveDetail detail = new CurveDetail();
            detail.Default(Context.UserName);

            Curve curve = new Curve();
            curve.Default(Context.UserName);

            if (Context.Curves.Local.Count() > 0)
            {
                curve.CurveID = Context.Curves.Local.Max(x => x.CurveID) + 1;
            }
            else
            {
                curve.CurveID = 1;
            }

            detail.Curve = curve;
            detail.CurveID = curve.CurveID;
            detail.Name = "Curve Name";
            Context.Curves.Add(curve);
            Context.CurveDetails.Add(detail);

            return detail;
        }
示例#2
0
文件: CurveBS.cs 项目: Juliusz/Test
        internal static void AddCurves(ScenarioGeneratorModel context)
        {
            DateTime now = context.AsOfDate;

            var curve1 = new Curve() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            var curveDetail1 = new CurveDetail() { Name = "SWAPSOIS", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            curve1.CurveDetails.Add(curveDetail1);

            var curve2 = new Curve() { StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            var curveDetail2 = new CurveDetail() { Name = "SWAPSOISRISK", StartTime = now.AddDays(-100), EndTime = DateTime.MaxValue, CreatedAt = now, CreatedBy = "A", ApprovedAt = now.AddDays(-100), ApprovedBy = "B", Latest = true };
            curve2.CurveDetails.Add(curveDetail2);

            CurveFamily item = context.CurveFamilies.Where(x => x.Name == "SWAPS").First();

            curveDetail1.CurveFamily = item;
            curveDetail2.CurveFamily = item;

            TargetSystem system = context.TargetSystems.Where(x => x.Name == "Simra").First();
            curveDetail1.TargetSystem = system;
            curveDetail2.TargetSystem = system;

            context.Curves.Add(curve1);
            context.Curves.Add(curve2);

            context.SaveChanges();
        }
示例#3
0
        public CurveConstituent AddRiskFactorDimItemDetail(RiskFactorDimItemDetail item, CurveDetail curve, RiskFactorDimension dimension)
        {
            var existingDim = curve.Curve.CurveDimensions.FirstOrDefault(x => x.RiskFactorDimensionID == dimension.RiskFactorDimensionID);
            CurveConstituent persisted = null;

            if (existingDim != null)
            {
                persisted = existingDim.CurveConstituents.Where(x => x.RiskFactorDimItemID == item.RiskFactorDimItemID
                                                              && x.CurveDimension.RiskFactorDimensionID == dimension.RiskFactorDimensionID
                                                              && x.CurveDimension.CurveID == curve.CurveID).FirstOrDefault();
            }

            if (persisted != null && Context.Entry(persisted).State == EntityState.Modified)
            {
                // remove any changes
                Context.Entry(persisted).State = EntityState.Unchanged;
                return persisted;
            }

            var detail = new CurveConstituent();
            detail.Default(Context.UserName);
            detail.CurveConstituentID = Context.CurveConstituents.Count() > 0 ? Context.CurveConstituents.Max(x => x.CurveConstituentID) + 1 : 1;
            var dim = curve.Curve.CurveDimensions.FirstOrDefault(x => x.RiskFactorDimensionID == dimension.RiskFactorDimensionID);
            if (dim == null)
            {
                var newDim = new CurveDimension();
                newDim.Approve(Context.UserName);
                newDim.CurveDimensionID = Context.CurveDimensions.Count() > 0 ? Context.CurveDimensions.Max(x => x.CurveDimensionID) + 1 : 1;
                newDim.Default(Context.UserName);
                newDim.RiskFactorDimensionID = dimension.RiskFactorDimensionID;
                detail.CurveDimension = newDim;
                newDim.Curve = curve.Curve;
                curve.Curve.CurveDimensions.Add(newDim);
                Context.CurveDimensions.Add(newDim);
            }
            else
            {
                detail.CurveDimension = dim;
            }

            detail.RiskFactorDimItem = item.RiskFactorDimItem;
            Context.CurveConstituents.Add(detail);

            return detail;
        }
示例#4
0
        private void CalcStats(List <Curve> curves, int valueCount, ref AnimationClipStatsPublic stats,
                               ref CurveDetail curveDetail, List <BuildCurveKey> streamedKeys)
        {
            foreach (var curve in curves)
            {
                switch (curve.clipType)
                {
                case ClipOptType.StreamedClip:
                    stats.streamCurves += valueCount;

                    foreach (var key in curve.keys)
                    {
                        for (var i = 0; i < valueCount; i++)
                        {
                            if (i == 0 && key.time == float.MinValue)
                            {
                                continue;
                            }

                            var cache = new BuildCurveKey();
                            cache.time       = key.time;
                            cache.curveIndex = curveDetail.StreamedClipCurveIndex + i;
                            streamedKeys.Add(cache);
                        }
                    }

                    curveDetail.StreamedClipCurveIndex += valueCount;
                    break;

                case ClipOptType.DenseClip:
                    stats.denseCurves += valueCount;
                    curveDetail.DenseClipCurveIndex += valueCount;
                    break;

                case ClipOptType.ConstantClip:
                    stats.constantCurves           += valueCount;
                    curveDetail.ConstantCurveIndex += valueCount;
                    break;
                }
            }
        }
示例#5
0
        public AnimationClipStatsPublic GetStats()
        {
            AnimationClipStatsPublic stats = new AnimationClipStatsPublic();

            stats.positionCurves   = PositionCurves.Count;
            stats.scaleCurves      = ScaleCurves.Count;
            stats.quaternionCurves = RotationCurves.Count;
            stats.totalCurves      = stats.positionCurves * 3 + stats.scaleCurves * 3 + stats.quaternionCurves * 4;

            var groupedCurves = GetGroupedCurves();

            var         streamedKeys = new List <BuildCurveKey>();
            CurveDetail curveDetail  = new CurveDetail();

            CalcStats(PositionCurves, 3, ref stats, ref curveDetail, streamedKeys);
            CalcStats(ScaleCurves, 3, ref stats, ref curveDetail, streamedKeys);
            CalcStats(RotationCurves, 4, ref stats, ref curveDetail, streamedKeys);

            var bindingSize =
                stats.positionCurves * 24 + stats.scaleCurves * 24 + stats.quaternionCurves * 24; // GenericBinding(24)
            var streamedSize = CalcStreamedClipSize(streamedKeys);
            var constantSize = sizeof(UInt32) + curveDetail.ConstantCurveIndex * sizeof(float);
            var densetSize   = 5 * sizeof(UInt32) + curveDetail.DenseClipCurveIndex * sizeof(float);

            var guessBase = 2168;

            var streamedClipCurves = groupedCurves[(int)ClipOptType.StreamedClip];
            var guessCurvesSize    = streamedClipCurves.PositionCurves.Count * 60 +
                                     streamedClipCurves.ScaleCurves.Count * 60 +
                                     streamedClipCurves.RotationCurves.Count * 88;

            stats.size = bindingSize + streamedSize + constantSize + densetSize + guessBase + guessCurvesSize;
            // var count = GetPathCount();
            // var guessPath = 8 * count * ( (curveDetail.ConstantCurveIndex > 0 ? 1 : 0) + (curveDetail.StreamedClipCurveIndex > 0 ? 1 : 0) - 1);
            // stats.size += guessPath;
            return(stats);
        }
示例#6
0
        protected override void BeforeSave()
        {
            DateTime timestamp = DateTime.UtcNow;

            //find all changed enities
            var modifiedEntities = Context.ChangeTracker.Entries<CurveDetail>()
                    .Where(p => p.State == EntityState.Modified)
                    .Select(p => p.Entity);

            foreach (CurveDetail detail in modifiedEntities)
            {
                //main entity, for which we keep versioning
                var mainEntity = detail.Curve;
                ICollection<CurveDetail> mainEntityDetails = mainEntity.CurveDetails;

                if (detail.Status == EntityStatus.ExpiredInSession)
                {
                    foreach (CurveDetail item in mainEntityDetails)
                    {
                        if (detail.CurveDetailID != item.CurveDetailID)
                        {
                            item.EndTime = detail.EndTime;
                            item.ModifiedBy = detail.ModifiedBy;
                            item.ModifiedAt = detail.ModifiedAt;
                        }
                    }

                    mainEntity.EndTime = detail.EndTime;
                    mainEntity.ModifiedBy = detail.ModifiedBy;
                    mainEntity.ModifiedAt = detail.ModifiedAt;
                }

                if (detail.Status == EntityStatus.ApprovedInSession)
                {
                    //entity has been approved
                    //mark existing details as expired
                    foreach (CurveDetail item in mainEntityDetails)
                    {
                        if (detail.CurveDetailID != item.CurveDetailID)
                        {
                            item.Latest = false;
                            item.EndTime = (DateTime)detail.ApprovedAt;
                            detail.StartTime = (DateTime)detail.ApprovedAt;
                        }
                    }

                    //check if main entity is approved - if not copy details
                    if (mainEntity.Status != EntityStatus.Approved)
                    {
                        mainEntity.ApprovedAt = detail.ApprovedAt;
                        mainEntity.ApprovedBy = detail.ApprovedBy;
                        mainEntity.StartTime = detail.StartTime;
                    }

                    // approve all consituents
                    foreach (var dim in mainEntity.CurveDimensions)
                    {
                        foreach (var item in dim.CurveConstituents)
                        {
                            if (item.Status != EntityStatus.Unapproved || item.Status != EntityStatus.UnapprovedInSession)
                            {
                                item.ApprovedAt = detail.ApprovedAt;
                                item.ApprovedBy = detail.ApprovedBy;
                                item.StartTime = detail.StartTime;
                            }
                        }
                    }
                }
                else if (detail.Status == EntityStatus.UnapprovedInSession)
                {
                    //new version of the entity
                    //we are creating a copy of currently edited entity
                    //and add it back to context

                    var copy = new CurveDetail();
                    mainEntity.CurveDetails.Add(copy);

                    //copy values from original
                    Context.Entry(copy).CurrentValues.SetValues(detail);

                    //reset auditing
                    copy.ResetCopy();

                    //revert the changes - done implicitly
                    Context.Entry(detail).State = EntityState.Unchanged;

                    //remove latest flag
                    detail.Latest = false;
                }
            }
        }
示例#7
0
        public void RemoveRiskFactorDimItemDetail(RiskFactorDimItemDetail item, CurveDetail curve, RiskFactorDimension dimension)
        {
            var dim = curve.Curve.CurveDimensions.FirstOrDefault(x => x.RiskFactorDimensionID == dimension.RiskFactorDimensionID);

            if (dim != null)
            {
                var curveConst = dim.CurveConstituents.FirstOrDefault(x => x.RiskFactorDimItem == item.RiskFactorDimItem);
                if (curveConst != null)
                {
                    if (Context.Entry(curveConst).State == EntityState.Added)
                    {
                        // safely remove item is not persisted
                        Context.CurveConstituents.Remove(curveConst);
                    }
                    else
                    {
                        curveConst.Expire(Context.UserName);
                        curveConst.Latest = false;
                    }
                }
                if (dim.CurveConstituents.Where(x => x.Status != EntityStatus.ExpiredInSession).Count() == 0)
                {
                    dim.IsSelected = false;
                }
            }
        }