public string JEEUpdateDB(MetricContract metric)
        {
            if (!(metric == null))
            {
                Connection connection = new Connection(url);
                var        json       = new JavaScriptSerializer().Serialize(metric);
                Task.Run(() => connection.sendData(httpVerb.POST, "/addMetric", json));

                if (metric.type > 1 && metric.type < 7)
                {
                    var collection = createDatabase();
                    var filter     = Builders <CalculatedMetrics> .Filter.Eq("deviceMAC", metric.mac);

                    if (collection.Find(filter).ToList().Count == 0)
                    {
                        InsertMetrics(new CalculatedMetrics(float.Parse(metric.value), float.Parse(metric.value), float.Parse(metric.value), float.Parse(metric.value), float.Parse(metric.value), float.Parse(metric.value), float.Parse(metric.value), float.Parse(metric.value), float.Parse(metric.value), metric.mac));
                    }
                    else
                    {
                        //Mise a jour de la liste de valeurs


                        CalculatedMetrics calculated = new CalculatedMetrics();

                        calculated.dayMin = updateMinimum(metric, "day", collection, filter, connection);
                        calculated.dayMax = updateMaximum(metric, "day", collection, filter, connection);
                        calculated.dayAvg = updateAverage(metric, "day", collection, filter, connection);

                        calculated.weekMin = updateMinimum(metric, "week", collection, filter, connection);
                        calculated.weekMax = updateMaximum(metric, "week", collection, filter, connection);
                        calculated.weekAvg = updateAverage(metric, "week", collection, filter, connection);

                        calculated.monthMin = updateMinimum(metric, "month", collection, filter, connection);
                        calculated.monthMax = updateMaximum(metric, "month", collection, filter, connection);
                        calculated.monthAvg = updateAverage(metric, "month", collection, filter, connection);

                        updateDb(calculated, collection, filter);
                    }
                    return(" UPDATE SUCCESS");
                }
                else
                {
                    return("wrong device Type");
                }
            }
            else
            {
                return("parameter is null");
            }
        }
        public CalculatedMetrics getAllCalculatedMetricsByMac(DeviceMacReceived dm)
        {
            var collection = createDatabase();
            var query      =
                from e in collection.AsQueryable <CalculatedMetrics>()
                where e.deviceMAC == dm.deviceMac
                select e;
            var a = new CalculatedMetrics();

            foreach (var item in query)
            {
                a = item;
            }
            return(a);
        }
        public void updateDb(CalculatedMetrics calculatedMetrics, IMongoCollection <CalculatedMetrics> collection, FilterDefinition <CalculatedMetrics> filter)
        {
            //insertion en base
            if (collection.Find(filter).ToList().Count == 0)
            {
                InsertMetrics(calculatedMetrics);
            }
            else
            {
                var updateDayMin = Builders <CalculatedMetrics> .Update.Set("DayMin", calculatedMetrics.dayMin);

                var updateDayMax = Builders <CalculatedMetrics> .Update.Set("DayMax", calculatedMetrics.dayMax);

                var updateDayAvg = Builders <CalculatedMetrics> .Update.Set("DayAvg", calculatedMetrics.dayAvg);

                var updateWeekMin = Builders <CalculatedMetrics> .Update.Set("WeekMin", calculatedMetrics.weekMin);

                var updateWeekMax = Builders <CalculatedMetrics> .Update.Set("WeekMax", calculatedMetrics.weekMax);

                var updateWeekAvg = Builders <CalculatedMetrics> .Update.Set("WeekAvg", calculatedMetrics.weekAvg);

                var updateMonthMin = Builders <CalculatedMetrics> .Update.Set("MonthMin", calculatedMetrics.monthMin);

                var updateMonthMax = Builders <CalculatedMetrics> .Update.Set("MonthMax", calculatedMetrics.monthMax);

                var updateMonthAvg = Builders <CalculatedMetrics> .Update.Set("MonthAvg", calculatedMetrics.monthAvg);


                collection.UpdateOne(filter, updateDayMin);
                collection.UpdateOne(filter, updateDayMax);
                collection.UpdateOne(filter, updateDayAvg);

                collection.UpdateOne(filter, updateWeekMin);
                collection.UpdateOne(filter, updateWeekMax);
                collection.UpdateOne(filter, updateWeekAvg);

                collection.UpdateOne(filter, updateMonthMin);
                collection.UpdateOne(filter, updateMonthMax);
                collection.UpdateOne(filter, updateMonthAvg);
            }
        }
        public void InsertMetrics(CalculatedMetrics metrics)
        {
            var collection = createDatabase();

            collection.InsertOneAsync(metrics);
        }