Query appropriate tables and return data to dashboard in the required format.
    :param current_index: int, current index during update
    :param variable_names: str, variable name to fetch values from
    :param selected_run: str, run containing the variable
    :return: dict, {<variable_name>: [<values>]}

def get_variable_update_dicts(current_index, variable_names, selected_run):
    """
    Query appropriate tables and return data to dashboard in the required format.
    :param current_index: int, current index during update
    :param variable_names: str, variable name to fetch values from
    :param selected_run: str, run containing the variable
    :return: dict, {<variable_name>: [<values>]}
    """
    conn, c = open_data_base_connection()
    data = {}
    for _, v_n in variable_names:
        data[v_n] = {'x': [], 'y': [], 'z': [], 'vn': []}

    try:
        # values for each variable
        for _, v_n in variable_names:
            plot_type = v_n.split("_")[0]
            if plot_type == "scalar":
                try:
                    c.execute("""SELECT X_value FROM {} WHERE rowid > {}""".format(selected_run + "_" + v_n,
                                                                                   current_index[v_n]))
                    x_values = np.array(c.fetchall()).squeeze().tolist()
                    c.execute("""SELECT Y_value FROM {} WHERE rowid > {}""".format(selected_run + "_" + v_n,
                                                                                   current_index[v_n]))
                    y_values = np.array(c.fetchall()).squeeze().tolist()
                    data[v_n]["x"] = x_values
                    data[v_n]["y"] = y_values
                    n_values = len(x_values)
                    current_index["{}".format(v_n)] += n_values
                    logging.info("New value found and updated")
                except IndexError:
                    logging.info("No new data point found")
            elif plot_type == "heatmap":
                try:
                    c.execute("""SELECT X_value FROM {} WHERE rowid > {}""".format(selected_run + "_" + v_n,
                                                                                   current_index[v_n]))
                    x_values = np.array(c.fetchall()).squeeze().tolist()
                    c.execute("""SELECT Y_value FROM {} WHERE rowid > {}""".format(selected_run + "_" + v_n,
                                                                                   current_index[v_n]))
                    y_values = np.array(c.fetchall()).squeeze().tolist()
                    c.execute("""SELECT V_names FROM {} WHERE rowid > {}""".format(selected_run + "_" + v_n,
                                                                                   current_index[v_n]))
                    v_values = np.array(c.fetchall()).squeeze().tolist()
                    data[v_n]["x"] = x_values
                    data[v_n]["z"] = y_values
                    data[v_n]["vn"] = v_values
                    n_values = len(x_values)
                    current_index["{}".format(v_n)] += n_values
                    logging.info("New value found and updated")
                except sqlite3.OperationalError:
                    c.execute("""SELECT X_value FROM {} WHERE rowid > {}""".format(selected_run + "_" + v_n,
                                                                                   current_index[v_n]))
                    x_values = np.array(c.fetchall()).squeeze().tolist()
                    c.execute("""SELECT Y_value FROM {} WHERE rowid > {}""".format(selected_run + "_" + v_n,
                                                                                   current_index[v_n]))
                    y_values = np.array(c.fetchall()).squeeze().tolist()
                    data[v_n]["x"] = x_values
                    data[v_n]["z"] = y_values
                    n_values = len(x_values)
                    current_index["{}".format(v_n)] += n_values
                    logging.info("New value found and updated")
                except IndexError:
                    logging.info("No new data point found")
    except KeyError:
        logging.error("I think the run variable has changes. So, I'm passing no data.")

    conn.close()
    return data