示例#1
0
        public void ShowTip(Point pt, BGE bge)
        {
            string s = bge.Date.ToString("MM/dd/yy ") + bge.Date.ToString("t", DateTimeFormatInfo.InvariantInfo);

            s += "\nReading: " + bge.Reading.ToString();
            s += "\nCarbs in 4 Hours: " + bge.CarbsIn4.ToString();
            int nHours   = bge.MinutesSinceCarbs / 60;
            int nMinutes = bge.MinutesSinceCarbs - nHours * 60;

            s += "\nTime Since Carbs: " + nHours.ToString() + ":" + nMinutes.ToString("0#");
            if (bge.Carbs > 0)
            {
                s += "\nCarbs: " + bge.Carbs.ToString();
            }

            if (bge.InterpReading)
            {
                s += "\n**** INTERPOLATED ****\n" + bge.Comment;
            }
            else if (bge.Comment.Length > 0)
            {
                s += "\nComment: " + bge.Comment;
            }

            m_sTip = s;

            Graphics gr = m_pbxTip.CreateGraphics();

            SizeF szf = gr.MeasureString(s, m_hFont);
            Size  sz  = new Size((int)Math.Floor(szf.Width), (int)Math.Floor(szf.Height));

            this.Show();
            this.SetBounds(pt.X - sz.Width / 2, pt.Y - sz.Height, sz.Width + 4, sz.Height + 4, BoundsSpecified.All);
        }
示例#2
0
        /* P T F  F R O M  B G E  A V G */

        /*----------------------------------------------------------------------------
        *       %%Function: PtfFromBgeAvg
        *       %%Qualified: bg.SBGE.PtfFromBgeAvg
        *       %%Contact: rlittle
        *
        *  ----------------------------------------------------------------------------*/
        PointF PtfFromBgeAvg(DateTime dayFirst, BGE bge, double dxQuarter, double dyBg)
        {
            float x = XFromDate(dayFirst, bge.Date, dxQuarter);
            float y = YFromReading(bge.WgtAvg, dyBg);

            // now we've got the number of quarters.  figure out the bge
            return(new PointF(x, y));
        }
        public bool closestRayIntersects(BGE.Geom.Ray ray, Vector3 point, ref Vector3 intersection)
        {
            // Calculate p0-c call it v

            Vector3 v = ray.pos - Position;
            Vector3 p0 = Vector3.zero, p1 = Vector3.zero;

            // Now calculate a, b and c
            float a, b, c;

            /*
             *  a = u.u
                b = 2u(p0 – pc)
                c = (p0 – c).(p0 – c) - r2
            */
            a = Vector3.Dot(ray.look, ray.look);
            b = 2.0f * Vector3.Dot(v, ray.look);
            c = Vector3.Dot(v, v) - (radius * radius);

            // Calculate the discriminant
            float discriminant = (b * b) - (4.0f * a * c);

            // Test for imaginary number
            // If discriminant > 0, calculate values for t0 and t1
            // Substitute into the ray equation and calculate the 2 intersection points
            // Push the interesctions into the vector intersections
            if (discriminant >= 0.0f)
            {

                discriminant = (float)Math.Sqrt(discriminant);

                float t0 = (-b + discriminant) / (2.0f * a);
                float t1 = (-b - discriminant) / (2.0f * a);

                p0 = ray.pos + (ray.look * t0);
                p1 = ray.pos + (ray.look * t1);

                if ((point - p0).magnitude < (point - p1).magnitude)
                {
                    intersection = p0;
                }
                else
                {
                    intersection = p1;
                }
                return true;
            }
            return false;
        }
示例#4
0
        /* C A L C  R E P O R T */

        /*----------------------------------------------------------------------------
        *       %%Function: CalcReport
        *       %%Qualified: bg.Reporter.CalcReport
        *       %%Contact: rlittle
        *
        *  ----------------------------------------------------------------------------*/
        public void Calc()
        {
            m_plrld = new ArrayList();

            // ok, let's walk through and figure out what gets reported and what doesn't
            //
            // first, draw the date we are working with.
            BGE      bge       = (BGE)m_slbge.GetByIndex(0);
            DateTime dttmFirst = new DateTime(bge.Date.Year, bge.Date.Month, bge.Date.Day);

            int ibge, ibgeMax;

            ibge    = 0;
            ibgeMax = m_slbge.Values.Count;
            RLD rld = new RLD();

            while (ibge < ibgeMax)
            {
                float []  dMeals   = { 8.0F, 12.0F, 18.0F };            // our defaults for meals
                float     dHours   = 0.0F;
                string [] rgsDay   = { "S", "M", "T", "W", "T", "F", "S" };
                bool []   rgfMeals = { false, false, false };

                while (ibge < ibgeMax)
                {
                    bge = (BGE)m_slbge.GetByIndex(ibge);
                    if (!bge.InterpReading)
                    {
                        break;
                    }
                    ibge++;
                }

                DateTime dttm        = new DateTime(bge.Date.Year, bge.Date.Month, bge.Date.Day);
                DateTime dttmNextDay = dttm.AddHours(29.5);        // next day is 4:30am the next day
                int      ibgeT       = ibge;
                rld.dttm = dttm;
                rld.sDay = rgsDay[(int)dttm.DayOfWeek];
                if (dttm.DayOfWeek == DayOfWeek.Sunday)
                {
                    rld.sDay        = dttm.ToString("M-dd");
                    rld.sDateHeader = dttm.ToString("d");
                }

                // let's see what meals we have manually accounted for...
                while (bge.Date < dttmNextDay)
                {
                    dHours = bge.Date.Hour + bge.Date.Minute / 60.0F;

                    if (bge.InterpReading)
                    {
                    }
                    else if (bge.Type == BGE.ReadingType.Breakfast)
                    {
                        dMeals[0]   = dHours;
                        rgfMeals[0] = true;
                    }
                    else if (bge.Type == BGE.ReadingType.Lunch)
                    {
                        dMeals[1]   = dHours;
                        rgfMeals[1] = true;
                    }
                    else if (bge.Type == BGE.ReadingType.Dinner)
                    {
                        dMeals[2]   = dHours;
                        rgfMeals[2] = true;
                    }

                    if (ibgeT + 1 >= ibgeMax)
                    {
                        break;
                    }

                    bge = (BGE)m_slbge.GetByIndex(++ibgeT);
                }

                // ok, we have figured out the meal boundaries.  now lets match the readings...
                // any reading within 1 hour of the meal time is considered a "before", and the first reading
                // between 2 hours and 3 hours after meal time is considered "after"
                bge = (BGE)m_slbge.GetByIndex(ibgeT = ibge);
                int   iMealNext      = 0;
                bool  fBeforeMatched = false;
                int   readingBefore  = 0;
                int   readingBed     = 0;
                int   readingFirst   = 0;     // the first reading of the day will serve as the "pre-breakfast" unless we get a better reading.
                float dBedMin        = dMeals[iMealDinner] + 2.0F;
                bool  fMealBumped    = false;

                while (bge.Date < dttmNextDay)
                {
                    while (bge.Date < dttmNextDay)
                    {
                        bge = (BGE)m_slbge.GetByIndex(ibgeT);
                        if (!bge.InterpReading)
                        {
                            break;
                        }
                        if (ibgeT + 1 >= ibgeMax)
                        {
                            break;
                        }
                        ibgeT++;
                    }
                    dHours = bge.Date.Hour + bge.Date.Minute / 60.0F;

                    // don't duplicate comments...
                    if (!fMealBumped && bge.FullComment.Length > 0)
                    {
                        if (rld.sComment.Length > 0)
                        {
                            rld.sComment += "; ";
                        }

                        rld.sComment += bge.FullComment;
                    }

                    fMealBumped = false;
                    if (bge.Date.Day == dttmNextDay.Day)
                    {
                        dHours += 24.0F;
                    }

                    if (readingFirst == 0 && dHours <= dMeals[iMealBreakfast])
                    {
                        readingFirst = bge.Reading;
                    }

                    if (iMealNext <= iMealDinner)
                    {
                        // are we looking for a 'before' reading?

                        if ((iMealNext == iMealBreakfast && bge.Type == BGE.ReadingType.Breakfast) ||
                            (iMealNext == iMealLunch && bge.Type == BGE.ReadingType.Lunch) ||
                            (iMealNext == iMealDinner && bge.Type == BGE.ReadingType.Dinner))
                        {
                            rld.mpimd[iMealNext].nCarbs = bge.Carbs;
                        }

                        if (!fBeforeMatched &&
                            bge.Reading != 0 &&
                            dHours >= dMeals[iMealNext] - m_dHoursBefore && dHours <= dMeals[iMealNext])
                        {
                            // got a "before" match
                            readingBefore = bge.Reading;
                        }

                        // did we find a "before" reading for the current meal and are looking
                        // for that meal (or a reading post-meal) to confirm that this is the last
                        // "before" reading?

                        if (readingBefore != 0 && !fBeforeMatched && dHours > dMeals[iMealNext])
                        {
                            rld.mpimd[iMealNext].nBefore = readingBefore;
                            fBeforeMatched = true;
                        }

                        // does this reading qualify as an 'after' reading?
                        if (dHours >= dMeals[iMealNext] + m_dHoursAfter && dHours <= dMeals[iMealNext] + 4.0)
                        {
                            // got an "after" match
                            rld.mpimd[iMealNext].nAfter = bge.Reading;
                            iMealNext++;
                            fBeforeMatched = false;
                            if (readingBefore != 0)
                            {
                                readingFirst = 0;
                            }
                            readingBefore = 0;
                            fMealBumped   = true;
                        }

                        if (!fMealBumped)
                        {
                            // check to see if we are ready to bump to the next meal
                            if (dHours > dMeals[iMealNext] + 4.0)
                            {
                                iMealNext++;
                                fBeforeMatched = false;
                                if (readingBefore != 0)
                                {
                                    readingFirst = 0;
                                }
                                readingBefore = 0;
                                fMealBumped   = true;
                            }
                        }

                        if (fMealBumped && iMealNext == iMealLunch)
                        {
                            if (readingFirst != 0)
                            {
                                // we still have a "first reading" which means that the breakfast
                                // meal never posted a before reading.  use that first reading now.
                                rld.mpimd[iMealBreakfast].nBefore = readingFirst;
                                readingFirst = 0;
                            }
                        }

                        if (!fMealBumped && ibgeT + 1 >= ibgeMax)
                        {
                            break;
                        }
                    }

                    if (dHours >= dBedMin)
                    {
                        readingBed = bge.Reading;
                    }

                    // if we bumped the meal, then go through again considering this reading
                    // for the next meal.
                    if (!fMealBumped)
                    {
                        if (ibgeT + 1 >= ibgeMax)
                        {
                            break;
                        }
                        bge = (BGE)m_slbge.GetByIndex(++ibgeT);
                    }
                }
                // need to flush everything here
                if (!fBeforeMatched && readingBefore != 0)
                {
                    rld.mpimd[iMealNext].nBefore = readingBefore;
                }
                if (!fBeforeMatched && iMealNext == iMealBreakfast && readingFirst != 0)
                {
                    rld.mpimd[iMealNext].nBefore = readingFirst;
                }

                rld.nBedReading = readingBed;
                m_plrld.Add(rld);
                rld = new RLD();

                // consume the rest of the day
                ibge = ibgeT;
                bge  = (BGE)m_slbge.GetByIndex(ibge);
                while (bge.Date < dttmNextDay)
                {
                    ibge++;
                    if (ibge >= ibgeMax)
                    {
                        break;
                    }

                    bge = (BGE)m_slbge.GetByIndex(ibge);
                }
            }
            // at this point, we have all the data we'll ever want...
        }
示例#5
0
        /* C A L C  G R A P H */

        /*----------------------------------------------------------------------------
        *       %%Function: CalcGraph
        *       %%Qualified: bg.SBGE.CalcGraph
        *       %%Contact: rlittle
        *
        *  ----------------------------------------------------------------------------*/
        public void CalcGraph(RectangleF rcf)
        {
            m_rcfDrawing = rcf;

            // graph the points in the dataset, m_cgp.nHalfDays at a time
            BGE      bge      = (BGE)m_slbge.GetByIndex(0);
            DateTime dayFirst = new DateTime(bge.Date.Year, bge.Date.Month, bge.Date.Day);

            // split apart the graphing range into intervals, by the quarter hour

            double cxQuarters = m_cgp.nHalfDays * 12 * 4;
            double dxQuarter  = (rcf.Width - m_dxOffset / 2) / cxQuarters;

            double cyBg = m_cgp.dBgHigh - m_cgp.dBgLow;
            double dyBg = (rcf.Height - m_dyOffset) / cyBg;

            // build up a set of points to graph
            int iValue = 0;

            m_plptfi = new ArrayList();
            float dxMax = 0;

            while (iValue < m_slbge.Values.Count)
            {
                bge = (BGE)m_slbge.GetByIndex(iValue);

                // set a point at bge

                PointF ptf;

                if (m_fWgtAvg)
                {
                    ptf = PtfFromBgeAvg(dayFirst, bge, dxQuarter, dyBg);
                }
                else
                {
                    ptf = PtfFromBge(dayFirst, bge, dxQuarter, dyBg);
                }

                if (ptf.X > dxMax)
                {
                    dxMax = ptf.X;
                }

                PTFI ptfi;

                ptfi.ptf = ptf;
                ptfi.bge = bge;

                m_plptfi.Add(ptfi);

                iValue++;
            }

            if (m_sbh != null)
            {
                if (dxMax > dxQuarter * cxQuarters)
                {
                    m_sbh.Minimum = 0;
                    m_sbh.Maximum = (int)(((dxMax / dxQuarter)) - (m_cgp.nHalfDays * 12 * 4));
                    m_sbh.Visible = true;
                }
                else
                {
                    m_sbh.Visible = false;
                }
            }

            m_dyPerBgUnit = dyBg;
            m_dxQuarter   = dxQuarter;
        }