"""
Created on Sat Jan 10 21:40:00 2026
@author: Lluís Vila
(c) 2025-26
"""
from is_float import is_float


def convert_temp_line(templineL):
    return [float(s) for s in templineL if is_float(s)]


def dict_append(d, name, tempL):
    if name not in d:
        d[name] = tempL
    else:
        d[name].extend(tempL)


def temp_join(in_filename, out_filename):

    d = {}
    
    with open(in_filename, 'r') as fin:
        for line in fin:
            lineL = line.strip().split(',')
            name = lineL[0]
            tempL = convert_temp_line(lineL[1:])
            dict_append(d, name, tempL)

    with open(out_filename, 'w') as fout:
        for name in d:
            tempL = d[name]
            lineL = [name, str(min(tempL)), str(max(tempL)), str(len(tempL))] + [str(x) for x in tempL]
            line = ','.join(lineL) + '\n'
            fout.write(line)
            
    return len(d)


