Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete in Python. Attached are the two Python files given. Attached is parseTempsDemo.py: # ! / usr / bin / env python 3 import sys

Complete in Python.
Attached are the two Python files given.
Attached is parseTempsDemo.py:
#!/usr/bin/env python3
import sys
from parse_temps import (parse_raw_temps)
def main():
"""
This main function serves as the driver for the demo. Such functions
are not required in Python. However, we want to prevent unnecessary module
level (i.e., global) variables.
"""
input_temps = sys.argv[1]
with open(input_temps, 'r') as temps_file:
# -----
# Output raw structure
# ------
for temps_as_floats in parse_raw_temps(temps_file):
print(temps_as_floats)
with open(input_temps, 'r') as temps_file:
# ------
# Split data
# ----
for temps_as_floats in parse_raw_temps(temps_file):
time, core_data = temps_as_floats
print(f"{time =}|{core_data =}")
with open(input_temps, 'r') as temps_file:
# --------
# Split Data
# --------
times =[]
core_0_data =[]
core_1_data =[]
core_2_data =[]
core_3_data =[]
for time, core_data in parse_raw_temps(temps_file):
times.append(time)
core_0_data.append(core_data[0])
core_1_data.append(core_data[1])
core_2_data.append(core_data[2])
core_3_data.append(core_data[3])
print(f"{times[:4]=}")
print(f"{core_0_data[:4]=}")
for time, *temps in list(zip(times, core_0_data, core_1_data, core_2_data, core_3_data))[4:]:
print(f"{time=}{temps=}")
with open(input_temps, 'r') as temps_file:
# ------
# Split Data, but Better!
# -----------
times =[]
core_data =[[] for _ in range(0,4)]
for time, raw_core_data in parse_raw_temps(temps_file):
times.append(time)
for core_idx, reading in enumerate(raw_core_data):
core_data[core_idx].append(reading)
for time, *temps in list(zip(times,*core_data))[4:]:
print(f"{time=}{temps=}")
if __name__=="__main__":
main()
Attached is parse_temps.py:
#!/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.
"""
import re
from typing import (TextIO, Iterator, List, Tuple)
def parse_raw_temps(original_temps: TextIO,
step_size: int =30)-> 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
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)
"""
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]
Your program must accept an input filename as the first command line argument. Your program must NOT prompt the user for a filename.
All code must be properly and fully documented using a language appropriate comment style. All functions (including parameters and return types) must be documented.
Input Format:
Data takes the form of temperatures in a .txt file. All data points are whitespace delimited.
Attached is the input file input_temps:
61.063.050.058.0
80.081.068.077.0
62.063.052.060.0
83.082.070.079.0
68.069.058.065.0
Each line represents temperature readings from 4 processor cores. Readings are taken every 30 seconds. In this example:
line 1 is 0 sec.
line 2 is 30 sec.
line 3 is 60 sec.
line 4 is 90 sec.
line 5 is 120 sec.
We need to look at each of the four cores independently. This means that each input file is really four (4) sets of temperature data.
Output Format:
All output must be written to text files (one file per core). Each line must take the form:
xk = x xk+1 ; yi = c0+ c1x ; type
where
xk and xk+1 are the domain in which yk is applicable
yk is the k^th function
type is interpolation
For the example data from the input file would generate 4 output files.
{basename}-core-0.txt,{basename}-core-1.txt,{basename}-core-2.txt,{basename}-core-3.txt
where {basename} is the input file name without the extension (e.g., without the .txt or .dat).
Expected Output:
Given the five-line input file input_temps:
we would end up with four output files...
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

9.1 Concepts of Hypothesis Testing

Answered: 1 week ago

Question

8. Explain the contact hypothesis.

Answered: 1 week ago

Question

7. Identify four antecedents that influence intercultural contact.

Answered: 1 week ago