using Mmap mutable struct StationMeasurements min::Float64 max::Float64 sum::Float64 count::Int64 end function update(sm, temp::Float64) if temp < min sm.min = temp elseif temp > max sm.max = temp end sm.sum += temp sm.count += 1 end function print_measurements(stations::Dict{String,StationMeasurements}) sorted_keys = sort(collect(keys(stations))) print("{") sm_vec = [] for city in sorted_keys sm = stations[city] min = round(sm.min; digits=1) max = round(sm.max; digits=1) avg = round((sm.sum / sm.count); digits=1) push!(sm_vec, "$city=$min/$avg/$max") end joined = join(sm_vec, ", ") print(joined) print("}") end function main() open("../../../measurements.txt", "r") do f println("Start") stations = Dict{String,StationMeasurements}() iteration = 0 for line in eachline(f) if iteration % 1000000 == 0 && iteration > 0 print("\x1b[J\x1b[H") percent = round((iteration / 1000000000) * 100; digits=2) println("$(percent)%") end station, temp_str = rsplit(line, ";") temp = parse(Float32, temp_str) if haskey(stations, station) sm = stations[station] sm.min = ifelse(temp < sm.min, temp, sm.min) sm.max = ifelse(temp > sm.max, temp, sm.max) sm.sum += temp sm.count += 1 else stations[station] = StationMeasurements(temp, temp, temp, 1) end iteration += 1 end print_measurements(stations) println("End") end end main()