from datetime import datetime


def read_daily_line(line):
    """
    Parses one line from a DailyFile and returns a dictionary containing the parameters by name.

    One line is parsed such that Daily(**read_daily_line(line)) creates a Daily instance successfully. Values are all
    returned as floats.

    :param str line: the line to be read, including whitespace since it will be parsed by splitting on tabs
    :return: dict
    """
    dailydata = {}
    ls = line.split('\t')
    try:
        dailydata['date'] = datetime.strptime(line.split('\t')[0].split('.')[0], '%y%j%H%M')
        dailydata['ads_xfer_temp'] = float(ls[1])
        dailydata['valves_temp'] = float(ls[2])
        dailydata['gc_xfer_temp'] = float(ls[3])
        dailydata['ebox_temp'] = float(ls[4])
        dailydata['catalyst_temp'] = float(ls[5])
        dailydata['molsieve_a_temp'] = float(ls[6])
        dailydata['molsieve_b_temp'] = float(ls[7])
        dailydata['inlet_temp'] = float(ls[8])
        dailydata['room_temp'] = float(ls[9])
        dailydata['v5'] = float(ls[10])
        dailydata['mfc1'] = float(ls[11])
        dailydata['mfc2'] = float(ls[12])
        dailydata['mfc3'] = float(ls[13])
        dailydata['he_pressure'] = float(ls[14])
        dailydata['linep'] = float(ls[15])
        dailydata['zerop'] = float(ls[16])
    except ValueError:
        print('ValueError while reading line from DailyFile.')

    return dailydata