Beispiel #1
0
        public ActionResult DoughnutUseTimeChart()
        {
            ViewBag.charttitle = Request.Query["title"];
            ViewBag.chartType  = Request.Query["chartType"];
            ViewBag.position   = Request.Query["position"];

            List <string>     label  = new List <string>();
            DevicesController device = new DevicesController();
            List <double>     data   = new List <double>();

            DevicesPowerUseOutputUtil powerUseOutputUtil = new DevicesPowerUseOutputUtil();

            double ACpower = Math.Round((powerUseOutputUtil.getACPowerUseTime() / 3600), 2);
            double LTpower = Math.Round((powerUseOutputUtil.getLPowerUseTime() / 3600), 2);
            double HDpower = Math.Round((powerUseOutputUtil.getHUMPowerUseTime() / 3600), 2);
            double EFpower = Math.Round((powerUseOutputUtil.getEXHFPowerUseTime() / 3600), 2);

            double[] myNum = { ACpower, LTpower, HDpower, EFpower };
            var      i     = 0;

            foreach (string getDeviceTypeName in device.typeName)
            {
                label.Add(getDeviceTypeName);
                //data.Add(device.GetDeviceCount(getDeviceTypeName));
                data.Add(myNum[i]);
                i++;
            }
            ViewBag.divId = GetRandomDivId();
            ChartController chart = new ChartController();

            ViewBag.datasets    = chart.DoughnutChart(label, data);
            ViewData["devices"] = label.ToJson();

            return(PartialView("_DoughnutChart"));
        }
Beispiel #2
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());
        }
Beispiel #3
0
        public IActionResult Dashboard()
        {
            MongoIndoorTempSetting_Model        mongoIndoor = new MongoIndoorTempSetting_Model();
            List <MongoIndoorTempSetting_Model> settingList = SETTINGCOLLECTION.Find(_ => true).ToList();

            if (settingList.Count <= 0)              //no record
            {
                mongoIndoor.Id               = "";
                mongoIndoor.acDefaultTemp    = 25.5;
                mongoIndoor.tempRangeHighest = 30;
                mongoIndoor.checkDegRange    = 2;
                mongoIndoor.eachTempRange    = 3;
                mongoIndoor.acLowestTemp     = 16;
            }
            foreach (MongoIndoorTempSetting_Model m in settingList)              //have setting record
            {
                mongoIndoor = m;
            }

            IntelligentControlDeviceUnit intelligentControlDeviceUnit = new IntelligentControlDeviceUnit();

            intelligentControlDeviceUnit.mongoIndoor = mongoIndoor;
            string checkTimeMin = "*/5 * * * *";

            if (mongoIndoor != null)
            {
                checkTimeMin = "*/" + mongoIndoor.checkTimeMinutes + " * * * *";
                Debug.WriteLine("checkTimeMin!!!!!!!!" + checkTimeMin);
            }
            RecurringJob.AddOrUpdate(() => intelligentControlDeviceUnit.IntelligentControlDevice(), checkTimeMin.ToString());
            RecurringJob.AddOrUpdate(() => intelligentControlDeviceUnit.scheduledControl(), "* * * * *");

            //batch
            DevicesPowerUseInputUtil devicesPowerUseInputUtil = new DevicesPowerUseInputUtil();

            RecurringJob.AddOrUpdate(() => devicesPowerUseInputUtil.updateRoomPower(), "* * * * *");


            DevicesPowerUseOutputUtil powerUseOutputUtil = new DevicesPowerUseOutputUtil();

            double TotalSavings = 0;
            double TotalUsage   = Math.Round(powerUseOutputUtil.getTotalPowerUse(), 2);
            double ACpower      = Math.Round(powerUseOutputUtil.getACPowerUse(), 2);
            double LTpower      = Math.Round(powerUseOutputUtil.getLPowerUse(), 2);
            double HDpower      = Math.Round(powerUseOutputUtil.getHUMPowerUse(), 2);
            double EFpower      = Math.Round(powerUseOutputUtil.getEXHFPowerUse(), 2);

            ViewBag.TotalUsage   = TotalUsage;
            ViewBag.TotalSavings = TotalSavings;
            ViewBag.ACpower      = ACpower;
            ViewBag.LTpower      = LTpower;
            ViewBag.HDpower      = HDpower;
            ViewBag.EFpower      = EFpower;

            ViewBag.trendJsonString = powerUseOutputUtil.getRoomPowerTrend();

            return(View());
        }
        public static string Run()
        {
            /*using (StreamWriter sw = fi1.CreateText()) //testing to output a text file
             * {
             *  sw.WriteLine("Hello");
             *  sw.WriteLine("And");
             *  sw.WriteLine("Welcome");
             * }*/
            DevicesPowerUseOutputUtil poweruseUil = new DevicesPowerUseOutputUtil();
            int count = poweruseUil.getCountOfDifferentRooms();
            List <DailyUsageModel> dailyUsages = poweruseUil.Dailyusage();
            List <String>          roomList    = poweruseUil.getRoomList();
            String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


            ExcelPackage.LicenseContext = LicenseContext.Commercial;
            FileOutputUtil.OutputDir    = new DirectoryInfo("wwwroot\\DirFoeEx\\");                        //File dicectory which you want to store in
            var fi1 = FileOutputUtil.GetFileInfo("Power_consumption_report.xlsx");                         //File Name and type

            using (var xlPackage = new ExcelPackage(fi1))                                                  //Fill data
            {
                ExcelWorksheet worksheet  = xlPackage.Workbook.Worksheets.Add("Power consumption report"); //Add worksheets
                var            namedStyle = xlPackage.Workbook.Styles.CreateNamedStyle("HyperLink");
                namedStyle.Style.Font.UnderLine = true;
                namedStyle.Style.Font.Color.SetColor(Color.Blue);


                worksheet.Cells["A1"].Value = "INB";    //Create Headers and format them
                using (ExcelRange r = worksheet.Cells["A1:G1"])
                {
                    r.Merge = true;
                    r.Style.Font.SetFromFont(new Font("Britannic Bold", 22, FontStyle.Italic));
                    r.Style.Font.Color.SetColor(Color.White);
                    r.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.CenterContinuous;
                    r.Style.Fill.PatternType    = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                    r.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(23, 55, 93));
                }
                worksheet.Cells["A2"].Value = "Power Consumption Report";
                using (ExcelRange r = worksheet.Cells["A2:G2"])
                {
                    r.Merge = true;
                    r.Style.Font.SetFromFont(new Font("Britannic Bold", 18, FontStyle.Italic));
                    r.Style.Font.Color.SetColor(Color.Black);
                    r.Style.HorizontalAlignment = ExcelHorizontalAlignment.CenterContinuous;
                    r.Style.Fill.PatternType    = ExcelFillStyle.Solid;
                    r.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(184, 204, 228));
                }


                worksheet.Cells["A4"].Value = "Rooms";
                worksheet.Cells["A4"].Style.Fill.PatternType = ExcelFillStyle.Solid;
                worksheet.Cells["A4"].Style.Fill.BackgroundColor.SetColor(Color.FromArgb(184, 204, 228));
                worksheet.Cells["A4"].Style.Font.Bold = true;

                var    startCellPoint = "B5";
                String EndCellPoint   = "B5";
                for (int i = 0; i < count; i++)
                {
                    worksheet.Cells[alphabet[(1 + i)] + "4"].Value = roomList[i];
                    worksheet.Cells[alphabet[(1 + i)] + "4"].Style.Fill.PatternType = ExcelFillStyle.Solid;
                    worksheet.Cells[alphabet[(1 + i)] + "4"].Style.Fill.BackgroundColor.SetColor(Color.FromArgb(184, 204, 228));
                    worksheet.Cells[alphabet[(1 + i)] + "4"].Style.Font.Bold           = true;
                    worksheet.Cells[alphabet[(1 + i)] + "4"].Style.HorizontalAlignment = ExcelHorizontalAlignment.CenterContinuous;
                    EndCellPoint = alphabet[(1 + i)] + "5";

                    int y = 0;
                    foreach (DailyUsageModel usageRecord in dailyUsages)
                    {
                        //System.Diagnostics.Debug.WriteLine("usageRecord.roomId == roomList[i]" + usageRecord.roomId + roomList[i]);
                        if (usageRecord.roomId == roomList[i])
                        {
                            String cellpoint = alphabet[(1 + i)] + "" + (6 + y);
                            //System.Diagnostics.Debug.WriteLine("new day" + cellpoint);
                            worksheet.Cells[cellpoint].Value = usageRecord.recorded_date + " " + usageRecord.power_used + "kWh ";
                            worksheet.Cells[cellpoint].AutoFitColumns();
                            y++;
                        }
                        else
                        {
                            // System.Diagnostics.Debug.WriteLine("not new day");
                        }
                    }
                }

                worksheet.Cells["B5"].Value = "Daily Usage (kWh)";
                worksheet.Cells["A5"].Value = "Date:";
                using (ExcelRange r = worksheet.Cells[startCellPoint + ":" + EndCellPoint])
                {
                    r.Merge = true;
                    r.Style.Font.Color.SetColor(Color.Black);
                    r.Style.HorizontalAlignment = ExcelHorizontalAlignment.CenterContinuous;
                    r.Style.Fill.PatternType    = ExcelFillStyle.Solid;
                    r.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(184, 204, 228));
                }
                //System.Diagnostics.Debug.WriteLine("list count: " + dailyUsages.Count);



                // save the new spreadsheet
                xlPackage.Save();
            }
            return(fi1.Name);
        }