diff --git a/SemesterProject-CPU-Temps/python3/parseTempsDemo.py b/SemesterProject-CPU-Temps/python3/parseTempsDemo.py index 9f1f6bbd1d865d8da9bd7affd870f9110304ceeb..31ee5347ae0ef725b9ce7e7d920c5236c54e27a4 100755 --- a/SemesterProject-CPU-Temps/python3/parseTempsDemo.py +++ b/SemesterProject-CPU-Temps/python3/parseTempsDemo.py @@ -13,12 +13,9 @@ def main(): """ input_temps = sys.argv[1] - includes_units = sys.argv[2] == "yes" # set to False for files without units - - print(includes_units) with open(input_temps, 'r') as temps_file: - for temps_as_floats in parse_raw_temps(temps_file, units=includes_units): + for temps_as_floats in parse_raw_temps(temps_file): print(temps_as_floats) diff --git a/SemesterProject-CPU-Temps/python3/parse_temps.py b/SemesterProject-CPU-Temps/python3/parse_temps.py index 07d71899b53ffebfcc095040c22e53e790b33b65..1954636869f8cf2a37b5bbc0aaebb94818b7cd8f 100755 --- a/SemesterProject-CPU-Temps/python3/parse_temps.py +++ b/SemesterProject-CPU-Temps/python3/parse_temps.py @@ -7,13 +7,12 @@ All code may be used freely in the semester project, iff it is imported using represents one or more functions. """ - +import re from typing import (TextIO, Iterator, List, Tuple) def parse_raw_temps(original_temps: TextIO, - step_size: int = 30, - units: bool = True) -> Iterator[Tuple[float, List[float]]]: + step_size: int = 30) -> Iterator[Tuple[float, List[float]]]: """ Take an input file and time-step size and parse all core temps. @@ -22,17 +21,13 @@ def parse_raw_temps(original_temps: TextIO, step_size: time-step in seconds - units: True if the input file includes units and False if the file - includes only raw readings (no units) - Yields: A tuple containing the next time step and a List containing _n_ core temps as floating point values (where _n_ is the number of CPU cores) """ - if units: - for step, line in enumerate(original_temps): - yield (step * step_size), [float(entry[:-2]) for entry in line.split()] - else: - for step, line in enumerate(original_temps): - yield (step * step_size), [float(entry) for entry in line.split()] + split_re = re.compile(r"[^0-9]*\s+|[^0-9]*$") + + for step, line in enumerate(original_temps): + yield (step * step_size), \ + [float(entry) for entry in split_re.split(line) if len(entry) > 0]