def visualization_data(interactions_filter): print("args:", request.args) print('form:', request.form) print('values:', request.values) print('data:', request.data) print('json:', request.json) fileindicator = request.json['fileindicator'] print('fileindicator:', fileindicator) cached_filename = get_cached_filename(fileindicator) cached_file_path = os.path.join(cache_dir, cached_filename) if os.path.isfile(cached_file_path): with open(cached_file_path) as source: network = source.read() os.utime(cached_file_path, None) #touches file to update timestamp to make it easy to delete oldest file else: file_list = file_list_constructor(fileindicator) df = create_df.main(file_list) nodes, links = ST_D3Vis.find_who_is_talking(df, interactions_filter = int(interactions_filter)) data = {'links':links, 'nodes':nodes} network = json.dumps(data) cached_file_list = sorted(os.listdir(cache_dir), key=get_last_use_time) if len(cached_file_list) > CACHE_LIMIT: oldest_file = os.path.join(cache_dir, cached_file_list[0]) os.remove(oldest_file) with open(cached_file_path, 'w') as output: output.write(network) return network
for (source, target), value in Counter(interactions_by_id).most_common(): edge_list.append({"source": source, "target": target, "value": value}) return node_list, edge_list def write_json(nodes, links, filename): data = {"links": links, "nodes": nodes} with open(filename, "w") as outfile: json.dump(data, outfile) def make_filename(file_name_list): """Use the last part of the URL to make a json filename.""" return "ST_relationships.json" # file_name = '-'.join(file_name_list) # return os.path.join(JSON_DIR, filename) file_list = sys.argv[1:] df = create_df.main(file_list) # Make filename that looks like 565-567-movie1, etc. # filename = make_filename(file_name_list) filename = "ST_relationships.json" nodes, edges = find_who_is_talking(df) write_json(nodes, edges, filename)