function convertStringToArray(string) {
  const numberStrings = string.replace(/[{}]/g, '').split(',');

  // Trim whitespace and convert the string numbers to integers
  const numberArray = numberStrings.map(num => parseInt(num.trim(), 10));

  return numberArray;
}

function filterAndSortMeasurementsByIds(measurements, ids) {
  return measurements
    .filter((measurement) => ids.includes(measurement.id))
    .sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp));
}
function filterAndSortMeasurementsByNumber(measurements, Numbers) {
  // Filter measurements based on their position in the Numbers array
  const filteredMeasurements = Numbers.map(index => measurements[index - 1]).filter(measurement => measurement !== undefined);

  // Sort the filtered measurements by their timestamp
  return filteredMeasurements.sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp));
}

function checkVideoPath(videos, name) {
  let res = true;
  videos.forEach(video => {
      const videoName = video.name;
      if(videoName==name)
        res=false;
  });
  return res;
}



function getMeasurementsIdsFromForm(choice, firstInput, lastInput) {
  if (choice === 'oneByOne') {
    const highlightedButtons = document.querySelectorAll('.number-button.highlight');
    return Array.from(highlightedButtons).map(button => parseInt(button.textContent));
  } else {
    const first = parseInt(firstInput.value);
    const last = parseInt(lastInput.value);
    const denominator = parseInt(document.getElementById('denominator').value);

    const measurementIds = new Set();
    measurementIds.add(first); // Always include the first image
    // Iterate through the range, adding the step size
    for (let i = first + denominator; i <= last; i += denominator) {
      measurementIds.add(i);
    }

    measurementIds.add(last); // Always include the last image

    // Convert the Set back to an array and sort it
    return Array.from(measurementIds).sort((a, b) => a - b);
  }
}