Tuple <int, List <PlanSection> > UnrollLoop(List <SectionOrError> soes, int loopIdx) { var loopSection = soes[loopIdx]; var inner = new List <PlanSection>(); int i = loopIdx + 1; for (; i < soes.Count; i++) { var soe = soes[i]; if (soe.IsLoop) { var r = UnrollLoop(soes, i); i = r.Item1 - 1; inner.AddRange(r.Item2); continue; } if (soe.LoopSection == loopSection) { inner.Add(soe); } else { break; } } var outer = new List <PlanSection>(); for (int k = 0; k < loopSection.LoopCount; k++) { var innerIdxed = new List <PlanSection>(); foreach (var ips in inner) { var nps = new PlanSection(ips.TargetPower, ips.Duration, ips.Desc); nps.LoopIndex.AddRange(ips.LoopIndex); nps.LoopIndex.Add(k); innerIdxed.Add(nps); } outer.AddRange(innerIdxed); } return(new Tuple <int, List <PlanSection> >(i, outer)); }
public int AveJ(DateTime now, PlanSection s) { var end = lastPowerAccumedAt; var addMilliJ = 0; if (now > lastPowerAccumedAt) { var span = now - lastPowerAccumedAt; addMilliJ = (int)(RecentPower * span.TotalMilliseconds); end = now; } var powerAccumedSpan = end - s.PlayStartedAt; if (Math.Round(powerAccumedSpan.TotalSeconds) > 0.8) { return((int)Math.Round(((double)(s.AccumMilliJ + addMilliJ)) / powerAccumedSpan.TotalMilliseconds)); } else { return(-1); } }
public void AccumJ(int accumPower, int count, DateTime now, PlanSection s) { lock (this) { if (lastPowerAccumedAt == DateTime.MinValue) { // first sample } else { if (now <= lastPowerAccumedAt) { return; } var span = now - lastPowerAccumedAt; int milliJ = (int)(accumPower * span.TotalMilliseconds / count); s.AccumMilliJ += milliJ; } lastPowerAccumedAt = now; RecentPower = accumPower / count; Debug.WriteLine("RecentPower: " + RecentPower.ToString()); } }
public void AddPausedSpan(TimeSpan span, PlanSection s) { s.PlayStartedAt += span; lastPowerAccumedAt += span; }