#K62617. Weather Data Summary

    ID: 31572 Type: Default 1000ms 256MiB

Weather Data Summary

Weather Data Summary

You are given weather station data, where each record consists of a timestamp, temperature, humidity, and wind_speed. Your task is to compute summary statistics for the temperature, humidity, and wind_speed readings. For each of these three metrics, you should calculate the minimum, maximum, average, and median values.

The input is provided via standard input (stdin) and the output should be printed to standard output (stdout) in JSON format. The output JSON should have three keys: temperature, humidity, and wind_speed. Each key maps to an object with four keys: min, max, average, and median.

Note that if the number of records is even, the median is the average of the two middle numbers. When printing results, do not perform any extra formatting—the raw computed floating point numbers are acceptable. Use the following formulas in LaTeX format for your calculations:

  • Minimum: $\min\{x_1, x_2, \dots, x_n\}$
  • Maximum: $\max\{x_1, x_2, \dots, x_n\}$
  • Average: $\frac{\sum_{i=1}^{n} x_i}{n}$
  • Median: \(\text{if } n \text{ is even, } \frac{x_{n/2} + x_{n/2 + 1}}{2}\text{; otherwise } x_{(n+1)/2}\)

The records are provided as follows: The first line contains an integer n representing the number of weather readings. Each of the next n lines contains a weather record with four fields separated by spaces:

  • timestamp (a string without spaces)
  • temperature (a float)
  • humidity (an integer)
  • wind_speed (a float)

Your program must correctly compute and output the summarized statistics in JSON format.

inputFormat

Input Format:

  • The first line contains an integer n, the number of weather readings.
  • Each of the next n lines contains a weather record in the following format:
    timestamp temperature humidity wind_speed

For example:

4
2023-05-01T14:00:00 22.5 55 5.5
2023-05-01T15:00:00 23.0 60 6.0
2023-05-01T16:00:00 21.5 58 5.0
2023-05-01T17:00:00 22.0 57 5.8

outputFormat

Output Format:

The program must output a single JSON object with the following structure:

{
  "temperature": {"min": value, "max": value, "average": value, "median": value},
  "humidity": {"min": value, "max": value, "average": value, "median": value},
  "wind_speed": {"min": value, "max": value, "average": value, "median": value}
}

All numeric values should be output as floating point numbers.

## sample
4
2023-05-01T14:00:00 22.5 55 5.5
2023-05-01T15:00:00 23.0 60 6.0
2023-05-01T16:00:00 21.5 58 5.0
2023-05-01T17:00:00 22.0 57 5.8
{"temperature":{"min":21.5,"max":23.0,"average":22.25,"median":22.25},"humidity":{"min":55.0,"max":60.0,"average":57.5,"median":57.5},"wind_speed":{"min":5.0,"max":6.0,"average":5.575,"median":5.65}}