示例#1
0
        public static float CalculateHoursPerWindow(RenderLevel level, float scale, float windowWidth)
        {
            var hoursInDay = (float)ReportManager.DayEndTime.Subtract(ReportManager.DayStartTime).TotalHours;
            var dayWidth   = level.TotalDayWidth * scale;

            return((windowWidth / dayWidth) * hoursInDay);
        }
示例#2
0
        public static float CalculateScaleOfChart(RenderLevel level, float hoursPerWindow, float windowWidth)
        {
            var hoursInDay = (float)ReportManager.DayEndTime.Subtract(ReportManager.DayStartTime).TotalHours;
            var days       = hoursPerWindow / hoursInDay;
            var scaledDayW = windowWidth / days;
            var scale      = scaledDayW / level.TotalDayWidth;

            return(scale);
        }
示例#3
0
        private static string GetDayImageFileName(RenderLevel renderLevel, int dayIndex)
        {
            var dayIndexStr = dayIndex.ToString();

            if (dayIndex < 10)
            {
                dayIndexStr = "00" + dayIndexStr;
            }
            if (dayIndex < 100)
            {
                dayIndexStr = "0" + dayIndexStr;
            }

            return(string.Format("day-{0}-{1}.png", renderLevel.Index, dayIndexStr));
        }
示例#4
0
        public static IEnumerable <UIImage> GetReportImages(MoodReport report, RenderLevel renderLevel)
        {
            List <UIImage> images           = new List <UIImage>();
            string         imagesFolder     = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Reports", report.Id.ToString());
            var            reportStartLocal = GetReportStartLocal(report);
            var            reportEndLocal   = GetReportEndLocal(report);
            var            days             = (float)reportEndLocal.Date.Subtract(reportStartLocal.Date).Days + 1;

            for (var i = 0; i < days; i++)
            {
                var imagePath = Path.Combine(imagesFolder, GetDayImageFileName(renderLevel, i));
                images.Add(UIImage.FromFile(imagePath));
            }
            return(images);
        }
示例#5
0
        public void Refresh(MoodReport report, RenderLevel renderLevel)
        {
            var viewStartTime = ChartHelper.ToCurrentTime(report.StartsOn, report.EndsOn, this.globalMap.ContentOffset.X * 1 / this.globalMap.ZoomScale, renderLevel, true).Value;
            var viewEndTime   = ChartHelper.ToCurrentTime(report.StartsOn, report.EndsOn, (this.globalMap.ContentOffset.X + this.Frame.Width) * 1 / this.globalMap.ZoomScale, renderLevel, true).Value;

            var labelTime  = viewStartTime;
            var labelIndex = 0;
            var labelPos   = 0f;

            while (labelTime < viewEndTime)
            {
                var pxTilEndOfDay = (float)(ReportManager.DayEndTime.Subtract(labelTime.TimeOfDay).TotalHours / ReportManager.DayEndTime.Subtract(ReportManager.DayStartTime).TotalHours)
                                    * renderLevel.DayImageWidth * this.globalMap.ZoomScale;
                if (pxTilEndOfDay >= labelW)
                {
                    UILabel label;
                    if (this.dayLabels.Count() > labelIndex)
                    {
                        label = this.dayLabels [labelIndex];
                    }
                    else
                    {
                        label = new UILabel(new RectangleF(0, 0, labelW, labelH));
                        label.BackgroundColor = UIColor.Clear;
                        label.TextColor       = UIColor.White;
                        label.Font            = font;
                        this.Add(label);
                        this.dayLabels.Add(label);
                    }
                    label.Text  = labelTime.ToString("ddd dd MMM");
                    label.Frame = new RectangleF(new PointF(labelPos, label.Frame.Y), label.Frame.Size);
                    labelIndex++;
                }
                labelTime = labelTime.Date.AddDays(1);
                labelPos  = (ChartHelper.ToXPos(report.StartsOn, report.EndsOn, labelTime, renderLevel.DayImageWidth, ReportManager.DayStartTime, ReportManager.DayEndTime, renderLevel.DayMarkerWidth)
                             * this.globalMap.ZoomScale) - this.globalMap.ContentOffset.X;
            }

            while (labelIndex < this.dayLabels.Count())
            {
                var i = this.dayLabels.Count() - 1;
                this.dayLabels[i].RemoveFromSuperview();
                this.dayLabels.RemoveAt(i);
            }
        }
示例#6
0
        public static void GenerateReportImages(MoodReport report, RenderLevel renderLevel)
        {
            Console.WriteLine("Generate report images - {0} / {1}", report.Id, renderLevel.Index);
            if (report != null)
            {
                string        imagesFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Reports", report.Id.ToString());
                DirectoryInfo imagesDir    = new DirectoryInfo(imagesFolder);
                if (!imagesDir.Exists)
                {
                    imagesDir.Create();
                }


                var nowLocal         = DateTime.UtcNow.ToLocalTime(ApplicationState.Current.EventTimeOffset);
                var reportStartLocal = GetReportStartLocal(report);
                var reportEndLocal   = GetReportEndLocal(report);
                //var finalSnapshotTime = nowLocal > reportEndLocal ? reportEndLocal : nowLocal;
                var finalSnapshotTime = reportEndLocal;

                var dayStart = reportStartLocal;
                var dayEnd   = reportStartLocal.Date.Add(DayEndTime);
                //var dayHours = dayEnd.Subtract (dayStart).TotalHours;
                if (dayEnd > reportEndLocal)
                {
                    dayEnd = reportEndLocal;
                }

                var allMoods          = Mood.All().ToList();
                var lastSnapshot      = GenerateEmptyMoodList(allMoods);
                var lastSnapshotAdded = dayStart;

                //var days = (float)reportEndLocal.Date.Subtract (reportStartLocal.Date).Days + 1;
                var dayIndex = 0;

                while (dayStart < reportEndLocal)
                {
                    var  imageFrame = new RectangleF(0f, 0f, renderLevel.DayImageWidth, renderLevel.DayImageHeight);
                    var  imager     = new GlobalMoodMapImager(dayStart, dayEnd);
                    bool lastAdded  = false;
                    var  snapshots  = Snapshot.OrderedList("TimeOfSnapshotLocal",
                                                           "MoodReport.Id = @ReportId and TimeOfSnapshotLocal >= @Start and TimeOfSnapshotLocal <= @End",
                                                           new { ReportId = report.Id, Start = lastSnapshotAdded, End = dayEnd }).ToList();

                    var addedFirst = false;
                    foreach (var snapshot in snapshots)
                    {
                        if (snapshot.TimeOfSnapshotLocal < dayStart)
                        {
                            lastSnapshot = GetMoods(snapshot);
                        }
                        else
                        {
                            if (!addedFirst && dayStart <= finalSnapshotTime)
                            {
                                addedFirst = true;
                                if (snapshot.TimeOfSnapshotLocal != dayStart)
                                {
                                    if (dayStart == finalSnapshotTime)
                                    {
                                        lastAdded = true;
                                    }
                                    imager.AddSnapshot(dayStart, lastSnapshot, lastAdded);
                                    lastSnapshotAdded = dayStart;
                                }
                            }
                            if (!lastAdded && snapshot.TimeOfSnapshotLocal <= finalSnapshotTime && snapshot.TimeOfSnapshotLocal <= dayEnd)
                            {
                                //if last snapshot more than 10 mins ago then add a pre-datapoint using last snapshot data
                                if (snapshot.TimeOfSnapshotLocal.Subtract(lastSnapshotAdded).TotalMinutes > 10)
                                {
                                    imager.AddSnapshot(snapshot.TimeOfSnapshotLocal.AddMinutes(-10), lastSnapshot, false);
                                }

                                if (snapshot.TimeOfSnapshotLocal == finalSnapshotTime)
                                {
                                    lastAdded = true;
                                }
                                lastSnapshot = GetMoods(snapshot);
                                imager.AddSnapshot(snapshot.TimeOfSnapshotLocal, lastSnapshot, lastAdded);
                                lastSnapshotAdded = snapshot.TimeOfSnapshotLocal;
                            }
                        }
                    }
                    //always make sure there is a snapshot at the start of the day
                    if (!addedFirst)
                    {
                        addedFirst = true;
                        imager.AddSnapshot(dayStart, lastSnapshot, lastAdded);
                        lastSnapshotAdded = dayStart;
                    }



                    if (!lastAdded && lastSnapshot != null && lastSnapshotAdded < dayEnd)
                    {
                        if (dayStart.AddDays(1) > reportEndLocal)
                        {
                            imager.AddSnapshot(finalSnapshotTime, lastSnapshot, true);
                            lastSnapshotAdded = finalSnapshotTime;
                        }
                        else
                        {
                            imager.AddSnapshot(dayEnd, lastSnapshot, false);
                            lastSnapshotAdded = dayEnd;
                        }
                    }


                    using (var img = imager.DrawMapImage(imageFrame)){
                        string  filename = Path.Combine(imagesFolder, GetDayImageFileName(renderLevel, dayIndex));
                        NSError err;
                        img.AsPNG().Save(filename, true, out err);
                    }


                    Console.WriteLine("Image drawn");

                    dayStart = dayStart.AddDays(1);
                    dayEnd   = dayEnd.AddDays(1);
                    if (dayEnd > reportEndLocal)
                    {
                        dayEnd = reportEndLocal;
                    }

                    dayIndex++;
                }
                Console.WriteLine("Images generated");
            }
        }
示例#7
0
        public static DateTime?ToCurrentTime(DateTime reportStart, DateTime reportEnd, float xPos, RenderLevel renderLevel, bool returnClosestIfNull)
        {
            var startTime = reportStart.Date.Add(ReportManager.DayStartTime);
            var endTime   = reportEnd.Date.Add(ReportManager.DayEndTime);

            var minsInaDay = (ReportManager.DayEndTime.Subtract(ReportManager.DayStartTime).TotalMinutes);
            //adjust to remove marker widths
            var daysInCurentPos = Math.Floor(xPos / renderLevel.TotalDayWidth);
            var posX            = (xPos / renderLevel.TotalDayWidth - daysInCurentPos) * renderLevel.TotalDayWidth - renderLevel.DayMarkerWidth;

            if (posX < 0)
            {
                if (returnClosestIfNull)
                {
                    daysInCurentPos = daysInCurentPos - 1;
                    if (daysInCurentPos < 0)
                    {
                        return(startTime);
                    }
                    posX = renderLevel.DayImageWidth;
                }
                else
                {
                    return(null);
                }
            }
            var minsToAdd   = (posX / renderLevel.DayImageWidth) * minsInaDay;
            var currentTime = startTime.AddDays(Math.Floor(daysInCurentPos)).AddMinutes((double)minsToAdd);

            if (currentTime < startTime)
            {
                return(startTime);
            }
            if (currentTime > endTime)
            {
                return(endTime);
            }
            return(currentTime);
        }
示例#8
0
 public static DateTime?ToCurrentTime(DateTime reportStart, DateTime reportEnd, float xPos, RenderLevel renderLevel)
 {
     return(ToCurrentTime(reportStart, reportEnd, xPos, renderLevel, false));
 }