示例#1
0
        public async Task <ActionResult <List <StatusAtualResponse> > > LoadData()
        {
            double maxima  = 0;
            var    service = new StatusAtualService();
            var    result  = await service.LoadData();

            foreach (StatusAtualResponse sar in result)
            {
                maxima              = Ultil.AchaLuminosidadeMaxima(maxima, sar.luminosidade.value);
                sar.pH.value        = Ultil.AjustaPH(sar.pH.value);
                sar.humidSolo.value = Ultil.AjustaUmidadeDoSolo(sar.humidSolo.value);
            }
            foreach (StatusAtualResponse sar in result)
            {
                sar.luminosidade.value = Ultil.AjustaLuminnosidade(sar.luminosidade.value, maxima);
            }
            return(Ok(result));
        }
示例#2
0
        public async Task <StatusHistoryRsponse> AjusteHistorys(string agrupamento)
        {
            StatusHistoryRsponse STR = new StatusHistoryRsponse();
            StatusAtualResponse  statusAtualResponse = new StatusAtualResponse();
            DateTime             data = his.First().recvTime;

            double[] dadosAgroup        = new double[6];
            int[]    contadores         = new int[6];
            bool[]   NotNull            = new bool[6];
            double   luminosidadeMaxima = 0;

            string dataFormat = agrupamento == "Dia" ? "{0:dd/MM/yy}" : agrupamento == "Mes" ? "{0:MMM/yy}" : agrupamento == "Ano" ? "{0:yyyy}" : "{0:d/M HH}";

            if (data != null)
            {
                STR.Data = new List <string>();
                STR.Data.Add(String.Format(dataFormat, data));
                STR.pH            = new List <double?>();
                STR.humidAmbiente = new List <double?>();
                STR.humidSolo     = new List <double?>();
                STR.luminosidade  = new List <double?>();
                STR.tempAmbiente  = new List <double?>();
                STR.tempSolo      = new List <double?>();
                zeraVetores(dadosAgroup, contadores, NotNull);
            }
            foreach (HistoryStatus hs in his)
            {
                if (hs.attrName == "luminosidade")
                {
                    luminosidadeMaxima = Ultil.AchaLuminosidadeMaxima(luminosidadeMaxima, Ultil.AjustaDouble(hs.attrValue));
                }
            }
            foreach (HistoryStatus hs in his)
            {
                if (agrupamento == "Dia")
                {
                    if (hs.recvTime.Day != data.Day || hs.recvTime.Month != data.Month || hs.recvTime.Year != data.Year)
                    {
                        agrupaPorPeriodo(hs, STR, ref data, dadosAgroup, contadores, NotNull, dataFormat);
                    }
                    else
                    {
                        switch (hs.attrName)
                        {
                        case "pH":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[0]++;
                                dadosAgroup[0] += Ultil.AjustaPH(Ultil.AjustaDouble(hs.attrValue));
                                NotNull[0]      = false;
                            }
                            break;

                        case "luminosidade":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[1]++;

                                dadosAgroup[1] += Ultil.AjustaLuminnosidade(Ultil.AjustaDouble(hs.attrValue), luminosidadeMaxima);
                                NotNull[1]      = false;
                            }
                            break;

                        case "tempSolo":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[2]++;

                                var a = Ultil.AjustaDouble(hs.attrValue);
                                dadosAgroup[2] += Ultil.AjustaDouble(hs.attrValue);
                                NotNull[2]      = false;
                            }
                            break;

                        case "tempAmbiente":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[3]++;

                                var a = Ultil.AjustaDouble(hs.attrValue);
                                dadosAgroup[3] += Ultil.AjustaDouble(hs.attrValue);
                                NotNull[3]      = false;
                            }
                            break;

                        case "humidSolo":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[4]++;

                                dadosAgroup[4] += Ultil.AjustaUmidadeDoSolo(Ultil.AjustaDouble(hs.attrValue));
                                NotNull[4]      = false;
                            }
                            break;

                        case "humidAmbiente":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[5]++;

                                dadosAgroup[5] += Ultil.AjustaDouble(hs.attrValue);
                                NotNull[5]      = false;
                            }
                            break;
                        }
                    }
                }
                if (agrupamento == "Mes")
                {
                    if (hs.recvTime.Month != data.Month || hs.recvTime.Year != data.Year)
                    {
                        agrupaPorPeriodo(hs, STR, ref data, dadosAgroup, contadores, NotNull, dataFormat);
                    }
                    else
                    {
                        switch (hs.attrName)
                        {
                        case "pH":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[0]++;

                                dadosAgroup[0] += Ultil.AjustaPH(Ultil.AjustaDouble(hs.attrValue));
                                NotNull[0]      = false;
                            }
                            break;

                        case "luminosidade":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[1]++;

                                dadosAgroup[1] += Ultil.AjustaLuminnosidade(Ultil.AjustaDouble(hs.attrValue), luminosidadeMaxima);
                                NotNull[1]      = false;
                            }
                            break;

                        case "tempSolo":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[2]++;

                                var a = Ultil.AjustaDouble(hs.attrValue);
                                dadosAgroup[2] += Ultil.AjustaDouble(hs.attrValue);
                                NotNull[2]      = false;
                            }
                            break;

                        case "tempAmbiente":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[3]++;

                                var a = Ultil.AjustaDouble(hs.attrValue);
                                dadosAgroup[3] += Ultil.AjustaDouble(hs.attrValue);
                                NotNull[3]      = false;
                            }
                            break;

                        case "humidSolo":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[4]++;

                                dadosAgroup[4] += Ultil.AjustaUmidadeDoSolo(Ultil.AjustaDouble(hs.attrValue));
                                NotNull[4]      = false;
                            }
                            break;

                        case "humidAmbiente":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[5]++;

                                dadosAgroup[5] += Ultil.AjustaDouble(hs.attrValue);
                                NotNull[5]      = false;
                            }
                            break;
                        }
                    }
                }
                if (agrupamento == "Ano")
                {
                    if (hs.recvTime.Year != data.Year)
                    {
                        agrupaPorPeriodo(hs, STR, ref data, dadosAgroup, contadores, NotNull, dataFormat);
                    }
                    else
                    {
                        switch (hs.attrName)
                        {
                        case "pH":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[0]++;

                                dadosAgroup[0] += Ultil.AjustaPH(Ultil.AjustaDouble(hs.attrValue));
                                NotNull[0]      = false;
                            }
                            break;

                        case "luminosidade":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[1]++;

                                dadosAgroup[1] += Ultil.AjustaLuminnosidade(Ultil.AjustaDouble(hs.attrValue), luminosidadeMaxima);
                                NotNull[1]      = false;
                            }
                            break;

                        case "tempSolo":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[2]++;

                                var a = Ultil.AjustaDouble(hs.attrValue);
                                dadosAgroup[2] += Ultil.AjustaDouble(hs.attrValue);
                                NotNull[2]      = false;
                            }
                            break;

                        case "tempAmbiente":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[3]++;

                                var a = Ultil.AjustaDouble(hs.attrValue);
                                dadosAgroup[3] += Ultil.AjustaDouble(hs.attrValue);
                                NotNull[3]      = false;
                            }
                            break;

                        case "humidSolo":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[4]++;

                                dadosAgroup[4] += Ultil.AjustaUmidadeDoSolo(Ultil.AjustaDouble(hs.attrValue));
                                NotNull[4]      = false;
                            }
                            break;

                        case "humidAmbiente":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[5]++;

                                dadosAgroup[5] += Ultil.AjustaDouble(hs.attrValue);
                                NotNull[5]      = false;
                            }
                            break;
                        }
                    }
                }
                if (agrupamento == "Hora")
                {
                    if (hs.recvTime.Hour != data.Hour || hs.recvTime.Day != data.Day || hs.recvTime.Month != data.Month || hs.recvTime.Year != data.Year)
                    {
                        agrupaPorPeriodo(hs, STR, ref data, dadosAgroup, contadores, NotNull, dataFormat);
                    }
                    else
                    {
                        switch (hs.attrName)
                        {
                        case "pH":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[0]++;

                                dadosAgroup[0] += Ultil.AjustaPH(Ultil.AjustaDouble(hs.attrValue));
                                NotNull[0]      = false;
                            }
                            break;

                        case "luminosidade":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[1]++;
                                dadosAgroup[1] += Ultil.AjustaLuminnosidade(Ultil.AjustaDouble(hs.attrValue), luminosidadeMaxima);
                                NotNull[1]      = false;
                            }
                            break;

                        case "tempSolo":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[2]++;
                                dadosAgroup[2] += Ultil.AjustaDouble(hs.attrValue);
                                NotNull[2]      = false;
                            }
                            break;

                        case "tempAmbiente":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[3]++;
                                dadosAgroup[3] += Ultil.AjustaDouble(hs.attrValue);
                                NotNull[3]      = false;
                            }
                            break;

                        case "humidSolo":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[4]++;

                                dadosAgroup[4] += Ultil.AjustaUmidadeDoSolo(Ultil.AjustaDouble(hs.attrValue));
                                NotNull[4]      = false;
                            }
                            break;

                        case "humidAmbiente":
                            if (!String.IsNullOrEmpty(hs.attrValue))
                            {
                                contadores[5]++;

                                dadosAgroup[5] += Ultil.AjustaDouble(hs.attrValue);
                                NotNull[5]      = false;
                            }
                            break;
                        }
                    }
                }
            }
            return(STR);
        }