def get_face_data(person_data, emotion, frame_index): filepath = housekeeping.build_filepath({ 'person_data': person_data, 'emotion': emotion, 'frame_index': frame_index, 'data_type': 'face' }) with open(filepath, 'r') as file: data = [line[:-1].split(' ')[1:-1] for line in file.readlines()] data = [{"x": float(pair[0]), "y": float(pair[1])} for pair in data] return data
def get_embedding_data(specs): specs['data_type'] = 'dissimilarity' filepath = housekeeping.build_filepath(specs) indices = housekeeping.get_emotion_indices( specs.get('emotions'), F001_key if specs.get('person_data') == 'F001' else M001_key) print(indices) dissimilarities = housekeeping.filter_data( housekeeping.read_matrix_file(filepath, specs.get('non_metric')), indices) print(len(dissimilarities)) if specs.get('return_dissimilarity'): return dissimilarities embedding_data = housekeeping.embed({ 'perplexity': int(specs.get('perplexity')), 'key': F001_key if specs.get('person_data') == 'F001' else M001_key, 'focal_emotion': specs.get('focal_emotion'), 'frame_indices': specs.get('frame_indices'), 'embedding_type': specs.get('embedding_type'), 'dimension': 1 if specs.get('embedding_type') == 'reld' else 2, 'emotions': specs.get('emotions'), 'dissimilarities': dissimilarities }) if specs.get('embedding_type') != 'reld': embedding_data = embedding_data.fit_transform( np.asmatrix(dissimilarities)) return housekeeping.prepare_data( specs.get('emotions'), specs.get('embedding_type'), embedding_data, 1 if specs.get('embedding_type') == 'reld' else 2, F001_key if specs.get('person_data') == 'F001' else M001_key)
def get_persistence_diagram(section_list, person_data, emotion, frameNumber, nonMetric, twoD): filepaths = housekeeping.build_filepath({ 'section_list': section_list, 'person_data': person_data, 'emotion': emotion, 'frame_index': frameNumber, 'is_two_dimensional': twoD, 'non_metric': nonMetric, 'data_type': 'persistence' }) return { 'selection_1': housekeeping.read_persistence_file(filepaths['selection_1']), 'selection_2': housekeeping.read_persistence_file(filepaths['selection_2']), 'selection_3': housekeeping.read_persistence_file(filepaths['selection_3']) }
def get_shepard_diagram(): spearman_file = housekeeping.build_filepath({ 'person_data': request.args.get('personData'), 'difference_metric': request.args.get('differenceMetric'), 'non_metric': request.args.get('nonMetric'), 'section_list': housekeeping.get_selected_subsections(request.args), 'is_two_dimensional': False if request.args.get('twoD') == '3d' else True, 'data_type': 'spearman', 'emotion': int(request.args.get('focalEmotion')), 'embedding_type': request.args.get('embeddingType'), 'emotions': list( filter( lambda e: True if e != None else False, [e if request.args.get(e) == '1' else None for e in emotions])) }) if path.exists(spearman_file): with open(spearman_file, 'r') as file: spearmans = json.load(file) return json.dumps(spearmans) emotion_file = housekeeping.build_filepath({ 'person_data': request.args.get('personData'), 'difference_metric': request.args.get('differenceMetric'), 'non_metric': request.args.get('nonMetric'), 'section_list': housekeeping.get_selected_subsections(request.args), 'is_two_dimensional': False if request.args.get('twoD') == '3d' else True, 'data_type': 'embedding', 'emotion': int(request.args.get('focalEmotion')), 'embedding_type': request.args.get('embeddingType'), 'emotions': [ emotions[i] for i in range(len(emotions)) if request.args.get(emotions[i]) == '1' ] }) before_file = housekeeping.build_filepath({ 'person_data': request.args.get('personData'), 'difference_metric': request.args.get('differenceMetric'), 'non_metric': request.args.get('nonMetric'), 'section_list': housekeeping.get_selected_subsections(request.args), 'is_two_dimensional': False if request.args.get('twoD') == '3d' else True, 'data_type': 'diss_before', 'emotion': int(request.args.get('focalEmotion')), 'embedding_type': request.args.get('embeddingType'), 'emotions': [ emotions[i] for i in range(len(emotions)) if request.args.get(emotions[i]) == '1' ] }) with open(emotion_file, 'r') as file: embedded_data = [ (m['x'], m['y']) for l in json.load(file) # iterate if l != None # remove None values for m in l # flatten ] matrix_before = getData.get_embedding_data({ 'person_data': request.args.get('personData'), 'section_list': housekeeping.get_selected_subsections(request.args), 'difference_metric': request.args.get('differenceMetric'), 'embedding_type': request.args.get('embeddingType'), 'emotions': [ emotions[i] for i in range(len(emotions)) if request.args.get(emotions[i]) == '1' ], 'focal_emotion': int(request.args.get('focalEmotion')), 'frame_indices': [request.args.get(slidevalues[i]) for i in range(len(slidevalues))], 'non_metric': request.args.get('nonMetric'), 'perplexity': request.args.get('perplexity'), 'return_dissimilarity': True, 'is_two_dimensional': False if request.args.get('twoD') == '3d' else True }) matrix_after = [[distance.euclidean(d, e) for d in embedded_data] for e in embedded_data] spearmans = spearmanr([l for line in matrix_before for l in line], [l for line in matrix_after for l in line]) with open(spearman_file, 'w') as file: file.write(json.dumps(spearmans)) return json.dumps(spearmans)
def get_embedding_data(): emotionFile = housekeeping.build_filepath({ 'person_data': request.args.get('personData'), 'difference_metric': request.args.get('differenceMetric'), 'non_metric': request.args.get('nonMetric'), 'section_list': housekeeping.get_selected_subsections(request.args), 'is_two_dimensional': False if request.args.get('twoD') == '3d' else True, 'data_type': 'embedding', 'frame_indices': [request.args.get(slidevalues[i]) for i in range(len(slidevalues))], 'focal_emotion': int(request.args.get('focalEmotion')), 'emotion': int(request.args.get('focalEmotion')), 'embedding_type': request.args.get('embeddingType'), 'emotions': list( filter( lambda e: True if e != None else False, [e if request.args.get(e) == '1' else None for e in emotions])) }) if not path.exists(emotionFile): data = getData.get_embedding_data({ 'person_data': request.args.get('personData'), 'section_list': housekeeping.get_selected_subsections(request.args), 'difference_metric': request.args.get('differenceMetric'), 'embedding_type': request.args.get('embeddingType'), 'emotions': [e if request.args.get(e) == '1' else None for e in emotions], 'focal_emotion': int(request.args.get('focalEmotion')), 'frame_indices': [ request.args.get(slidevalues[i]) for i in range(len(slidevalues)) ], 'non_metric': request.args.get('nonMetric'), 'perplexity': request.args.get('perplexity'), 'return_dissimilarity': False, 'is_two_dimensional': False if request.args.get('twoD') == '3d' else True }) with open(emotionFile, 'w') as file: file.write(json.dumps(data)) else: with open(emotionFile, 'r') as file: data = json.load(file) return json.dumps(data)