-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_temps.py
54 lines (41 loc) · 1.67 KB
/
parse_temps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /usr/bin/env python3
"""
This module is a collection of input helpers for the CPU Temperatures Project.
All code may be used freely in the semester project, iff it is imported using
``import parse_temps`` or ``from parse_temps import {...}`` where ``{...}``
represents one or more functions.
"""
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]]]:
"""
Take an input file and time-step size and parse all core temps.
Args:
original_temps: an input file
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()]
def get_values_count(filename: TextIO):
"""
Helper function to find the number of lines in the input file
Args:
filename: the file name of the file to count the number of lines
Yields:
The number of lines in the file
"""
count = 0
with open(filename, 'r') as f:
for line in f:
count += 1
return count