// Use this for initialization void Start() { xMin = transform.GetChild(0).transform.position.x - maxBlockX; xMax = transform.GetChild(0).transform.position.x + maxBlockX; camera = Camera.main; state = camera.GetComponent <BackGround>().GetState(); sunMoon = transform.GetChild(3).GetComponent <SunMoon>(); }
private static (DateTime peak, DateTime min, DateTime max) FindPeakCenter(DateTime tPeakTime, double nPeakVal, string cMember, int?zone, LocationTimeHolder lth = null) { var fld = typeof(SunMoon).GetProperty(cMember); DateTime tStartPeakTime = DateTime.MaxValue; int xTry = 0; int iJumpSize = 3600; TimeSpan tsJump = TimeSpan.FromSeconds(iJumpSize); while (xTry < 1000) { xTry++; var sm = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, tPeakTime - tsJump, zone, lth); double nVal = getValue(fld.GetValue(sm), cMember); if (nVal == nPeakVal) { tsJump += TimeSpan.FromSeconds(iJumpSize); if (sm.Datum < tStartPeakTime) { tStartPeakTime = sm.Datum; } } else { tsJump -= TimeSpan.FromSeconds(iJumpSize); iJumpSize = iJumpSize / 10; tsJump += TimeSpan.FromSeconds(iJumpSize); } if (iJumpSize < 0.01) { break; } } DateTime tEndPeakTime = DateTime.MinValue; xTry = 0; iJumpSize = 3600; tsJump = TimeSpan.FromSeconds(iJumpSize); while (xTry < 1000) { xTry++; var sm = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, tPeakTime + tsJump, zone, lth); double nVal = getValue(fld.GetValue(sm), cMember); if (nVal == nPeakVal) { tsJump += TimeSpan.FromSeconds(iJumpSize); if (sm.Datum > tStartPeakTime) { tEndPeakTime = sm.Datum; } } else { tsJump -= TimeSpan.FromSeconds(iJumpSize); iJumpSize = iJumpSize / 10; tsJump += TimeSpan.FromSeconds(iJumpSize); } if (iJumpSize < 0.01) { break; } } if (tStartPeakTime == DateTime.MaxValue) { tStartPeakTime = tPeakTime; } if (tEndPeakTime == DateTime.MinValue) { tEndPeakTime = tPeakTime; } if (tStartPeakTime != tPeakTime || tEndPeakTime != tPeakTime) { tPeakTime = tStartPeakTime.AddMilliseconds((tEndPeakTime - tStartPeakTime).TotalMilliseconds / 2); } return(tPeakTime, tStartPeakTime, tEndPeakTime); }
public static PeakPoint FindPeakAt(double nPeakDest, DateTime tStartPoint, string cMember, int?zone = null, double iJumpSize = 360000, LocationTimeHolder lth = null) { if (zone == null) { zone = (DateTime.Now - DateTime.UtcNow).Hours; } DateTime mNow = tStartPoint; var fld = typeof(SunMoon).GetProperty(cMember); if (fld != null) { SunMoon sm = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow, zone, lth); double nLastDist = double.MaxValue; TimeSpan tsJump = TimeSpan.FromSeconds(0); var xPoints = new Dictionary <DateTime, double>(); xPoints.Add(sm.Datum, getValue(fld.GetValue(sm), cMember)); int iTry = 0; while (iTry < 1000) { iTry++; if (iTry > 100) { iTry.ToString(); } sm = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow + tsJump, zone, lth); double nVal = getValue(fld.GetValue(sm), cMember); double nDist = nPeakDest - nVal; if (nDist < 0) { nDist = nDist * -1; } if (nDist > nLastDist) //wenn am PeakVorbei { xPoints.Add(sm.Datum.AddMilliseconds(iTry), nVal); nLastDist = double.MaxValue; //two step back and continue smaler tsJump -= TimeSpan.FromSeconds(iJumpSize * 2); iJumpSize = iJumpSize / 10; } else { nLastDist = nDist; } tsJump += TimeSpan.FromSeconds(iJumpSize); if (iJumpSize < 0.01) { sm = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow + tsJump, zone, lth); iJumpSize = iJumpSize * 10; //für die Anzeige break; } } string c = ""; foreach (var x in xPoints) { c += x.Key + " " + x.Value + "\n"; } c.ToString(); double nPeakVal = getValue(fld.GetValue(sm), cMember); var peak = FindPeakCenter(sm.Datum, nPeakVal, cMember, zone, lth); var tPeakTime = peak.Item1; string cEinheit = GetEinheit(cMember); string cPeakVal = nPeakVal.ToString(); if ("h".Equals(cEinheit)) { cPeakVal = GetTime(nPeakVal); } else if ("°".Equals(cEinheit)) { cPeakVal = GetGrad(nPeakVal); } else if ("km".Equals(cEinheit)) { cPeakVal = GetKm(nPeakVal); } return(new PeakPoint() { DateTime = tPeakTime, Value = nPeakVal, JumpCount = iTry, JumpSize = TimeSpan.FromSeconds(iJumpSize), PeakStart = peak.Item2, PeakEnd = peak.Item3 }); } return(null); }
public static PeakPoint FindPeakBefore(DateTime tStartPoint, int iDirection, string cMember, int?zone = null, double iJumpSize = 360000, LocationTimeHolder lth = null) { if (zone == null) { zone = (DateTime.Now - DateTime.UtcNow).Hours; } DateTime mNow = tStartPoint; var fld = typeof(SunMoon).GetProperty(cMember); if (fld != null) { SunMoon sm = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow, zone, lth); double nMaxVal = getValue(fld.GetValue(sm), cMember) * iDirection; var xPoints = new Dictionary <DateTime, double>(); xPoints.Add(sm.Datum, nMaxVal); TimeSpan tsJump = TimeSpan.FromSeconds(iJumpSize); //prüfen, ob nicht ein halber Zyklus übersprungen werden sollt.. var nPrev = getValue(fld.GetValue(new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow - TimeSpan.FromHours(6), zone, lth)), cMember) * iDirection; var nNext = getValue(fld.GetValue(new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow + TimeSpan.FromHours(6), zone, lth)), cMember) * iDirection; if (nPrev > nMaxVal && nNext < nMaxVal) { var next = FindPeakBefore(tStartPoint.AddHours(-12), iDirection * -1, cMember, zone, iJumpSize, lth); tsJump = next.DateTime - tStartPoint; nMaxVal = getValue(fld.GetValue(new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow + tsJump, zone, lth)), cMember) * iDirection; xPoints.Clear(); xPoints.Add(mNow + tsJump, nMaxVal); } int iTry = 0; while (iTry < 1000) { iTry++; sm = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow - tsJump, zone, lth); double nVal = getValue(fld.GetValue(sm), cMember) * iDirection; if (nVal > nMaxVal) { nMaxVal = nVal; } if (nVal < nMaxVal) { tsJump -= TimeSpan.FromSeconds(iJumpSize); if (iJumpSize > 0.1) { //two step back and continue smaler tsJump -= TimeSpan.FromSeconds(iJumpSize); xPoints.Add(sm.Datum.AddMilliseconds(iTry), nVal); nMaxVal = getValue(fld.GetValue(new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow - tsJump, zone, lth)), cMember) * iDirection; xPoints.Add((mNow + tsJump).AddMilliseconds(iTry + 1), getValue(fld.GetValue(new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow - tsJump, zone, lth)), cMember) * iDirection); iJumpSize = iJumpSize / 10; } else { sm = new SunMoon(sys.lastUserLocation.Latitude, sys.lastUserLocation.Longitude, mNow - tsJump, zone, lth); break; } } tsJump += TimeSpan.FromSeconds(iJumpSize); } string c = ""; foreach (var x in xPoints) { c += x.Key + " " + x.Value + "\n"; } c.ToString(); double nPeakVal = getValue(fld.GetValue(sm), cMember); DateTime tPeakTime = sm.Datum; var peak = FindPeakCenter(tPeakTime, nPeakVal, cMember, zone, lth); tPeakTime = peak.Item1; string cEinheit = GetEinheit(cMember); string cPeakVal = nPeakVal.ToString(); if ("h".Equals(cEinheit)) { cPeakVal = GetTime(nPeakVal); } else if ("°".Equals(cEinheit)) { cPeakVal = GetGrad(nPeakVal); } else if ("km".Equals(cEinheit)) { cPeakVal = GetKm(nPeakVal); } return(new PeakPoint() { DateTime = tPeakTime, Value = nPeakVal, JumpCount = iTry, JumpSize = TimeSpan.FromSeconds(iJumpSize), PeakStart = peak.Item2, PeakEnd = peak.Item3 }); } return(null); }