Esempio n. 1
0
 public void LoadUnitConfigFromFile(byte addr, string dataFilePath)
 {
     UnitConfig = new UnitConfig();
     UnitConfig.LoadFromFile(addr, dataFilePath);
 }
Esempio n. 2
0
        /// <summary>
        /// zjistit jaka je prave ted smena a nastavit cil a defektivitu podle toho
        /// </summary>
        public void RecalcTabule(UnitConfig unitConfig)
        {
            try
            {
                //zatim jen pro typ A

                Logger.Debug($"+ unit {unitConfig.Addr}");
                DateTime dateTimeNow = DateTime.Now;

                if (!IsOkNg)
                {
                    IsTabuleOk = false;
                    Logger.Error("nelze spočítat tabuli");
                    return;
                }

                //pocet sekund od zacátku dne
                int secondsFromMidn = dateTimeNow.Second + dateTimeNow.Minute * 60 + dateTimeNow.Hour * 3600;

                //pocet sekund celého dne
                //int allDaySec = 24 * 60 * 60;

                //pocet sec. prestavky, nyni prestavka 30min - udelat jako parametr ?
                int prestavkaSec = 30 * 60;
                //8hod - 0.5hod. prestavka
                int delkaSmenySec = 27000;

                int zacatekSmeny1Sec = (int)unitConfig.Zacatek1SmenyTime.TotalSeconds;
                int zacatekSmeny2Sec = (int)unitConfig.Zacatek2SmenyTime.TotalSeconds;
                int zacatekSmeny3Sec = (int)unitConfig.Zacatek3SmenyTime.TotalSeconds;

                int zacatekPrestavkySmeny1Sec = (int)unitConfig.Prestavka1SmenyTime.TotalSeconds;
                int zacatekPrestavkySmeny2Sec = (int)unitConfig.Prestavka2SmenyTime.TotalSeconds;
                int zacatekPrestavkySmeny3Sec = (int)unitConfig.Prestavka3SmenyTime.TotalSeconds;
                int konecPrestavkySmeny1Sec   = zacatekPrestavkySmeny1Sec + prestavkaSec;
                int konecPrestavkySmeny2Sec   = zacatekPrestavkySmeny2Sec + prestavkaSec;
                int konecPrestavkySmeny3Sec   = zacatekPrestavkySmeny3Sec + prestavkaSec;

                int odZacatkuSmenySec = 0;

                IsPrestavkaTabule = false;

                Logger.Debug($"actual time is {dateTimeNow}");

                if (secondsFromMidn > zacatekSmeny1Sec && secondsFromMidn < zacatekSmeny2Sec)  //smena1
                {
                    string o;
                    if (secondsFromMidn < zacatekPrestavkySmeny1Sec)
                    {
                        IsPrestavkaTabule = false;
                        UbehlyCasSmenySec = secondsFromMidn - zacatekSmeny1Sec;
                        o = "c1";
                    }
                    else if (secondsFromMidn > zacatekPrestavkySmeny1Sec && secondsFromMidn < konecPrestavkySmeny1Sec)
                    {
                        IsPrestavkaTabule = true;
                        UbehlyCasSmenySec = 0;
                        o = "pr";
                    }
                    else
                    {
                        IsPrestavkaTabule = false;
                        UbehlyCasSmenySec = zacatekPrestavkySmeny1Sec - zacatekSmeny1Sec + secondsFromMidn - konecPrestavkySmeny1Sec;
                        o = "c2";
                    }
                    CilKusuTabule   = unitConfig.Cil1Smeny;
                    CilDefectTabule = unitConfig.Def1Smeny;
                    Logger.Debug("smena1 " + o);
                }
                else if (secondsFromMidn > zacatekSmeny2Sec && secondsFromMidn < zacatekSmeny3Sec) //smena 2
                {
                    string o;
                    if (secondsFromMidn < zacatekPrestavkySmeny2Sec)
                    {
                        IsPrestavkaTabule = false;
                        UbehlyCasSmenySec = secondsFromMidn - zacatekSmeny2Sec;
                        o = "c1";
                    }
                    else if (secondsFromMidn > zacatekPrestavkySmeny2Sec && secondsFromMidn < konecPrestavkySmeny2Sec)
                    {
                        IsPrestavkaTabule = true;
                        UbehlyCasSmenySec = 0;
                        o = "pr";
                    }
                    else
                    {
                        IsPrestavkaTabule = false;
                        UbehlyCasSmenySec = zacatekPrestavkySmeny2Sec - zacatekSmeny2Sec + secondsFromMidn - konecPrestavkySmeny2Sec;
                        o = "c2";
                    }
                    CilKusuTabule   = unitConfig.Cil2Smeny;
                    CilDefectTabule = unitConfig.Def2Smeny;
                    Logger.Debug("smena2 " + o);
                }
                else if (secondsFromMidn > zacatekSmeny3Sec || secondsFromMidn < zacatekSmeny1Sec) //smena 3
                {
                    string o;
                    if (secondsFromMidn > zacatekSmeny3Sec)
                    {
                        IsPrestavkaTabule = false;
                        UbehlyCasSmenySec = secondsFromMidn - zacatekSmeny3Sec;
                        o = "c1";
                    }
                    else if (secondsFromMidn < zacatekPrestavkySmeny3Sec)
                    {
                        IsPrestavkaTabule = false;
                        UbehlyCasSmenySec = 86400 - zacatekSmeny3Sec + secondsFromMidn;
                        o = "c2 (po pulnoci)";
                    }
                    else if (secondsFromMidn >= zacatekPrestavkySmeny3Sec && secondsFromMidn < konecPrestavkySmeny3Sec)
                    {
                        IsPrestavkaTabule = true;
                        UbehlyCasSmenySec = 0;
                        o = "pr";
                    }
                    else
                    {
                        IsPrestavkaTabule = false;
                        UbehlyCasSmenySec = 86400 - zacatekSmeny3Sec + zacatekPrestavkySmeny3Sec + secondsFromMidn - konecPrestavkySmeny3Sec;
                        o = "c3";
                    }
                    CilKusuTabule   = unitConfig.Cil3Smeny;
                    CilDefectTabule = unitConfig.Def3Smeny;
                    Logger.Debug("smena3 " + o);
                }

                if (!IsPrestavkaTabule)
                {
                    try
                    {
                        double casNa1Kus   = (double)delkaSmenySec / (double)CilKusuTabule;
                        var    aktualniCil = UbehlyCasSmenySec / casNa1Kus;
                        RozdilTabule = (int)Math.Round(Ok - aktualniCil);
                    }
                    catch (Exception ex)
                    {
                        RozdilTabule = int.MinValue;
                        Logger.Error(ex);
                    }

                    try
                    {
                        AktualDefectTabule = (float)Ng / (float)Ok;
                    }
                    catch (Exception ex)
                    {
                        AktualDefectTabule = float.NaN;
                        //Logger.Error(ex);
                    }
                }

                Logger.Debug($"- unit {unitConfig.Addr}");

                IsTabuleOk = true;
            }
            catch (Exception ex)
            {
                IsTabuleOk = false;
                Logger.Error(ex);
            }
        }