public void AddRating(double julianDate, GCLocation loc, GCConfigRatedEntry now, GCConfigRatedEntry prev) { double offsetHours = loc.OffsetUtcHours; GCRatedMoment ma = new GCRatedMoment(); ma.JulianDay = new GregorianDateTime(); ma.JulianDay.SetFromJulian(julianDate); ma.JulianDay.TimezoneHours = offsetHours; double biasHours = loc.TimeZone.GetBiasMinutesForDay(ma.JulianDay) / 60.0; ma.JulianDay.shour += biasHours / 24.0; ma.JulianDay.TimezoneHours += biasHours; ma.JulianDay.NormalizeValues(); //m.Entry = now; ma.Title = now.Title; ma.Rating = now.Rating; ma.Note = now.Note; ma.Key = now.Key; p_ratings.Add(ma); if (now.Margins != null) { int counter = 0; foreach (GCConfigRatedMargin e in now.Margins) { if (e.Rating != 0.0) { GCRatedMoment m = new GCRatedMoment(); //m.Entry = e; m.Title = e.Title; m.Rating = e.Rating; m.Note = e.Note; m.JulianDay = new GregorianDateTime(); m.JulianDay.SetFromJulian(julianDate + e.OffsetMinutesStart / 1440.0); m.JulianDay.TimezoneHours = offsetHours; m.Key = now.Key + ".s" + counter.ToString(); p_ratings.Add(m); m = new GCRatedMoment(); //m.Entry = e; m.Title = ""; m.Rating = 0.0; m.Note = null; m.Key = now.Key + ".s" + counter.ToString(); m.JulianDay = new GregorianDateTime(); m.JulianDay.SetFromJulian(julianDate + e.OffsetMinutesEnd / 1440.0); m.JulianDay.TimezoneHours = offsetHours; p_ratings.Add(m); } counter++; } } }
public void AddRating(GregorianDateTime julian, GCConfigRatedEntry now, GCConfigRatedEntry prev) { if (prev.Rating != now.Rating || now.Rating != 0.0) { GCRatedMoment m = new GCRatedMoment(); m.JulianDay = new GregorianDateTime(julian); //m.Entry = now; m.Title = now.Title; m.Rating = now.Rating; m.Note = now.Note; m.Key = now.Key; p_ratings.Add(m); } if (now.Margins != null) { int counter = 0; foreach (GCConfigRatedMargin e in now.Margins) { if (e.Rating != 0.0) { GCRatedMoment m = new GCRatedMoment(); //m.Entry = e; m.Title = e.Title; m.Rating = e.Rating; m.Note = e.Note; m.JulianDay = julian.TimeWithOffset(e.OffsetMinutesStart / 1440.0); m.Key = now.Key + ".s" + counter.ToString(); p_ratings.Add(m); m = new GCRatedMoment(); //m.Entry = e; m.Title = ""; m.Rating = 0.0; m.Note = null; m.Key = now.Key + ".s" + counter.ToString(); m.JulianDay = julian.TimeWithOffset(e.OffsetMinutesEnd / 1440.0); p_ratings.Add(m); } counter++; } } }
/// <summary> /// Creating list of intervals based on single moments /// </summary> /// <param name="rec"></param> public void CreateRatedList(GCConfigRatedEvents rec) { StringBuilder sb = new StringBuilder(); List <string> nt = new List <string>(); Intervals.Clear(); Dictionary <string, GCRatedMoment> notes = new Dictionary <string, GCRatedMoment>(); GCRatedMoment lastRec = null; double lastMoment = -1; double thisMoment = 0; foreach (GCRatedMoment rm in p_ratings) { thisMoment = rm.JulianDay.GetJulianComplete(); if (lastMoment < 0) { lastMoment = thisMoment; lastRec = rm; } // test if this period is acceptable if ((rec.useMinPeriodLength && rec.minPeriodLength < (thisMoment - lastMoment) * 1440.0) || !rec.useMinPeriodLength) { GCRatedInterval gi = new GCRatedInterval(); gi.startTime = lastRec.JulianDay; gi.endTime = rm.JulianDay; nt.Clear(); sb.Clear(); foreach (string k in notes.Keys) { GCRatedMoment b = notes[k]; if (b.Rating < 0.0) { gi.ratingNeg += b.Rating; } else if (b.Rating > 0.0) { gi.ratingPos += b.Rating; } if (b.Note != null && b.Note.Length > 0) { nt.Add(b.Note); } if (Math.Abs(b.Rating) > 0.001) { if (sb.Length > 0) { sb.Append(", "); } sb.Append(b.Title); } } // last test for acceptance limit if (!rec.useAcceptLimit || (gi.ratingPos + gi.ratingNeg > rec.acceptLimit)) { if (sb.Length > 0) { if (nt.Count > 0) { gi.Notes = nt.ToArray <string>(); } gi.Title = sb.ToString(); Intervals.Add(gi); } } } if (rm.Key != null) { notes[rm.Key] = rm; } lastMoment = thisMoment; lastRec = rm; } // calculate percentage double max = rec.GetMaximum(); foreach (GCRatedInterval interval in Intervals) { interval.ResultRatio = Convert.ToInt32((interval.ratingPos + interval.ratingNeg) * 100.0 / max); interval.ResultRatio = Math.Max(interval.ResultRatio, -100); } // sorting GCRatedInterval.IntervalComparer ic = new GCRatedInterval.IntervalComparer(); Intervals.Sort(ic); }