0% found this document useful (0 votes)
20 views1 page

Max Temperature Mapper and Reducer

The document contains two Python scripts, 'mapper.py' and 'reducer.py', designed for processing temperature data. The mapper reads input data, extracts the date and temperature, and outputs them in a key-value format. The reducer then calculates and outputs the maximum temperature for each date from the mapper's output.

Uploaded by

siddharthrishi17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

Max Temperature Mapper and Reducer

The document contains two Python scripts, 'mapper.py' and 'reducer.py', designed for processing temperature data. The mapper reads input data, extracts the date and temperature, and outputs them in a key-value format. The reducer then calculates and outputs the maximum temperature for each date from the mapper's output.

Uploaded by

siddharthrishi17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

mapper.

py

#!/usr/bin/env python
import sys
for line in [Link]: # Read input from STDIN (standard input)
line = [Link]() # Remove any leading/trailing whitespace
sensor_id, date, hour, temperature = [Link](",") # Split the line into
sensor_Id, date, hour, temperature
print("{0}\t{1}".format(date, temperature)) # Emit the date as the key and
temperature as the value

----------------------------

[Link]
#!/usr/bin/env python
import sys
# Initialize variables to store the current date and the maximum temperature
current_date = None
max_temperature = -float("inf")
for line in [Link]: # Read input from STDIN (standard input)
line = [Link]() # Remove any leading/trailing whitespace
date, temperature = [Link]("\t") # Parse the input we got from the mapper
temperature = float(temperature)
if current_date == date: # Check if we are still processing the same date
if temperature > max_temperature: # Update the maximum temperature for the
current date
max_temperature = temperature
else:
if current_date: # If the date changes and it's not the first line
print("{0}\t{1}".format(current_date, max_temperature)) # Emit the
maximum temperature for the previous date
current_date = date # Update to the new date
max_temperature = temperature

if current_date: # Output the maximum temperature for the last date


print("{0}\t{1}".format(current_date, max_temperature))

You might also like