def history_page(game_id="", version=None):
    show_old_version_notice = version is not None and utils.is_old_version(
        version)

    matches = datamodel.get_known_games(game_id)
    if not matches:
        logger.warning(f"Could not find a game matching {game_id}")
        return render_template("404_page.html",
                               game_not_found=True,
                               game_name=game_id)
    game_id = matches[0]
    games_dict = datamodel.get_available_games_dict()
    country = games_dict[game_id]["country_name"]

    event_filter = get_event_filter()

    with datamodel.get_db_session(game_id) as session:
        dict_builder = EventTemplateDictBuilder(session, game_id, event_filter)
        events, title, details, links = dict_builder.get_event_and_link_dicts()
        wars = dict_builder.get_war_list()
    return render_template(
        "history_page.html",
        game_name=game_id,
        country=country,
        wars=wars,
        events=events,
        details=details,
        links=links,
        title=title,
        is_filtered_page=not event_filter.is_empty_filter,
        show_old_version_notice=show_old_version_notice,
        version=utils.VERSION,
        update_version_id=version,
    )
def update_content(tab_value, search, date_fraction, dash_plot_checklist,
                   country_perspective):
    config.CONFIG.normalize_stacked_plots = ("normalize_stacked_plots"
                                             in dash_plot_checklist)
    game_id, matches = _get_game_ids_matching_url(search)
    if not matches:
        logger.warning(f"Could not find a game matching {game_id}")
        return render_template("404_page.html",
                               game_not_found=True,
                               game_name=game_id)
    game_id = matches[0]

    games_dict = datamodel.get_available_games_dict()
    if game_id not in games_dict:
        logger.warning(f"Game ID {game_id} does not match any known game!")
        return []

    logger.info(
        f"dash_server.update_content: Tab is {tab_value}, Game is {game_id}")
    with datamodel.get_db_session(game_id) as session:
        current_date = utils.get_most_recent_date(session)

    children = []
    if tab_value in visualization_data.THEMATICALLY_GROUPED_PLOTS:
        plots = visualization_data.THEMATICALLY_GROUPED_PLOTS[tab_value]
        plot_data = visualization_data.get_current_execution_plot_data(
            game_id, country_perspective)
        for plot_spec in plots:
            figure_data = get_figure_data(plot_data, plot_spec)
            if not figure_data:
                continue
            figure_layout = get_figure_layout(plot_spec)
            figure_layout["title"] = plot_spec.title
            figure = go.Figure(data=figure_data, layout=figure_layout)

            children.append(
                html.Div(
                    [
                        dcc.Graph(
                            id=plot_spec.plot_id,
                            figure=figure,
                            style=dict(textAlign="center"),
                        )
                    ],
                    style=dict(
                        margin="auto",
                        width=f"{config.CONFIG.plot_width}px",
                        height=f"{config.CONFIG.plot_height}px",
                    ),
                ))
    else:
        slider_date = 0.01 * date_fraction * current_date
        children.append(get_galaxy(game_id, slider_date))
        children.append(
            html.P(
                f"Galaxy Map at {datamodel.days_to_date(slider_date)}",
                style=TEXT_STYLE,
            ))
    return children
def update_game_header(search):
    game_id, matches = _get_game_ids_matching_url(search)
    if not matches:
        logger.warning(f"Could not find a game matching {game_id}")
        return "Unknown Game"
    game_id = matches[0]
    games_dict = datamodel.get_available_games_dict()
    country = games_dict[game_id]["country_name"]
    return f"{country} ({game_id})"
Example #4
0
def index_page(version=None):
    """ Show a list of known games with database files.

    :param version: Used to check for updates.
    :return:
    """
    show_old_version_notice = False
    if config.CONFIG.check_version and version is not None:
        show_old_version_notice = utils.is_old_version(version)
    games = datamodel.get_available_games_dict().values()
    return render_template(
        "game_index.html",
        games=games,
        show_old_version_notice=show_old_version_notice,
        version=utils.VERSION_ID,
        update_version_id=version,
    )
def update_country_select_options(search):
    game_id, _ = _get_game_ids_matching_url(search)
    games_dict = datamodel.get_available_games_dict()

    if game_id not in games_dict:
        logger.warning(f"Game ID {game_id} does not match any known game!")
        return []

    options = [{"label": "None", "value": None}]
    with datamodel.get_db_session(game_id) as session:
        for c in session.query(datamodel.Country):
            if (
                c.is_real_country()
                and (c.has_met_player() or config.CONFIG.show_everything)
                and not c.is_other_player
            ):
                options.append({"label": c.country_name, "value": c.country_id_in_game})
    return options
def update_content(
    tab_value, search, date_fraction, dash_plot_checklist, country_perspective
):
    config.CONFIG.normalize_stacked_plots = (
        "normalize_stacked_plots" in dash_plot_checklist
    )
    game_id, matches = _get_game_ids_matching_url(search)
    if not matches:
        logger.warning(f"Could not find a game matching {game_id}")
        return render_template("404_page.html", game_not_found=True, game_name=game_id)
    game_id = matches[0]

    games_dict = datamodel.get_available_games_dict()
    if game_id not in games_dict:
        logger.warning(
            f"Game ID {game_id} does not match any known game! (URL parameter {search})"
        )
        return []

    logger.info(f"dash_server.update_content: Tab is {tab_value}, Game is {game_id}")
    with datamodel.get_db_session(game_id) as session:
        current_date = utils.get_most_recent_date(session)

    children = []
    if tab_value in config.CONFIG.tab_layout:
        plots = visualization_data.get_plot_specifications_for_tab_layout().get(
            tab_value
        )
        plot_data = visualization_data.get_current_execution_plot_data(
            game_id, country_perspective
        )
        for plot_spec in plots:
            if not plot_spec:
                continue  # just in case it's possible to sneak in an invalid ID
            start = time.time()
            figure_data = get_raw_plot_data_dicts(plot_data, plot_spec)
            end = time.time()
            logger.debug(
                f"Prepared figure {plot_spec.title} in {end - start:5.3f} seconds."
            )
            if not figure_data:
                continue
            figure_layout = get_figure_layout(plot_spec)
            figure_layout["title"] = plot_spec.title
            figure = go.Figure(data=figure_data, layout=figure_layout)

            children.append(
                html.Div(
                    [
                        dcc.Graph(
                            id=plot_spec.plot_id,
                            figure=figure,
                            style=dict(textAlign="center"),
                        )
                    ],
                    style=dict(margin="auto", width=f"{config.CONFIG.plot_width}px",),
                )
            )
    else:
        slider_date = 0.01 * date_fraction * current_date

        children.append(
            html.Div(
                [get_galaxy(game_id, slider_date), SELECT_SYSTEM_DEFAULT],
                style=dict(
                    margin="auto",
                    width=f"{config.CONFIG.plot_width}px",
                    # height=f"{config.CONFIG.plot_height}px",
                    backgroundColor=BACKGROUND_DARK,
                ),
            )
        )
    return children