Balloon sounding layers
MediumOnline Assessment
Turn the raw telemetry of weather-balloon flights into one temperature profile per flight.
Each record is a string "flight,second,altitude,temp": the flight id, the seconds since that flight's launch, the altitude in metres, and the air temperature in tenths of a degree Celsius (so -123 means -12.3 degrees). The altitude or the temperature may be "-" when the sensor sent nothing. Records of different flights are mixed together and records of one flight may arrive in any order.
Clean and summarise the data like this:
- Discard every record whose altitude is
"-"before doing anything else. - If a flight still has several records with the same
second, only the one listed last survives. - Order each flight's records by
second, numerically. The flight's burst altitude is the highest altitude among its records, and the burst is the earliest record that has that altitude. Everything after the burst is the descent and is ignored; the burst itself and everything before it are the ascent. - A record at altitude
abelongs to layera // 1000(layer 0 is 0-999 m, layer 1 is 1000-1999 m, and so on). Only records with a temperature are readings. A layer is reported only if the ascent has at least 2 readings in it, and its value is their mean, rounded to the nearest whole tenth, with exact halves rounded away from zero (50.5becomes51,-25.5becomes-26).
A flight with no records left after step 1 does not appear in the output.
Input: records, a list of strings in the format above. Flight ids contain only letters and digits and never contain a comma.
Output: a list with one entry per remaining flight, sorted by flight id in plain string order. Each entry is [flight, burst_altitude, layers], where layers is a list of [layer, mean_temp] pairs in increasing layer order (possibly empty).
Example 1
- Input:
- [["K2,120,2300,-40","K2,0,100,100","K2,30,900,80","K2,60,1400,10","K2,60,1500,30","K2,90,-,20","K2,110,2100,-35","K2,150,1800,5"]]
- Output:
- [["K2",2300,[[0,90],[2,-38]]]]
- Explanation
- Flight
K2: the record at second 90 has no altitude and is dropped. Two records share second 60, so only the later-listed one (1500 m, temp 30) is kept. Sorted by second, the highest altitude is 2300 m at second 120; the record at second 150 is descent and ignored. Layer 0 holds temps 100 and 80 (mean 90). Layer 1 holds only the temp 30, a single reading, so it is not reported. Layer 2 holds -35 and -40, mean -37.5, which rounds away from zero to -38.
Example 2
- Input:
- [["A1,0,500,51","A1,20,800,50","A1,40,1200,-25","A1,60,1900,-26","A1,80,2600,-"]]
- Output:
- [["A1",2600,[[0,51],[1,-26]]]]
- Explanation
- Flight
A1: layer 0 holds 51 and 50, mean 50.5, rounded away from zero to 51. Layer 1 holds -25 and -26, mean -25.5, rounded away from zero to -26. The burst record (2600 m) has no temperature, so it is a record but not a reading and layer 2 has no readings.
Example 3
- Input:
- [["B3,0,200,150","Z9,5,-,10","B3,10,600,140","B3,30,1000,120","B3,50,1900,100","Z9,9,-,12","B3,70,3000,60","B3,90,1500,40","B3,110,3000,55"]]
- Output:
- [["B3",3000,[[0,145],[1,110]]]]
- Explanation
- Flight
Z9has only records without altitude, so it is not in the output. FlightB3first reaches 3000 m at second 70; the dip to 1500 m at second 90 and the second 3000 m record at second 110 are descent and ignored. Layer 0 holds 150 and 140 (mean 145), layer 1 holds 120 and 100 (mean 110), and layer 3 has only the burst reading (60), so it is not reported.
Constraints
0 <= len(records) <= 400- each record is
"flight,second,altitude,temp"with a flight id of 1 to 6 letters or digits secondis an integer with0 <= second <= 100000;altitudeis an integer with0 <= altitude <= 40000, or"-";tempis an integer between-900and500, or"-"- records of different flights may be interleaved, and records of one flight may be listed in any order