Beispiel #1
0
    // Calculates the new seconds and current hours and minutes values to seconds and sets either the time or timer value to this
    public void SetSeconds(ClockModel clockModel, ClockView clockView)
    {
        int newSeconds = 0;

        if (clockView.modeDropdown.captionText.text == ClockModel.TimeDisplayMode)
        {
            clockModel.time = RemoveCurrentSecond(clockModel.time);
        }

        else if (clockView.modeDropdown.captionText.text == ClockModel.TimerMode)
        {
            clockModel.timer = RemoveCurrentSecond(clockModel.timer);
        }

        newSeconds = clockView.secondDropdown.value;

        SetValues(clockModel, clockView, newSeconds, clockView.modeDropdown.captionText.text);
    }
Beispiel #2
0
        public List <ClockModel> GetClocks(int id)
        {
            var dbuser = database.GetWithChildren <DBUser>(id);

            List <ClockModel> clockModelList = new List <ClockModel>();

            foreach (var item in dbuser.Clocks)
            {
                ClockModel cm = new ClockModel()
                {
                    ClockTimeZone = TimeZoneInfo.FindSystemTimeZoneById(item.ClockTimeZoneId),
                    HeadColor     = Color.FromHex(item.ClockHeadColor),
                    FaceColor     = Color.FromHex(item.ClockFaceColor)
                };
                clockModelList.Add(cm);
            }
            return(clockModelList);
        }
Beispiel #3
0
    // Calculates the new minute and current hours and seconds values to seconds and sets either the time or timer value to this
    public void SetMinute(ClockModel clockModel, ClockView clockView)
    {
        int newMinute = 0;

        if (clockView.modeDropdown.captionText.text == ClockModel.TimeDisplayMode)
        {
            clockModel.time = RemoveCurrentMinute(clockModel.time);
        }

        else if (clockView.modeDropdown.captionText.text == ClockModel.TimerMode)
        {
            clockModel.timer = RemoveCurrentMinute(clockModel.timer);
        }

        newMinute = clockView.minuteDropdown.value * ClockModel.SecondsInMinute;

        SetValues(clockModel, clockView, newMinute, clockView.modeDropdown.captionText.text);
    }
Beispiel #4
0
        private void timerProc(object sender, ElapsedEventArgs e)
        {
            DateTime date = DateTime.Now;

            if (isAlarm())
            {
                return;
            }

            //停止响铃后5s内不重复响铃
            long nowTime = date.ToFileTimeUtc();

            if (nowTime - lastStopTime <= 5 * 1000 * 1000 * 10)
            {
                return;
            }

            List <ClockModel> lst = MainModel.ins.cfgMd.lstClock;

            for (int i = 0; i < lst.Count; ++i)
            {
                if (!lst[i].isEnable)
                {
                    continue;
                }

                if (lst[i].hour != date.Hour)
                {
                    continue;
                }
                if (lst[i].minute != date.Minute)
                {
                    continue;
                }

                if (date.Second <= 1)
                {
                    playClockModel = lst[i];
                    playMusic();
                    break;
                }
            }
        }
Beispiel #5
0
        public void ClockModel_CorrectTime_Test()
        {
            var clocks   = new ClockModel();
            var ct       = DateTime.Now;
            var overlaps = 0;

            for (var i = 0; i < SecondInDay; i++)
            {
                var t = clocks.GetTime();
                if (t.Hours == ct.Hour % 12 && t.Mins == ct.Minute && t.Sec == ct.Second)
                {
                    overlaps++;
                }

                clocks.Tick();
            }

            Assert.AreEqual(2, overlaps);
        }
Beispiel #6
0
        public void load()
        {
            List <TimerModel> lstTimer = md.lstTimer;

            for (int i = 0; i < lstTimer.Count; ++i)
            {
                TimerModel tm = lstTimer[i];
                TimeFormat.parseTime(lstTimer[i].time, out tm.hour, out tm.minute, out tm.second);
                //lstTimer[i].totalSecond = hour * 3600 + minute * 60 + second;
            }

            List <ClockModel> lstClock = md.lstClock;

            for (int i = 0; i < lstClock.Count; ++i)
            {
                ClockModel cm = lstClock[i];
                TimeFormat.parseTime(lstClock[i].time, out cm.hour, out cm.minute);
            }
        }
Beispiel #7
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            ClockModel md = new ClockModel();
            ClockVM    vm = new ClockVM()
            {
                Index = lstClockVM.Count,
                md    = md,
                IsNew = true,
            };

            foreach (var item in lstClockVM)
            {
                item.IsNew = false;
            }

            arrClock.Add(md);
            lstClockVM.Add(vm);
            lstTimer.ScrollIntoView(lstClockVM.Last());

            AutoSaveServer.ins.hasChanged = true;
        }
Beispiel #8
0
    // Calculates the new hour and current minutes and seconds values to seconds and sets either the time or timer value to this
    public void SetHour(ClockModel clockModel, ClockView clockView)
    {
        int newHour = 0;

        if (clockView.modeDropdown.captionText.text == ClockModel.TimeDisplayMode)
        {
            clockModel.time = RemoveCurrentHour(clockModel.time);

            // If the user is using the 12hr digital format for the Time Display
            if (clockView.timeHour12.activeSelf)
            {
                // If the time period is AM, then set new hour normally using dropdown value
                if (clockModel.period == TimePeriod.AM)
                {
                    newHour = (clockView.timeHour12Dropdown.value * ClockModel.MinutesInHour * ClockModel.SecondsInMinute);
                }
                // If the time period is PM, then set new hour accounting for the additional 12 hours (being after midday) using dropdown value
                else
                {
                    newHour = ((clockView.timeHour12Dropdown.value + ClockModel.HoursOnClock) * ClockModel.MinutesInHour * ClockModel.SecondsInMinute);
                }
            }
            // Setup normally for 24hrs
            else
            {
                newHour = clockView.timeHour24Dropdown.value * ClockModel.MinutesInHour * ClockModel.SecondsInMinute;
            }
        }

        // Setup normally for timer, using dropdown value
        else if (clockView.modeDropdown.captionText.text == ClockModel.TimerMode)
        {
            clockModel.timer = RemoveCurrentHour(clockModel.timer);
            newHour          = clockView.timerStopwatchHourDropdown.value * ClockModel.MinutesInHour * ClockModel.SecondsInMinute;
        }

        SetValues(clockModel, clockView, newHour, clockView.modeDropdown.captionText.text);
    }
Beispiel #9
0
    // Displays the time, timer or stopwatch value as speficied format (analog)
    private void SetClockHands(ClockModel clockModel, ClockView clockView)
    {
        Quaternion hourRotation   = Quaternion.identity;
        Quaternion minuteRotation = Quaternion.identity;
        Quaternion secondRotation = Quaternion.identity;

        float modeValue    = 0;
        float segmentValue = 0;

        switch (clockView.modeDropdown.captionText.text)
        {
        case ClockModel.TimeDisplayMode:
            modeValue    = clockModel.time;
            segmentValue = ClockModel.HoursOnClock;
            break;

        case ClockModel.TimerMode:
            modeValue    = clockModel.timer;
            segmentValue = ClockModel.HoursOnTimerStopwatch;
            break;

        case ClockModel.StopwatchMode:
            modeValue    = clockModel.stopwatch;
            segmentValue = ClockModel.HoursOnTimerStopwatch;
            break;
        }

        // Use of euler angles for clock hands reference: https://www.youtube.com/watch?v=pbTysQw-WNs
        // Hour hand
        clockView.analog_HourHand.transform.eulerAngles = new Vector3(0, 0, -(((modeValue / (ClockModel.ClockMultiplier * ClockModel.MinutesInHour)) / segmentValue)
                                                                              / ClockModel.FullRotationDegrees) * ClockModel.TwelveHoursInSeconds);
        // Minute hand
        clockView.analog_MinuteHand.transform.eulerAngles = new Vector3(0, 0, -((modeValue / (ClockModel.ClockMultiplier * ClockModel.SecondsInMinute))
                                                                                / ClockModel.FullRotationDegrees) * ClockModel.TwelveHoursInSeconds);
        // Second hand
        clockView.analog_SecondHand.transform.eulerAngles = new Vector3(0, 0, -((modeValue / ClockModel.ClockMultiplier) / ClockModel.FullRotationDegrees)
                                                                        * ClockModel.TwelveHoursInSeconds);
    }
        private async void ClockUser()
        {
            var clockModel = new ClockModel();
            var result     = new ClockResponseModel();

            var usersLocation = await GetUsersLocationAsync();

            if (usersLocation != null)
            {
                clockModel.Email = await Constants.GetEmail();

                clockModel.ClockLocation = usersLocation;
                clockModel.ClockTime     = DateTime.UtcNow.AddHours(3);

                if (buttonClock.Text == "Clock In")
                {
                    result = await _userService.ClockInAsync(clockModel);

                    if (result != null && result.Succeeded)
                    {
                        buttonClock.Text            = "Clock Out";
                        buttonClock.BackgroundColor = Color.Red;
                        await DisplayAlert("Success", "Clocked In Successfully", "OK");
                    }
                }
                else
                {
                    result = await _userService.ClockOutAsync(clockModel);

                    if (result != null && result.Succeeded)
                    {
                        buttonClock.Text            = "Clock In";
                        buttonClock.BackgroundColor = Color.FromHex("#77D065");
                        await DisplayAlert("Success", "Clocked Out Successfully", "OK");
                    }
                }
            }
        }
Beispiel #11
0
    // Allows for the user to set whether the time period is AM or PM and displays the chosen option.
    public void SetPeriod(ClockModel clockModel, ClockView clockView)
    {
        clockView.periodText.text = clockView.periodDropdown.captionText.text;

        if (clockView.periodText.text == "AM")
        {
            // Don't make changes if time is already an AM value
            if (clockModel.period == TimePeriod.PM)
            {
                clockModel.period = TimePeriod.AM;
                clockModel.time  -= ClockModel.TwelveHoursInSeconds;
            }
        }
        else
        {
            // Don't make changes if time is already a PM value
            if (clockModel.period == TimePeriod.AM)
            {
                clockModel.period = TimePeriod.PM;
                clockModel.time  += ClockModel.TwelveHoursInSeconds;
            }
        }
    }
Beispiel #12
0
    //	Changes whether the clock is analog or digital (hides/reveals appropriate objects).
    public void SetTimerStopwatchFormat(ClockModel clockModel, ClockView clockView)
    {
        switch (clockView.timerStopwatchDropdown.captionText.text)
        {
        case ClockModel.AnalogFormat:
            // Turn off digital objects
            clockView.digital.SetActive(false);
            clockView.digital_Period.SetActive(false);
            // Turn on analog objects
            clockView.analog.SetActive(true);
            clockView.secondValue.SetActive(true);
            break;

        case ClockModel.DigitalFormat:
            // Turn off analog and uneeded digital objects
            clockView.analog.SetActive(false);
            clockView.digital_Period.SetActive(false);
            // Turn on digital objects
            clockView.digital.SetActive(true);
            clockView.secondValue.SetActive(true);

            // Adjust number text and its width depending on the relevent mode's format
            if (clockView.modeDropdown.captionText.text == ClockModel.TimerMode)
            {
                clockView.numberText.text           = ClockModel.ZeroTimer;
                clockView.numberTransform.sizeDelta = new Vector2(ClockModel.MediumWidth, clockView.numberTransform.sizeDelta.y);
            }
            else if (clockView.modeDropdown.captionText.text == ClockModel.StopwatchMode)
            {
                clockView.numberText.text           = ClockModel.ZeroStopwatch;
                clockView.numberTransform.sizeDelta = new Vector2(ClockModel.LongWidth, clockView.numberTransform.sizeDelta.y);
            }
            break;
        }
        SetNumberDisplay(clockModel, clockView);
        SetClockHands(clockModel, clockView);
    }
Beispiel #13
0
    private void OnClockEvent(List <ClockInfo> clocks)
    {
        for (int i = 0; i < clocks.Count; i++)
        {
            ClockInfo clock = clocks[i];
            if (clock.id == (int)WealthTypeEnum.Energy)
            {
                WealthInfo energyInfo = GetWealth((int)WealthTypeEnum.Energy);
                if (energyInfo.count < energyInfo.limit)
                {
                    float ENERGY_RECOVER = GameModel.Instance.GetGameConfig(1004);
                    if (clock.value >= ENERGY_RECOVER)
                    {
                        int recoverCount = (int)Math.Floor(clock.value / ENERGY_RECOVER);
                        if ((energyInfo.limit - energyInfo.count) > recoverCount)
                        {
                            energyInfo.count = energyInfo.count + (int)recoverCount;
                        }
                        else
                        {
                            energyInfo.count = energyInfo.limit;
                        }
                        PlayerModel.Instance.SaveWealths();
                        PlayerPrefsUtil.SetInt(PlayerPrefsUtil.ENERGY_OUT_TIME, ClockModel.ConvertDateTimeInt(System.DateTime.Now));

                        int leftTime = (int)(clock.value % ENERGY_RECOVER);
                        ClockModel.Instance.SetClock(new ClockInfo((int)WealthTypeEnum.Energy, leftTime));
                    }
                }
                else
                {
                    ClockModel.Instance.RemoveClock(clock.id);
                }
                return;
            }
        }
    }
Beispiel #14
0
        /// <summary>
        /// Handler
        /// </summary>
        /// <param name="eventdate"></param>
        /// <returns></returns>
        public async Task Handler(object eventdate)
        {
            if (eventdate != null)
            {
                var eventData      = JsonConvert.DeserializeObject <EventData>(eventdate.ToString());
                var splittedValues = eventData.Data.Split(timeSeparator);
                var timeModel      = new ClockModel
                {
                    Hour = Convert.ToInt32(splittedValues[0]),
                    Min  = Convert.ToInt32(splittedValues[1])
                };
                try
                {
                    var angleValue = await _ClockBusiness.GetAngle(timeModel);

                    // TODo Save in to database;
                    // Call to Database repo
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.Message);
                }
            }
        }
Beispiel #15
0
    // Sets the the bool controlling the current mode type's activity to false.
    public void Stop(ClockModel clockModel, ClockView clockView)
    {
        switch (clockView.modeDropdown.captionText.text)
        {
        case ClockModel.TimeDisplayMode:
            clockModel.timeRunning = false;
            break;

        case ClockModel.TimerMode:
            // If user clicks the stop button twice in a row, it will reset the timer
            if (!clockModel.timerRunning)
            {
                clockModel.timer          = 0;
                clockView.numberText.text = ClockModel.ZeroTimer;
            }
            clockView.source.Stop();
            clockModel.timerRunning = false;
            break;

        case ClockModel.StopwatchMode:
            clockModel.stopwatchRunning = false;
            break;
        }
    }
    // Setup and intialise Clock
    public void SetUpClock(ClockModel clockModel, ClockView clockView)
    {
        clockView.source      = clockView.GetComponent <AudioSource>();
        clockView.source.clip = clockModel.timerSound;

        // Organises and sets up all variables of the clock (saving the user from having to pass them in manually)
        Transform[] childTransforms = clockView.GetComponentsInChildren <Transform>();

        foreach (Transform t in childTransforms)
        {
            switch (t.tag)
            {
            // ANALOG
            case "Analog":
                clockView.analog = t.gameObject;
                break;

            case "Analog Time":
                clockView.analog_Time = t.gameObject;
                break;

            case "Analog Timer":
                clockView.analog_TimerStopwatch = t.gameObject;
                break;

            case "Hour":
                clockView.analog_HourHand = t.gameObject;
                break;

            case "Minute":
                clockView.analog_MinuteHand = t.gameObject;
                break;

            case "Second":
                clockView.analog_SecondHand = t.gameObject;
                break;

            // DIGITAL
            case "Digital":
                clockView.digital = t.gameObject;
                break;

            case "Digital Numbers":
                clockView.digital_Numbers = t.gameObject;
                break;

            case "Digital Period":
                clockView.digital_Period = t.gameObject;
                break;

            // SETTINGS
            case "Hideable Settings":
                clockView.hideableSettings = t.gameObject;
                break;

            case "Mode":
                clockView.mode = t.gameObject;
                break;

            case "Time Format":
                clockView.timeFormat = t.gameObject;
                break;

            case "Timer Format":
                clockView.timerStopwatchFormat = t.gameObject;
                break;

            case "Set Values":
                clockView.setValues = t.gameObject;
                break;

            case "Time Hour 12":
                clockView.timeHour12 = t.gameObject;
                break;

            case "Time Hour 24":
                clockView.timeHour24 = t.gameObject;
                break;

            case "Timer Hour Value":
                clockView.timerStopwatchHourValue = t.gameObject;
                break;

            case "Minute Value":
                clockView.minuteValue = t.gameObject;
                break;

            case "Second Value":
                clockView.secondValue = t.gameObject;
                break;

            case "Period Value":
                clockView.periodValue = t.gameObject;
                break;

            case "Stopwatch Settings":
                clockView.stopwatchSettings = t.gameObject;
                break;

            case "Start and Stop":
                clockView.startAndStop = t.gameObject;
                break;
            }
        }

        clockView.numberTransform = clockView.digital_Numbers.GetComponent <RectTransform>();

        clockView.modeDropdown           = clockView.mode.GetComponent <TMP_Dropdown>();
        clockView.timeDropdown           = clockView.timeFormat.GetComponent <TMP_Dropdown>();
        clockView.timerStopwatchDropdown = clockView.timerStopwatchFormat.GetComponent <TMP_Dropdown>();

        clockView.timeHour24Dropdown         = clockView.timeHour24.GetComponent <TMP_Dropdown>();
        clockView.timeHour12Dropdown         = clockView.timeHour12.GetComponent <TMP_Dropdown>();
        clockView.timerStopwatchHourDropdown = clockView.timerStopwatchHourValue.GetComponent <TMP_Dropdown>();
        clockView.minuteDropdown             = clockView.minuteValue.GetComponent <TMP_Dropdown>();
        clockView.secondDropdown             = clockView.secondValue.GetComponent <TMP_Dropdown>();
        clockView.periodDropdown             = clockView.periodValue.GetComponent <TMP_Dropdown>();

        clockView.numberText      = clockView.digital_Numbers.GetComponent <TextMeshProUGUI>();
        clockView.numberTransform = clockView.numberText.GetComponent <RectTransform>();
        clockView.periodText      = clockView.digital_Period.GetComponent <TextMeshProUGUI>();
    }
Beispiel #17
0
 // Plays the AudioClip passed into this script (used for timer reaching 0)
 private void TimerFinish(ClockModel clockModel, ClockView clockView)
 {
     clockModel.timer        = 0;
     clockModel.timerRunning = false;
     clockView.source.Play();
 }
Beispiel #18
0
 public void TestMethod1()
 {
     var cm = new ClockModel();
 }
Beispiel #19
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif
            var tc = new Microsoft.ApplicationInsights.TelemetryClient();

            var navigation = new NavigationController(launchScreenCallback);
            CoreWindow.GetForCurrentThread().KeyDown += navigation.GlobalKeyDown;

            await SettingsController.LoadSettings();

            try
            {
                var clockModel = new ClockModel();
                Task.Run(() => clockModel.Update());
                (Resources["clockViewModel"] as ClockViewModel).Initialize(clockModel);
                TimerController.RegisterModel(clockModel);
                navigation.RegisterView(typeof(ClockView));
                clockModel.NightFallDelegate += TimeOfDayChangedHandler;
            }
            catch (Exception ex)
            {
                var properties = new Dictionary <String, string> {
                    { "Module", "Clock" }
                };
                tc.TrackException(ex, properties);
                System.Diagnostics.Debugger.Break();
            }

            try
            {
                var weatherModel = new WeatherModel_wunderground();
                Task.Run(() => weatherModel.Update());
                TimerController.RegisterModel(weatherModel);
                (Resources["weatherThisWeekViewModel"] as WeatherThisWeekViewModel).Initialize(weatherModel);
                (Resources["weatherTodayViewModel"] as WeatherTodayViewModel).Initialize(weatherModel);
                navigation.RegisterView(typeof(WeatherThisWeekView));
                navigation.RegisterView(typeof(WeatherTodayView));
            }
            catch (Exception ex)
            {
                var properties = new Dictionary <String, string> {
                    { "Module", "Weather" }
                };
                tc.TrackException(ex, properties);
                System.Diagnostics.Debugger.Break();
            }

            try
            {
                var transitModel = new TransitModel_translink();
                Task.Run(() => transitModel.Update());
                TimerController.RegisterModel(transitModel);
                (Resources["transitViewModel"] as TransitViewModel).Initialize(transitModel);
                TimerController.RegisterViewModel((Resources["transitViewModel"] as TransitViewModel));
                navigation.RegisterView(typeof(TransitView));
            }
            catch (Exception ex)
            {
                var properties = new Dictionary <String, string> {
                    { "Module", "Transit" }
                };
                tc.TrackException(ex, properties);
                System.Diagnostics.Debugger.Break();
            }

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new ThemeAwareFrame(ElementTheme.Light);

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(ClockView), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
            tc.TrackEvent("Smart Mirror has loaded.");

            setupAutoScroll(navigation);
        }
Beispiel #20
0
 // Add time passed to time value and display it on UI
 private void RunClock(ClockModel clockModel, ClockView clockView)
 {
     clockModel.time += Time.deltaTime;
     SetClockHands(clockModel, clockView);
     SetNumberDisplay(clockModel, clockView);
 }
        /// <summary>
        /// Default route for the Clock Vehicle process.
        /// Empty model for the user to enter a Vehicle Liscence Plate.
        /// </summary>
        /// <seealso cref="Models.Clock.ClockModel"/>
        /// <returns>View of the ClockModel</returns>
        public IActionResult ClockVehicle()
        {
            ClockModel newModel = new ClockModel();

            return(View(newModel));
        }
Beispiel #22
0
    //	Changes whether the clock is analog or digital in a variety of time formats (hides/reveals appropriate objects).
    public void SetTimeFormat(ClockModel clockModel, ClockView clockView)
    {
        switch (clockView.timeDropdown.captionText.text)
        {
        case ClockModel.AnalogFormat:
            // Turn off Digital objects
            clockView.digital.SetActive(false);
            clockView.timeHour24.SetActive(false);
            clockView.periodValue.SetActive(false);
            // Turn on Analog objects
            clockView.analog.SetActive(true);
            clockView.timeHour12.SetActive(true);
            clockView.secondValue.SetActive(true);
            break;

        case ClockModel.TwentyFour_HourMinuteFormat:
            // Turn off Analog objects
            clockView.analog.SetActive(false);
            // Turn off unnecessary digital objects
            clockView.digital_Period.SetActive(false);
            clockView.periodValue.SetActive(false);
            clockView.secondValue.SetActive(false);
            clockView.timeHour12.SetActive(false);
            // Turn on format appropriate objects for digital clock
            clockView.digital.SetActive(true);
            clockView.timeHour24.SetActive(true);
            clockView.numberTransform.sizeDelta = new Vector2(ClockModel.ShortWidth, clockView.numberTransform.sizeDelta.y);      // Resize digital number text width
            break;

        case ClockModel.Twelve_HourMinuteFormat:
            // Turn off Analog objects
            clockView.analog.SetActive(false);
            // Turn off unnecessary digital objects
            clockView.secondValue.SetActive(false);
            clockView.timeHour24.SetActive(false);
            // Turn on format appropriate objects for digital clock
            clockView.digital_Period.SetActive(true);
            clockView.periodValue.SetActive(true);
            clockView.digital.SetActive(true);
            clockView.timeHour12.SetActive(true);
            clockView.numberTransform.sizeDelta = new Vector2(ClockModel.ShortWidth, clockView.numberTransform.sizeDelta.y);      // Resize digital number text width
            break;

        case ClockModel.TwentyFour_HourMinuteSecondsFormat:
            // Turn off Analog objects
            clockView.analog.SetActive(false);
            // Turn off unnecessary digital objects
            clockView.digital_Period.SetActive(false);
            clockView.periodValue.SetActive(false);
            clockView.timeHour12.SetActive(false);
            // Turn on format appropriate objects for digital clock
            clockView.secondValue.SetActive(true);
            clockView.digital.SetActive(true);
            clockView.timeHour24.SetActive(true);
            clockView.numberTransform.sizeDelta = new Vector2(ClockModel.MediumWidth, clockView.numberTransform.sizeDelta.y);      // Resize digital number text width
            break;

        case ClockModel.Twelve_HourMinuteSecondsFormat:
            // Turn off Analog objects
            clockView.analog.SetActive(false);
            // Turn off unnecessary digital objects
            clockView.timeHour24.SetActive(false);
            // Turn on format appropriate objects for digital clock
            clockView.digital_Period.SetActive(true);
            clockView.periodValue.SetActive(true);
            clockView.secondValue.SetActive(true);
            clockView.digital.SetActive(true);
            clockView.timeHour12.SetActive(true);
            clockView.numberTransform.sizeDelta = new Vector2(ClockModel.MediumWidth, clockView.numberTransform.sizeDelta.y);      // Resize digital number text width
            break;
        }
        SetNumberDisplay(clockModel, clockView);
        SetClockHands(clockModel, clockView);
    }
Beispiel #23
0
 // Add time passed to stopwatch value and display it on UI
 private void RunStopwatch(ClockModel clockModel, ClockView clockView)
 {
     clockModel.stopwatch += Time.deltaTime;
     SetClockHands(clockModel, clockView);
     SetNumberDisplay(clockModel, clockView);
 }
Beispiel #24
0
    // Displays the time, timer or stopwatch value as speficied format (digital)
    private void SetNumberDisplay(ClockModel clockModel, ClockView clockView)
    {
        switch (clockView.modeDropdown.captionText.text)
        {
        case ClockModel.TimeDisplayMode:
            int timeInt   = (int)clockModel.time;
            int timeIntPM = (int)(clockModel.time - ClockModel.TwelveHoursInSeconds);

            // If time is less than or equal to 12 hours in seconds, change the time period
            if (clockModel.time >= 0 && clockModel.time < ClockModel.TwelveHoursInSeconds && clockModel.period == TimePeriod.PM)
            {
                clockModel.period         = TimePeriod.AM;
                clockView.periodText.text = ClockModel.AM;
            }

            // If time is greater than than or equal to 24 hours in seconds, change the time period
            else if (clockModel.time >= ClockModel.TwelveHoursInSeconds && clockModel.time < (ClockModel.TwelveHoursInSeconds * 2) && clockModel.period == TimePeriod.AM)
            {
                clockModel.period         = TimePeriod.PM;
                clockView.periodText.text = ClockModel.PM;
            }

            // If time pasts 24hr, refresh to 0
            if (clockModel.time >= ClockModel.TwentyFourHoursInSeconds)
            {
                clockModel.time -= ClockModel.TwentyFourHoursInSeconds;
            }

            switch (clockView.timeDropdown.captionText.text)
            {
            case ClockModel.TwentyFour_HourMinuteFormat:
                DisplayDigital(clockView, ClockModel.HourMinuteDisplay, timeInt);
                break;

            case ClockModel.Twelve_HourMinuteFormat:
                // Check time period to see if hour values need to be reduced for 12hr time
                if (clockModel.period == TimePeriod.PM)
                {
                    Adjust12HourTime(clockView, timeIntPM, ClockModel.HourMinuteDisplay);
                }
                else
                {
                    Adjust12HourTime(clockView, timeInt, ClockModel.HourMinuteDisplay);
                }
                break;

            case ClockModel.TwentyFour_HourMinuteSecondsFormat:
                DisplayDigital(clockView, ClockModel.HourMinuteSecondDisplay, timeInt);
                break;

            case ClockModel.Twelve_HourMinuteSecondsFormat:
                // Check time period to see if hour values need to be reduced for 12hr time
                if (clockModel.period == TimePeriod.PM)
                {
                    Adjust12HourTime(clockView, timeIntPM, ClockModel.HourMinuteSecondDisplay);
                }
                else
                {
                    Adjust12HourTime(clockView, timeInt, ClockModel.HourMinuteSecondDisplay);
                }
                break;
            }

            break;

        case ClockModel.TimerMode:
            int timerInt = (int)clockModel.timer;

            // Displays the timer value in 00:00:00 format if timer value is 0 or greater
            if (timerInt >= 0)
            {
                DisplayDigital(clockView, ClockModel.HourMinuteSecondDisplay, timerInt);
            }

            break;

        case ClockModel.StopwatchMode:
            int stopwatchInt = (int)clockModel.stopwatch;

            // Creating a variable where the decimal values of stopwatch can be used as an integer (needed for display code)
            float stopwatchDecimals    = (clockModel.stopwatch - stopwatchInt) * 100;
            int   stopwatchIntDecimals = (int)stopwatchDecimals;

            // Displays the stopwatch value in 00:00:00.00 format
            DisplayDigital(clockView, ClockModel.HourMinuteSecondMillisecondDisplay, stopwatchInt, false, stopwatchIntDecimals);

            break;
        }
    }
Beispiel #25
0
 public void AddRemainTime(ClockModel model)
 {
     RemainTime.Add(model);
 }
Beispiel #26
0
 // Set the stopwatch value to 0 and display it on UI
 public void ResetStopwatch(ClockModel clockModel, ClockView clockView)
 {
     clockModel.stopwatch = 0;
     SetNumberDisplay(clockModel, clockView);
 }
Beispiel #27
0
 public void RemoveRemainTime(ClockModel model)
 {
     RemainTime.Remove(model);
 }
        public async Task <ActionResult> ConfirmClockVehicle(ClockModel cModel)
        {
            //Due to the lack of an auth/identitfy of the driver
            //This would is acting as a placeholder for the current driver ID
            Guid driverID = Guid.NewGuid();

            string updateResponse = null;

            //If clock in, check for damages against the AI service
            if (cModel.clock == "In")
            {
                //Generate a new ID for the potential damage model
                Guid damageID = Guid.NewGuid();

                //Create ImageDTO list for each image to be added as we go through the loop of uploads.
                List <ImageDTO> vehicleImages = new List <ImageDTO>();

                //Set state of tracking = null
                //Used to track the verdict.
                //This allows to continue processing all uploaded images but still know that one showed damage
                string verdictTracker = "Undamaged";
                //Set counter to 0. This is used to add a suffix count to the end of the image filename when uploaded
                int count = 0;

                //Loop through uploads
                foreach (IFormFile img in cModel.imgs)
                {
                    //Increment the count
                    count++;
                    //Create a new image DTO.
                    ImageDTO newImageDTO = ImageDTO.CreateDTO(ImageDTO.GenerateImageId(damageID, cModel.time, count.ToString(), img), img);
                    vehicleImages.Add(newImageDTO);

                    try
                    {
                        //Check the damage of the images against the AI model
                        APIDTO returnApiDto = await _damageService.DamageCheckImg(newImageDTO);

                        //Extract at the decimal percentage of guesses for each tag
                        double damagedGuess = returnApiDto.predictions.FirstOrDefault(x => x.tagName == "Damaged").probability;
                        double wholeGuess   = returnApiDto.predictions.FirstOrDefault(x => x.tagName == "Whole").probability;

                        //If both results are over 0.1 then cant say for certain. i.e level of uncertainty
                        //This is to make sure a Staff member will manually resolve it
                        if (wholeGuess >= 0.1 && damagedGuess >= 0.1)
                        {
                            //If not already set to damage from previous image.
                            //Test this because Damaged is a stronger case than Inclonclusive
                            if (verdictTracker == "Undamaged")
                            {
                                verdictTracker = "Inconclusive";
                            }
                        }
                        //If the verdict is Damaged
                        else if (damagedGuess > wholeGuess)
                        {
                            //If Damaged then overrules the above conclusion of a previous image
                            verdictTracker = "Damaged";
                        }
                    }
                    catch
                    {
                        //In any case of an error, set to Inclousive
                        verdictTracker = "Inconclusive";
                    }
                }

                //After loop of images, check the state.
                //If either damage or incloncsive
                if (verdictTracker != "Undamaged")
                {
                    try
                    {
                        //Set the new state to
                        if (verdictTracker == "Inconclusive")
                        {
                            cModel.clock = "Inconclusive";
                        }
                        //Damaged
                        else
                        {
                            cModel.clock = "Damaged";
                        }

                        //Create and Insert a Damage history record to keep track of vehicle damages
                        DamageHistoryDTO newDamageDTO = DamageHistoryDTO.CreateDTO(DamageHistoryModel.CreateModel(cModel, damageID, driverID));
                        updateResponse = await _vehicleService.InsertDamageHistoryAsync(newDamageDTO);

                        if (updateResponse != "Success")
                        {
                            return(RedirectToAction("ClockVehicle"));
                        }

                        //Update Vehicle with new state
                        cModel.vehicle.state = "Under Investigation";
                        VehicleDTO newVehDto = VehicleDTO.CreateDTO(cModel.vehicle);
                        updateResponse = await _vehicleService.UpdateVehicleAsync(newVehDto);

                        if (updateResponse != "Success")
                        {
                            return(RedirectToAction("ClockVehicle"));
                        }

                        //Loop and upload images to blob storage
                        foreach (ImageDTO img in vehicleImages)
                        {
                            //Save Images to the blob storage.
                            updateResponse = await _blobService.UploadImage(img);

                            if (updateResponse != "Success")
                            {
                                return(RedirectToAction("ClockVehicle"));
                            }
                        }

                        //Return back to confirmed view
                        return(View("ClockConfirmed", cModel));
                    }
                    catch
                    {
                        //if error at anypoint, restart the form by rdirecting to initial action
                        return(RedirectToAction("ClockVehicle"));
                    }
                }
            }

            //Update state of the vehicle in vehicle table
            cModel.vehicle.state = cModel.clock;
            VehicleDTO vehDTO = VehicleDTO.CreateDTO(cModel.vehicle);

            updateResponse = await _vehicleService.UpdateVehicleAsync(vehDTO);

            if (updateResponse != "Success")
            {
                return(RedirectToAction("ClockVehicle"));
            }

            //Insert into the history table.
            //Note: The DriverID would be replaced with identification if implemented as mentioned above
            Guid            historyID = Guid.NewGuid();
            ClockHistoryDTO newDTO    = ClockHistoryDTO.CreateDTO(cModel, historyID, driverID);

            updateResponse = await _vehicleService.InsertClockHistoryAsync(newDTO);

            if (updateResponse != "Success")
            {
                return(RedirectToAction("ClockVehicle"));
            }

            //Return back to confirmed view
            return(View("ClockConfirmed", cModel));
        }