Exemple #1
0
        private void hBA1CSchätzenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IDatabaseDriver  database              = AzusaContext.GetInstance().DatabaseDriver;
            DexTimelineEntry latestGlucose         = database.Dexcom_GetLatestGlucoseEntry();
            DateTime         scope                 = latestGlucose.Timestamp.AddMonths(-3);
            IEnumerable <DexTimelineEntry> entries = database.Dexcom_GetGlucoseEntriesAfter(scope);

            uint totalGlucose     = 0;
            uint numGlucoseValues = 0;

            foreach (DexTimelineEntry entry in entries)
            {
                if (entry.Glucose.HasValue)
                {
                    totalGlucose += entry.Glucose.Value;
                    numGlucoseValues++;
                }
            }

            double avgGlucose = (double)totalGlucose / (double)numGlucoseValues;
            double hba1c      = 0.031;

            hba1c *= avgGlucose;
            hba1c += 2.393;

            string text = String.Format("Geschätzer HBA1c: {0}%", hba1c);

            Debug.WriteLine(text);
            MessageBox.Show(text);
        }