def flowchart():
    elem = []
    if (request.method == 'POST'):
        if os.path.exists("raw_data.json"):
            os.remove("raw_data.json")
        # The name of the request method should go in as an arg here
        # get_the_graph.forming('android.app.Application.onCreate')
        content1 = request.get_json()
        method_selected = content1.split('!')[0]
        nameApp = content1.split('!')[1]

        # Get the thread of the method
        thread = database.get_thread(method_selected)

        # Get all the data of this thread with 'Function: 1' for method_selected
        data = database.get_particular_selected(method_selected, thread)

        print("INTERESTING")
        print(data)

        # Calculate the positions for these data
        precomputed_pos, rect_data, maximum_height, maximum_width = precalc.precalc(
            data)

        print("method_selected")
        print(method_selected)

        line_it = None
        for j in range(0, len(rect_data)):
            if (rect_data[j]['Method'].split('(')[0] == method_selected):
                line_it = j
                break

        print("before")
        print("line_it")
        print(line_it)

        # line_it = rect_data[line_it]['Line_no']

        # print("after")
        # print("line_it")
        # print(line_it)

        # line_it = None
        # for j in range(0, len(d)):
        # 	for i in range(0, len(rect_data)):
        # 		if(rect_data[i]['Method'].split('(')[0] == method_selected):
        # 			line_it = i
        # 			break

        autoscroll_position_index = -1

        if (line_it != None):
            autoscroll_position_index = line_it

        for i in range(0, len(precomputed_pos)):
            precomputed_pos[i].pop(0)

        to_send1 = []
        to_send1.append(precomputed_pos)
        to_send1.append(rect_data)
        to_send1.append(maximum_height)
        to_send1.append(maximum_width)
        to_send1.append(autoscroll_position_index)

        method_found = ""
        clean_code = []
        character = []
        line_no = []
        clean_code.append("Line_nos")
        to_send2 = clean_code + line_no

        character.insert(0, "Character_nos")
        to_send2 = to_send2 + character

        to_send2.append(method_found)

        to_send = []
        to_send.append(to_send1)
        to_send.append(to_send2)

        get_the_graph.forming(method_selected)
        selectedThread = get_the_graph.getThread(method_selected)
        # getTheGraph.forming(method_selected)
        nodes, edges = input_json.getvalues('raw_data.json')
        elem.append(nodes)
        elem.append([0])
        elem.append(edges)
        elem.append([100])
        elem.append(selectedThread)

        elem.append("separator")
        elem.append(to_send)
        return json.dumps(elem)
def select_in_stack():
    if (request.method == 'POST'):
        content1 = json.loads(request.data)
        content = content1.split('!')[0]
        nameApp = content1.split('!')[1]
        print("SelectInStackNameApp: ", nameApp)
        nodes, edges = input_json.getvalues('raw_data.json')

        # Get the thread of the method
        thread = database.get_thread(content)

        # Get all the data of this thread with 'Function: 1' for method_selected
        data = database.get_particular_selected(content, thread)

        print(data)

        # data = database.get_particular_selected(content)

        d = database.getline(content)

        precomputed_pos, rect_data, maximum_height, maximum_width = precalc.precalc(
            data)

        # line_it = None
        # for j in range(0, len(d)):
        # 	for i in range(0, len(rect_data)):
        # 		if(rect_data[i]['Method'].split('(')[0] == content):
        # 			line_it = i
        # 			break

        line_it = None
        for j in range(0, len(rect_data)):
            if (rect_data[j]['Method'].split('(')[0] == content):
                line_it = j
                break

        autoscroll_position_index = -1

        if (line_it != None):
            autoscroll_position_index = line_it

        for i in range(0, len(precomputed_pos)):
            precomputed_pos[i].pop(0)

        to_send1 = []
        to_send1.append(precomputed_pos)
        to_send1.append(rect_data)
        to_send1.append(maximum_height)
        to_send1.append(maximum_width)
        to_send1.append(autoscroll_position_index)

        if (content == ""):
            method = "com.helpshift.util.HelpshiftContext.b()"
        method_name = content

        method_name = content.split(',')[0]

        log_bbid = d[0]['BB_ID']

        filename_path, method_found, args = file_path.find_file(
            method_name, nameApp)

        l, c = file_path.find_line_no(filename_path, method_name, args,
                                      method_found, log_bbid)
        # bbblock_line_no = file_path.findbbblock(filename_path, line_no)

        line_no = []
        character = []
        line_no.append(l)
        character.append(c)

        # Figure out the relation between BB_ID and hexcode and then send only that line number underneath so that only that gets highlighted
        code = file_path.source_code(filename_path)

        clean_code = []
        for i in range(0, len(code)):
            temp = code[i].split("\n")
            clean_code.append(temp[0])

        clean_code.append("Line_nos")
        to_send2 = clean_code + line_no

        character.insert(0, "Character_nos")
        to_send2 = to_send2 + character

        to_send2.append(method_found)

        to_send = []
        to_send.append(to_send1)
        to_send.append(to_send2)

        return jsonify(to_send)