Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

need this activetime in brailletime to reset to back zero when it's done through in…

  1. User

    need this activetime in brailletime to reset to back zero when it's done through in function activity. try fix it: let overallStartTime = null; let isFirstGeneration = true; let brailleStartTime = Date.now(); function handleProgressBar() { const progressBarFilled = document.querySelector('.progress-bar-filled'); const currentTime = Date.now(); const normalSecondsPassed = Math.max(Math.round((currentTime - overallStartTime) / 1000) - 1, 0); const brailleSecondsPassed = Math.max(Math.round((currentTime - brailleStartTime) / 100) - 1, 0); function mapToBraille(time) { const brailleDigits = ['⠝', '⠷', '⠾', '⠄', '⠑', '⠭', '⠱', '⠚', '⠆', '⠤']; const seconds = Math.floor(time) % 1000; let brailleResult = ''; // Map seconds to braille characters const secondsString = seconds.toString().padStart(3, '0'); for (let i = 0; i < secondsString.length; i++) { const digit = parseInt(secondsString[i]); if (!isNaN(digit)) { brailleResult += brailleDigits[digit]; } } return brailleResult; } if (isGenerating) { const activeTime = normalSecondsPassed - Math.floor(normalSecondsPassed / 10); const brailleTime = mapToBraille(brailleSecondsPassed); progressBarFilled.innerHTML = brailleTime + '&nbsp;&nbsp;' + activeTime + '&nbsp;sec'; } else { const brailleTime = mapToBraille(brailleSecondsPassed); progressBarFilled.innerHTML = '⠿⠿⠿' + '&nbsp;&nbsp;' + normalSecondsPassed + '&nbsp;sec'; } } async function generateImage() { if (isGenerating || autoQueueActive) { return; } if (galleryArray.length >= totalLimit) { if (autoSaveEnabled) { saveAllImages().then(() => { clearGallery(); }); } else { clearGallery(); } return; } function updateProgress() { handleProgressBar(); if (isGenerating) { requestAnimationFrame(updateProgress); } } function clearGallery() { galleryArray.length = 0; updateImageCounter(); bufferContainer.innerHTML = ''; if (autoQueueActive) { generateInterval = setInterval(generateImage, interval); } } isGenerating = true; startTime = Date.now(); overallStartTime = Date.now(); updateProgress();

  2. Assistant

    Based on the provided code, it seems like you want the brailleStartTime to be reset to zero whenever the function handleProgressBar is called through the generateImage function.

    To achieve this, you can add a line of code within the generateImage function to reset the brailleStartTime to the current time. Here's the modified code:

    async function generateImage() {
      if (isGenerating || autoQueueActive) {
        return;
      }
      if (galleryArray.length >= totalLimit) {
        if (autoSaveEnabled) {
          saveAllImages().then(() => {
            clearGallery();
          });
        } else {
          clearGallery();
        }
        return;
      }
    
      // Reset brailleStartTime to current time
      brailleStartTime = Date.now();
    
      function updateProgress() {
        handleProgressBar();
        if (isGenerating) {
          requestAnimationFrame(updateProgress);
        }
      }
    
      // Rest of the code...
    }
    

    By resetting brailleStartTime to the current time before calling handleProgressBar within the generateImage function, you ensure that it starts counting from zero every time the generateImage function is triggered.