This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
from typing import List, Tuple | |
def get_start_end_times_from_dataframe_based_on_binary_condition(pd_timestamp_series:pd.Series, pd_binary_condition_series:pd.Series)->List[Tuple[int]]: | |
"""Find all contiguous chunks of time where some condition was either True or False. | |
Given a Pandas DataFrame that has timestamp information (e.g., Unix Time in ms) and some column where the values are either True or False, this function | |
will find the start and end times, along with what the value was for that slice of time, for all chunks present, returning them as a list of tuples. | |
NOTE: While it could be argued that this would work for categorical conditions (i.e., non-binary conditions), I personally did not write this function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os.path import join | |
from subprocess import run, TimeoutExpired, CalledProcessError, check_output | |
from typing import List | |
def run_command(command_args: List[str]=None, timeout_duration: int=30) -> None: | |
""" | |
Run a command via subprocessing. | |
Attempts to run the command given, with a timeout_duration (default 30s). | |
If the command cannot finish executing, then it will return a TimeoutError. |