예제 #1
0
        public IEnumerable <MachineTimelineReport> GetMachineTimelineByDate(DateTime LogDate)
        {
            // ------------------- Set Start Time to 08:00:00 AM -------------------------
            LogDate = new DateTime(LogDate.Year, LogDate.Month, LogDate.Day, 8, 0, 0, DateTimeKind.Local);
            // ---------------------------------------------------------------------------

            List <MachineTimelineReport> retTimeline = new List <MachineTimelineReport>();

            foreach (var objThing in _thingService.GetCurrentActivity())
            {
                var objMc = new MachineTimelineReport();
                objMc.measure = objThing.Name;
                objMc.data    = new List <string>();
                var objMongo    = new MachineRunningStatus();
                var objTimeLine = objMongo.GetMachineStatusByIdAndDate(objThing.Id, LogDate);

                if (objTimeLine.Count() > 0)
                {
                    for (int i = 0; i < objTimeLine.Count(); i++)
                    {
                        string objData = "";

                        //objData.StartDateTime = objTimeLine.ElementAt(i).CDateTime.ToLocalTime();
                        //objData.Status = objTimeLine.ElementAt(i).MachineRunningStatus;

                        if (i >= objTimeLine.Count() - 1)
                        {
                            DateTime endday;

                            if (objTimeLine.ElementAt(i).CDateTime.ToLocalTime().ToString("yyyyMMdd") != DateTime.Now.ToString("yyyMMdd"))
                            {
                                //endday = new DateTime(objTimeLine.ElementAt(i).CDateTime.Year, objTimeLine.ElementAt(i).CDateTime.Month, objTimeLine.ElementAt(i).CDateTime.Day, 23, 59, 59);
                                endday = LogDate.AddDays(1);
                            }
                            else
                            {
                                endday = DateTime.Now;
                            }



                            objData = "[\"" + objTimeLine.ElementAt(i).CDateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") +
                                      @"""," + objTimeLine.ElementAt(i).MachineRunningStatus + @",""" +
                                      endday.ToString("yyyy-MM-dd HH:mm:ss") + "\"]";
                            //objData.EndDateTime = objTimeLine.ElementAt(i).CDateTime.ToLocalTime();
                        }
                        else
                        {
                            objData = "[\"" + objTimeLine.ElementAt(i).CDateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") +
                                      @"""," + objTimeLine.ElementAt(i).MachineRunningStatus + @",""" +
                                      objTimeLine.ElementAt(i + 1).CDateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") + "\"]";
                            //objData.EndDateTime = objTimeLine.ElementAt(i + 1).CDateTime.ToLocalTime();
                        }

                        objMc.data.Add(objData);
                    }
                }
                else
                {
                    DateTime dayenddt = new DateTime(LogDate.Year, LogDate.Month, LogDate.Day, 12, 0, 0, DateTimeKind.Local);
                    string   objData  = "[\"" + dayenddt.ToString("yyyy-MM-dd HH:mm:ss") +
                                        @""",0,""" + dayenddt.ToString("yyyy-MM-dd HH:mm:ss") + "\"]";
                    objMc.data.Add(objData);
                }
                retTimeline.Add(objMc);
            }
            return(retTimeline);
        }
예제 #2
0
        public IEnumerable <MachineDailyStatus> GetMachineDailySummaryByDate(DateTime LogDate)
        {
            // ------------------- Set Start Time to 08:00:00 AM -------------------------
            LogDate = new DateTime(LogDate.Year, LogDate.Month, LogDate.Day, 8, 0, 0, DateTimeKind.Local);
            // ---------------------------------------------------------------------------

            List <MachineDailyStatus> retReport = new List <MachineDailyStatus>();

            foreach (var objThing in _thingService.GetCurrentActivity())
            {
                var objMc = new MachineDailyStatus();
                objMc.MachineID   = objThing.Id;
                objMc.MachineName = objThing.Name;

                var objMongo    = new MachineRunningStatus();
                var objTimeLine = objMongo.GetMachineStatusByIdAndDate(objThing.Id, LogDate);

                string lastStatus = "";

                for (int i = 0; i < objTimeLine.Count(); i++)
                {
                    if (i < objTimeLine.Count() - 1)
                    {
                        if (lastStatus != objTimeLine.ElementAt(i).MachineRunningStatus)
                        {
                            switch (objTimeLine.ElementAt(i).MachineRunningStatus)
                            {
                            case "0":
                                objMc.OffCnt++;
                                break;

                            case "1":
                                objMc.RunCnt++;
                                break;

                            case "2":
                                objMc.SetupCnt++;
                                break;

                            case "3":
                                objMc.StopCnt++;
                                break;

                            case "4":
                                objMc.QACnt++;
                                break;
                            }
                        }

                        switch (objTimeLine.ElementAt(i).MachineRunningStatus)
                        {
                        case "0":
                            objMc.OffTime += (objTimeLine.ElementAt(i + 1).CDateTime - objTimeLine.ElementAt(i).CDateTime);
                            break;

                        case "1":
                            objMc.RunTime += (objTimeLine.ElementAt(i + 1).CDateTime - objTimeLine.ElementAt(i).CDateTime);
                            break;

                        case "2":
                            objMc.SetupTime += (objTimeLine.ElementAt(i + 1).CDateTime - objTimeLine.ElementAt(i).CDateTime);
                            break;

                        case "3":
                            objMc.StopTime += (objTimeLine.ElementAt(i + 1).CDateTime - objTimeLine.ElementAt(i).CDateTime);
                            break;

                        case "4":
                            objMc.QATime += (objTimeLine.ElementAt(i + 1).CDateTime - objTimeLine.ElementAt(i).CDateTime);
                            break;
                        }
                    }
                    else
                    {
                        // Case Last Record
                        if (lastStatus != objTimeLine.ElementAt(i).MachineRunningStatus)
                        {
                            switch (objTimeLine.ElementAt(i).MachineRunningStatus)
                            {
                            case "0":
                                objMc.OffCnt++;
                                break;

                            case "1":
                                objMc.RunCnt++;
                                break;

                            case "2":
                                objMc.SetupCnt++;
                                break;

                            case "3":
                                objMc.StopCnt++;
                                break;

                            case "4":
                                objMc.QACnt++;
                                break;
                            }
                        }

                        DateTime endday;

                        if (objTimeLine.ElementAt(i).CDateTime.ToLocalTime().ToString("yyyyMMdd") != DateTime.Now.ToString("yyyMMdd"))
                        {
                            //endday = new DateTime(objTimeLine.ElementAt(i).CDateTime.Year, objTimeLine.ElementAt(i).CDateTime.Month, objTimeLine.ElementAt(i).CDateTime.Day,23, 59, 59);
                            endday = LogDate.AddDays(1);
                        }
                        else
                        {
                            endday = DateTime.Now.ToUniversalTime();
                        }

                        switch (objTimeLine.ElementAt(i).MachineRunningStatus)
                        {
                        case "0":
                            objMc.OffTime += (endday - objTimeLine.ElementAt(i).CDateTime);
                            break;

                        case "1":
                            objMc.RunTime += (endday - objTimeLine.ElementAt(i).CDateTime);
                            break;

                        case "2":
                            objMc.SetupTime += (endday - objTimeLine.ElementAt(i).CDateTime);
                            break;

                        case "3":
                            objMc.StopTime += (endday - objTimeLine.ElementAt(i).CDateTime);
                            break;

                        case "4":
                            objMc.QATime += (endday - objTimeLine.ElementAt(i).CDateTime);
                            break;
                        }
                    }

                    lastStatus = objTimeLine.ElementAt(i).MachineRunningStatus;
                }
                retReport.Add(objMc);
            }
            return(retReport);
        }
예제 #3
0
        public IEnumerable <MachineStatusLog> GetMachineStatusByIdAndDate(string MachineID, DateTime LogDate)
        {
            var objMongo = new MachineRunningStatus();

            return(objMongo.GetMachineStatusByIdAndDate(MachineID, LogDate));
        }