Beispiel #1
0
        /// <summary>
        /// Calculates the original gravity of a sud based on the provided malts and adjuncts
        /// Formula : http://www.brewersfriend.com
        /// </summary>
        /// <returns></returns>
        private void calculateGravity()
        {
            float gravity        = 0.0f;
            float maltGravity    = 0.0f;
            float adjunctGravity = 0.0f;//not affeted by boilding efficiency (usually added later)

            foreach (Malt item in ItemList)
            {
                if (item.isMashable)
                {
                    maltGravity += item.PPG * WeightConverter.Convert(item.Amount, "Pound");
                }
                else
                {
                    adjunctGravity += item.PPG * WeightConverter.Convert(item.Amount, "Pound");
                }
            }

            maltGravity *= (this._Efficiency / 100);
            gravity      = maltGravity + adjunctGravity;
            gravity     /= VolumeConverter.Convert(this._BatchVolume, "US Gallon");

            //output range 1.000 - 1.1XX
            Gravity = (float)(gravity * 0.001 + 1);
        }
Beispiel #2
0
        public override float ReadSingle <TUnitType>(TUnitType desiredUnit)
        {
            string s = ReadString();
            int    c = s.Length - 1;

            while (c > 0)
            {
                if (char.IsDigit(s[c]))
                {
                    c++;
                    break;
                }
                c--;
            }

            string Unit = s.Substring(c).ToLowerInvariant();

            s = s.Substring(0, c);
            float parsedNumber;

            if (!float.TryParse(s, out parsedNumber))
            {
                throw new InvalidDataException("Unable to parse " + s + " to a valid single in block " + Token);
            }

            if (desiredUnit is UnitOfLength)
            {
                if (!LengthConverter.KnownUnits.ContainsKey(Unit))
                {
                    throw new InvalidDataException("Unknown or unexpected length unit " + Unit + " encountered in block " + Token);
                }

                parsedNumber = (float)lengthConverter.Convert(parsedNumber, LengthConverter.KnownUnits[Unit], (UnitOfLength)(object)desiredUnit);
            }
            else if (desiredUnit is UnitOfWeight)
            {
                if (!WeightConverter.KnownUnits.ContainsKey(Unit))
                {
                    throw new InvalidDataException("Unknown or unexpected weight unit " + Unit + " encountered in block " + Token);
                }

                parsedNumber = (float)weightConverter.Convert(parsedNumber, WeightConverter.KnownUnits[Unit], (UnitOfWeight)(object)desiredUnit);
            }
            return(parsedNumber);
        }
        private void UpdateData()
        {
            if (!(Selected_MaxDate >= Selected_MinDate))
            {
                DependencyService.Get <IMessage>().ShortAlert("Date Non Valide");
                return;
            }
            Weight_Data.Clear();
            Min = null;
            Max = null;
            IMC = 0;

            foreach (var item in DataStore.GetWeightAsync().Where(i => i.Date.Date >= Selected_MinDate & i.Date.Date <= Selected_MaxDate))
            {
                Weight_Data.Add(WeightConverter.Convert(item, Settings.WeightUnit));
            }
            if (Weight_Data.Count > 0)
            {
                Weight_Data  = new ObservableCollection <Weight_Model>(Weight_Data.OrderBy(i => i.Date));
                Min          = Weight_Data.OrderBy(i => i.Weight).First();
                Max          = Weight_Data.OrderBy(i => i.Weight).Last();
                MaximumChart = Convert.ToInt32(Max.Weight + 100);
                IMC          = Math.Round(WeightConverter.DoubleWeightConvetBack(Weight_Data.OrderBy(i => i.Date).Last().Weight, Settings.WeightUnit) / Math.Pow(Profil.Height / 100, 2), 1);
                if (string.IsNullOrWhiteSpace(Message))
                {
                    Message = Resources["Last"] + " " + Resources["Weight_Label"] + " : " + Weight_Data.Last().Weight + " " + Settings.WeightUnit;
                }
            }
            if (IMC < 18.5)
            {
                GlucoseColor = Color.FromHex("#f1c40f");
            }
            if (IMC >= 18.5 & IMC <= 25)
            {
                GlucoseColor = Color.FromHex("#2ecc71");
            }
            if (IMC > 25)
            {
                GlucoseColor = Color.FromHex("#e74c3c");
            }
        }
Beispiel #4
0
        ///// <summary>
        /////     Configuration class for the server
        ///// </summary>
        //public static class Config
        //{
        //    public static int Port = 500;
        //    public static string Endpoint = "127.0.0.1";
        //}


        public void Start()
        {
            try
            {
                IPAddress ipAddress = IPAddress.Parse(serverEndpoint);

                Console.WriteLine("Starting TCP listener...");

                Listener = new TcpListener(ipAddress, serverPort);

                Listener.Start();


                while (true)
                {
                    Console.WriteLine("Server is listening on " + Listener.LocalEndpoint);
                    Console.WriteLine("Waiting for a connection...");
                    Console.WriteLine("###########################################");

                    // incoming client connected
                    TcpClient client = Listener.AcceptTcpClient();


                    var sw = new Stopwatch();
                    sw.MeasureTimeElapsed(() =>
                    {
                        // 1. Log that we received a request
                        Console.WriteLine("Connection accepted.");
                        Console.WriteLine("Reading data...");

                        #region --- 2. Read Payload: ---
                        // Read the actual payload (posted by the connecting client)
                        // get the incoming data through a network stream
                        NetworkStream stream = client.GetStream();
                        byte[] buffer        = new byte[client.ReceiveBufferSize];

                        // read incoming stream
                        int bytesRead = stream.Read(buffer, 0, client.ReceiveBufferSize);

                        Console.WriteLine("Recieved data: ");
                        Console.WriteLine("----------------------------------");

                        // convert the command data received into a string
                        string dataReceived = Encoding.ASCII.GetString(buffer, 0, bytesRead).TrimEnd(Environment.NewLine.ToCharArray());
                        Console.WriteLine("Received Command : " + dataReceived);
                        #endregion


                        #region --- 3. Parse & Evaluate payload: ---
                        // IMPORTANT: We expect payload to be in the format: "TOGRAM,100"
                        var data = dataReceived.Split(',', StringSplitOptions.RemoveEmptyEntries);

                        var errors                  = new List <string>();
                        double?clientValue          = null;
                        string clientConversionType = null;

                        ConversionType?conversionType = null;


                        #region --- Parse ConversionType: ---
                        try
                        {
                            // try casting the clients input to the data types we expect it to be:
                            clientConversionType = data[0].ToUpperInvariant();
                            conversionType       = Enum.Parse <ConversionType>(clientConversionType);
                        }
                        catch (Exception e)
                        {
                            errors.Add($"Invalid ConversionType ({clientConversionType}). Supported types are: {ConversionType.TOGRAM}, {ConversionType.TOOUNCE}!");
                        }
                        #endregion

                        #region --- Parse Value: ---
                        try
                        {
                            clientValue = double.Parse(data[1], NumberStyles.Number);
                        }
                        catch (Exception e)
                        {
                            errors.Add($"Invalid Value ({clientValue}). Value must be a valid number!");
                        }
                        #endregion

                        #endregion

                        if (errors.Any())
                        {
                            errors.ForEach(error => WriteToStream(error, stream));
                            WriteToStream("FOO", stream);
                        }
                        else
                        {
                            if (conversionType.HasValue && clientValue.HasValue)
                            {
                                //4.process the request
                                var result = WeightConverter.Convert(conversionType.Value, clientValue.Value);
                                var msg    = $"{result.Value} {result.Unit}";

                                //5. return result to client
                                WriteToStream(msg, stream);
                            }
                        }


                        client.Close();
                    });
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.StackTrace);
                Console.ReadLine();
            }
        }
Beispiel #5
0
        private void UpdateData()
        {
            Profil    = DataStore.GetSettingsAsync().First();
            Objectifs = DataStore.GetObjectifAsync().First();
            Glucose_Data.Clear();
            Weight_Data.Clear();
            Last_Glycemia = null;
            Last_Hb1Ac    = null;
            Last_Pression = null;
            Last_Weight   = null;
            Average       = 0;
            Nbr_Hight     = 0;
            Nbr_Low       = 0;
            Nbr_Normal    = 0;
            Min           = 0;
            Max           = 0;
            foreach (var item in DataStore.GetGlucosAsync().Where(i => i.Date >= DateTime.Now.AddDays(-7)))
            {
                Glucose_Data.Add(GlycemiaConverter.Convert(item, Profil.GlycemiaUnit));
            }
            foreach (var item in DataStore.GetWeightAsync())
            {
                Weight_Data.Add(WeightConverter.Convert(item, Profil.WeightUnit));
            }
            pression_data = new ObservableCollection <Pression_Model>(DataStore.GetPressionAsync().Where(i => i.Date.Date == DateTime.Now.Date));
            Hb1Ac_Data    = new ObservableCollection <Hb1Ac_Model>(DataStore.GetHb1acAsync());

            if (Glucose_Data.Count > 0)
            {
                Last_Glycemia = Glucose_Data.OrderBy(i => i.Date).Last();
                Average       = (Profil.GlycemiaUnit == "mg / dL") ? Math.Round((Glucose_Data.Sum(i => i.Glycemia)) / Glucose_Data.Count, 0) : Math.Round((Glucose_Data.Sum(i => i.Glycemia)) / Glucose_Data.Count, 3);
                Min           = Glucose_Data.OrderBy(i => i.Glycemia).First().Glycemia;
                Max           = Glucose_Data.OrderBy(i => i.Glycemia).Last().Glycemia;
                if (Profil.GlycemiaUnit == "mg / dL")
                {
                    Nbr_Normal = Glucose_Data.Where(i => i.Glycemia >= Objectifs.Min_Glycemia & i.Glycemia <= Objectifs.Max_Glycemia).Count();
                    Nbr_Hight  = Glucose_Data.Where(i => i.Glycemia > Objectifs.Max_Glycemia).Count();
                    Nbr_Low    = Glucose_Data.Where(i => i.Glycemia < Objectifs.Min_Glycemia).Count();
                    if (Last_Glycemia.Glycemia < Objectifs.Min_Glycemia & Last_Glycemia.Glycemia != 0)
                    {
                        GlucoseColor = Color.FromHex("#f1c40f");
                    }
                    if (Last_Glycemia.Glycemia >= Objectifs.Min_Glycemia & Last_Glycemia.Glycemia <= Objectifs.Max_Glycemia)
                    {
                        GlucoseColor = Color.FromHex("#0AC774");
                    }
                    if (Last_Glycemia.Glycemia > Objectifs.Max_Glycemia)
                    {
                        GlucoseColor = Color.FromHex("#C72D14");
                    }
                }
                else
                {
                    Nbr_Normal = Glucose_Data.Where(i => i.Glycemia >= GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Min_Glycemia, Profil.GlycemiaUnit) & i.Glycemia <= GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Max_Glycemia, Profil.GlycemiaUnit)).Count();
                    Nbr_Hight  = Glucose_Data.Where(i => i.Glycemia > GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Max_Glycemia, Profil.GlycemiaUnit)).Count();
                    Nbr_Low    = Glucose_Data.Where(i => i.Glycemia < GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Min_Glycemia, Profil.GlycemiaUnit)).Count();
                    if (Last_Glycemia.Glycemia < GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Min_Glycemia, Profil.GlycemiaUnit) & Average != 0)
                    {
                        GlucoseColor = Color.FromHex("#f1c40f");
                    }
                    if (Last_Glycemia.Glycemia >= GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Min_Glycemia, Profil.GlycemiaUnit) & Average <= GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Max_Glycemia, Profil.GlycemiaUnit))
                    {
                        GlucoseColor = Color.FromHex("#2ecc71");
                    }
                    if (Last_Glycemia.Glycemia > GlycemiaConverter.DoubleGlycemiaConvert(Objectifs.Max_Glycemia, Profil.GlycemiaUnit))
                    {
                        GlucoseColor = Color.FromHex("#e74c3c");
                    }
                }
            }
            if (pression_data.Count > 0)
            {
                Last_Pression = Pression_Data.Where(i => i.Date.Date <= DateTime.Now.Date).OrderBy(i => i.Date).Last();
            }
            if (Hb1Ac_Data.Count > 0)
            {
                Last_Hb1Ac = Hb1Ac_Data.Where(i => i.Date.Date <= DateTime.Now.Date).OrderBy(i => i.Date).Last();
            }
            if (Weight_Data.Count > 0)
            {
                Last_Weight = Weight_Data.Where(i => i.Date.Date <= DateTime.Now.Date).OrderBy(i => i.Date).Last();
            }
            if (DataStore.GetStepsAsync().Count() > 0)
            {
                if (DataStore.GetStepsAsync().Where(i => i.Date.Date == DateTime.Now.Date).Count() > 0)
                {
                    Steps = DataStore.GetStepsAsync().Single(i => i.Date.Date == DateTime.Now.Date).Steps;
                }
            }
            NextMedication();
        }
Beispiel #6
0
        private void UpdateData()
        {
            List <LogBook_Model> _data = new List <LogBook_Model>();

            Profil = DataStore.GetSettingsAsync().First();
            foreach (var item in DataStore.GetGlucosAsync())
            {
                var glucose = new LogBook_Model
                {
                    Data            = item,
                    DataValue       = GlycemiaConverter.Convert(item, Profil.GlycemiaUnit).Glycemia.ToString(),
                    Date            = item.Date,
                    Activity        = item.Activity,
                    Take_Medication = item.Taking_Medication,
                    Type            = "Glucose",
                    Unit            = Profil.GlycemiaUnit,
                    PicturePath     = item.PicturePathe
                };
                _data.Add(glucose);
            }
            foreach (var item in DataStore.GetHb1acAsync())
            {
                var drug = new LogBook_Model
                {
                    Data        = item,
                    DataValue   = item.Hb1Ac.ToString(),
                    Date        = item.Date,
                    Type        = "Hb1Ac",
                    Unit        = "%",
                    PicturePath = item.PicturePathe
                };
                _data.Add(drug);
            }

            foreach (var item in DataStore.GetPressionAsync())
            {
                var drug = new LogBook_Model
                {
                    Data        = item,
                    DataValue   = item.Diastolique.ToString() + "/" + item.Systolique.ToString(),
                    Date        = item.Date,
                    At_Home     = (item.Where == "home") ? true : false,
                    At_Doctor   = (item.Where == "clinic") ? true : false,
                    Type        = "Pression",
                    Unit        = "mmgH",
                    PicturePath = item.PicturePathe
                };
                _data.Add(drug);
            }
            foreach (var item in DataStore.GetWeightAsync())
            {
                var drug = new LogBook_Model
                {
                    Data        = item,
                    DataValue   = WeightConverter.Convert(item, Profil.WeightUnit).Weight.ToString(),
                    Date        = item.Date,
                    Type        = "Weight",
                    Unit        = Profil.WeightUnit,
                    PicturePath = item.PicturePathe
                };
                _data.Add(drug);
            }
            private_list  = new ObservableCollection <LogBook_Model>(_data);
            Selected_item = null;
            old_selected  = null;
            var sorted = from data in _data
                         orderby data.Date descending
                         group data by data.DateSort into DataGroup
                         select new Grouping <string, LogBook_Model>(DataGroup.Key, DataGroup);

            DataGrouped = new ObservableCollection <Grouping <string, LogBook_Model> >(sorted);
        }