Exemplo n.º 1
0
        public List <DevicesListModel> GetAllDevices()
        {
            var collection = Getconn();
            IQueryable <DevicesListModel> query = from d in collection.AsQueryable <DevicesListModel>() select d;
            List <DevicesListModel>       list  = new List <DevicesListModel>();

            DevicesPowerUseOutputUtil devicesPowerUseOutputUtil = new DevicesPowerUseOutputUtil();

            foreach (var get in query.ToList())
            {
                DateTime nowData = DateTime.Now;
                DateTime runtime = get.turn_on_time;
                TimeSpan count   = new TimeSpan(nowData.Ticks - runtime.Ticks);
                //Debug.WriteLine("currentValue " + get.devicesId + ":");

                double currentValue = GetCurrentValue(get.devicesId);
                //Debug.WriteLine("currentValue "+ get.devicesId+ ":"+currentValue);
                double currentMonth_Usage = devicesPowerUseOutputUtil.getSpecApplianceTurnOnPowerUse(get.devicesId);
                double monthTotalUseTime  = devicesPowerUseOutputUtil.getSpecApplianceMonthlyPowerUseTime(get.devicesId) * 0.00027777777777778;
                monthTotalUseTime = Convert.ToDouble(monthTotalUseTime.ToString("0.000"));


                double turnedOnUsage = devicesPowerUseOutputUtil.getSpecApplianceTurnOnPowerUse(get.devicesId);
                double turnedOnTime  = devicesPowerUseOutputUtil.getSpecApplianceTurnOnPowerUseTime(get.devicesId) * 0.00027777777777778;
                turnedOnTime = Convert.ToDouble(turnedOnTime.ToString("0.000"));

                //double avgPowers = currentMonth_Usage / count.TotalDays;
                double avgPowers = currentMonth_Usage / 30;
                avgPowers = Convert.ToDouble(avgPowers.ToString("0.00"));

                var data = new DevicesListModel()
                {
                    _id                      = get._id,
                    roomId                   = get.roomId,
                    devicesId                = get.devicesId,
                    devices_Name             = get.devices_Name,
                    power                    = get.power,
                    lastest_checking_time    = get.lastest_checking_time,
                    turn_on_time             = get.turn_on_time,
                    pos_x                    = get.pos_x,
                    pos_y                    = get.pos_y,
                    desc                     = get.desc,
                    current                  = currentValue,
                    powerOnOff               = false,
                    avgPower                 = avgPowers,
                    status                   = get.status,
                    set_value                = get.set_value,
                    currentMonthTotalUseTime = monthTotalUseTime,
                    currentMonthUsage        = currentMonth_Usage,
                    turnedOnTime             = turnedOnTime,
                    turnedOnUsage            = turnedOnUsage
                };
                //Debug.WriteLine(data.current);
                list.Add(data);
            }

            MongoDevicesList = query.ToList();
            return(list.ToList());
        }
        public async Task <DevicesListModel> GetDeviceListAsync()
        {
            var data = await _awsClientsService.IoTClient.ListThingsInThingGroupAsync(new Amazon.IoT.Model.ListThingsInThingGroupRequest()
            {
                MaxResults = 100, ThingGroupName = _config["BaseSystem:ThingGroup"]
            });

            var result = new DevicesListModel();

            foreach (var item in data.Things)
            {
                result.Devices.Add(new DevicesListEntryModel()
                {
                    DeviceId   = item,
                    DeviceName = item,
                    DeviceUrl  = _config["BaseSystem:ServerUrl"] + "/api/devices/" + item
                });
            }
            return(result);
        }