Exemplo n.º 1
0
def write_weka_file_for_each_user(data, attributes):
    all_users = {}

    for row in data:
        userid = row[len(row) - 1]  # User ID is the last element in list

        # Get User data from row and add to user dictionary
        # try to get existing key, and append to the existing list in value
        try:
            user_list = all_users[userid]
            user_list.append(row)
            all_users[userid] = user_list

        except KeyError:
            # If doesn't exist, create the list
            user_list = [row]
            all_users[userid] = user_list

    for user, userdata in all_users.items():
        weka_data = {
            'description': 'Data for ' + user,
            'relation': 'SensorRecordings',
            'attributes': attributes,
            'data': userdata,
        }

        # Write Weka formatted file for entire cohort
        f = open(out_dir[0] + '/' + user + '.arff', 'w')
        f.write(arff.dumps(weka_data))
        f.close()
Exemplo n.º 2
0
def write_weka_file_for_cohort(data, attributes):
    weka_data = {
        'description': '',
        'relation': 'sensors',
        'attributes': attributes,
        'data': data,
    }
    f = open(out_dir[0] + '/cohort.arff', 'w')
    f.write(arff.dumps(weka_data))
    f.close()