#!python3
import csv


def break_up_into_sessions(pathToData):
    with open(pathToData, 'r') as f:
        reader = csv.DictReader(f, delimiter='\t')
        allData = []
        for line in reader:
            allData.append(line)
    # print(allData)

    individualSessions = []
    SID = []
    currentID = allData[0]['RECORDING_SESSION_LABEL']
    for session in allData:
        if session['RECORDING_SESSION_LABEL'] == currentID:
            SID.append(session)
        else:
            individualSessions.append(SID)

            with open("./rawData/individualSession_" +
                      SID[0]['RECORDING_SESSION_LABEL'] + ".csv", "w") as f:
                writer = csv.DictWriter(f, SID[0].keys())
                writer.writeheader()
                writer.writerows(SID)

            # with open('eggs.csv', 'w', newline='') as csvfile:

            SID = []
            currentID = session['RECORDING_SESSION_LABEL']
            SID.append(session)
