def csv_2_dict_va_polar(path): ''' Function creates 2 dictionaries for valence and arousal for each song in csv key - song id value - array of values ''' print 'rendering csv file' # read csv ifile = open(path, "rb") reader = csv.reader(ifile) # dict: key => song id, # value => array of valence (1.dict) arousal (2. dict) r = {} theta = {} # parse csv for row in reader: # print row[81] key = int(row[81]) if key not in r: r[key] = [] theta[key] = [] for i in range(82+20, 129, 2): if float(row[i]) <= 1 and float(row[i+1]) <= 1: rr, ttheta = cart2polar(float(row[i]), float(row[i+1])) r[key].append(rr) theta[key].append(ttheta) return r, theta
def csv_2_dict_va_polar(path): ''' Function creates 2 dictionaries for valence and arousal for each song in csv key - song id value - array of values ''' print 'rendering csv file' # read csv ifile = open(path, "rb") reader = csv.reader(ifile) # dict: key => song id, # value => array of valence (1.dict) arousal (2. dict) r = {} theta = {} # parse csv for row in reader: # print row[81] key = int(row[81]) if key not in r: r[key] = [] theta[key] = [] for i in range(82 + 20, 129, 2): if float(row[i]) <= 1 and float(row[i + 1]) <= 1: rr, ttheta = cart2polar(float(row[i]), float(row[i + 1])) r[key].append(rr) theta[key].append(ttheta) return r, theta
def uniform_va_rgb_polar(path): ''' Function returns va and rgb for this responses where only one mood was selected ''' print 'rendering csv file' # read csv ifile = open(path, "rb") reader = csv.reader(ifile) # dict: key => song id, # value => array of valence (1.dict) arousal (2. dict) rrr = [] tetha = [] id = [] r = [] g = [] b = [] for row in reader: rr = 0 ttetha = 0 count = 0 for i in range(82 + 20, 129, 2): if float(row[i]) <= 1 and float(row[i + 1]) <= 1: va = float(row[i]) ar = float(row[i + 1]) rr, ttheta = cart2polar(va, ar) count += 1 if count == 1: rrr.append(rr) tetha.append(ttheta) id.append(int(row[81])) red, green, blue = colorsys.hsv_to_rgb(float(row[132]), float(row[133]), float(row[134])) r.append(red) g.append(green) b.append(blue) return id, rrr, tetha, r, g, b
def uniform_va_rgb_polar(path): ''' Function returns va and rgb for this responses where only one mood was selected ''' print 'rendering csv file' # read csv ifile = open(path, "rb") reader = csv.reader(ifile) # dict: key => song id, # value => array of valence (1.dict) arousal (2. dict) rrr = [] tetha = [] id = [] r = [] g = [] b = [] for row in reader: rr=0 ttetha=0 count = 0 for i in range(82+20, 129, 2): if float(row[i]) <= 1 and float(row[i+1]) <= 1: va = float(row[i]) ar = float(row[i+1]) rr, ttheta = cart2polar(va,ar) count += 1 if count == 1: rrr.append(rr) tetha.append(ttheta) id.append(int(row[81])) red, green, blue = colorsys.hsv_to_rgb(float(row[132]), float(row[133]), float(row[134])) r.append(red) g.append(green) b.append(blue) return id, rrr, tetha, r, g, b
def uniform_va_hsv_polar(path): ''' Function returns va and hsv for this responses where only one mood was selected ''' print 'rendering csv file' # read csv ifile = open(path, "rb") reader = csv.reader(ifile) # dict: key => song id, # value => array of valence (1.dict) arousal (2. dict) rrr = [] tetha = [] id = [] h = [] s = [] v = [] for row in reader: rr=0 ttetha=0 count = 0 for i in range(82+20, 129, 2): if float(row[i]) <= 1 and float(row[i+1]) <= 1: va = float(row[i]) ar = float(row[i+1]) rr, ttheta = cart2polar(va,ar) count += 1 if count == 1: tetha.append(ttheta) rrr.append(rr) id.append(int(row[81])) h.append(float(row[132])) s.append(float(row[133])) v.append(float(row[134])) return id, rrr, tetha, h, s, v
def uniform_va_hsv_polar(path): ''' Function returns va and hsv for this responses where only one mood was selected ''' print 'rendering csv file' # read csv ifile = open(path, "rb") reader = csv.reader(ifile) # dict: key => song id, # value => array of valence (1.dict) arousal (2. dict) rrr = [] tetha = [] id = [] h = [] s = [] v = [] for row in reader: rr = 0 ttetha = 0 count = 0 for i in range(82 + 20, 129, 2): if float(row[i]) <= 1 and float(row[i + 1]) <= 1: va = float(row[i]) ar = float(row[i + 1]) rr, ttheta = cart2polar(va, ar) count += 1 if count == 1: tetha.append(ttheta) rrr.append(rr) id.append(int(row[81])) h.append(float(row[132])) s.append(float(row[133])) v.append(float(row[134])) return id, rrr, tetha, h, s, v