private List <TimeProfileEntry> MakeTimeProfileEntryFromDeviceAction([NotNull] DeviceAction da, [NotNull] Affordance affordance,
                                                                             [NotNull] AffordanceDevice affdev, Random rnd)
        {
            var tpes = new List <TimeProfileEntry>();

            foreach (var actionProfile in da.Profiles)
            {
                var lt = actionProfile.VLoadType;
                if (lt == null)
                {
                    throw new LPGException("load type was null");
                }
                var tp = actionProfile.Timeprofile;
                if (tp == null)
                {
                    throw new LPGException("Time profile was null");
                }
                var cp        = CalcDeviceFactory.GetCalcProfile(tp, new TimeSpan(0, 1, 0));
                var factor    = GetMaxExpansionFactor((double)affordance.TimeStandardDeviation, rnd);
                var newlength = cp.GetNewLengthAfterCompressExpand(factor);
                if (da.Device == null)
                {
                    throw new LPGException("Device was null");
                }
                var tpe = new TimeProfileEntry(affdev, newlength, lt,
                                               (int)(affdev.TimeOffset + actionProfile.TimeOffset), affordance, factor, da.Device.Name);
                tpes.Add(tpe);
            }
            return(tpes);
        }
        private TimeProfileEntry MakeTimeProfileEntryFromDevice([NotNull] AffordanceDevice affdev, [NotNull] Affordance affordance, Random rnd)
        {
            var lt = affdev.LoadType;

            if (lt == null)
            {
                throw new DataIntegrityException("LoadType was null");
            }
            var tp = affdev.TimeProfile;

            if (tp == null)
            {
                throw new DataIntegrityException("Time profile was null");
            }
            var cp        = CalcDeviceFactory.GetCalcProfile(tp, new TimeSpan(0, 1, 0));
            var factor    = GetMaxExpansionFactor((double)affordance.TimeStandardDeviation, rnd);
            var newlength = cp.GetNewLengthAfterCompressExpand(factor);

            if (affdev.Device == null)
            {
                throw new DataIntegrityException("Device was null");
            }
            string name = affdev.Device.Name;
            var    tpe  = new TimeProfileEntry(affdev, newlength, lt, (int)affdev.TimeOffset, affordance, factor,
                                               name);

            return(tpe);
        }
 public void GetCalcProfileTest()
 {
     using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
     {
         var tp = new TimeBasedProfile("blub", null, db.ConnectionString, TimeProfileType.Relative,
                                       "fake", Guid.NewGuid().ToStrGuid());
         tp.SaveToDB();
         tp.AddNewTimepoint(new TimeSpan(0, 0, 0), 100, false);
         tp.AddNewTimepoint(new TimeSpan(0, 2, 0), 0, false);
         tp.AddNewTimepoint(new TimeSpan(0, 4, 0), 100, false);
         tp.AddNewTimepoint(new TimeSpan(0, 6, 0), 0, false);
         var ctp = CalcDeviceFactory.GetCalcProfile(tp, new TimeSpan(0, 0, 30));
         ctp.TimeSpanDataPoints.Count.Should().Be(4);
         ctp.StepValues.Count.Should().Be(12);
         var v = ctp.StepValues;
         v[0].Should().Be(1);
         v[1].Should().Be(1);
         v[2].Should().Be(1);
         v[3].Should().Be(1);
         db.Cleanup();
     }
 }