Skip to content

Commit

Permalink
Final changes for v0.3-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasdoehne committed Dec 22, 2018
1 parent 614f450 commit a6c462f
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 215 deletions.
6 changes: 3 additions & 3 deletions stellarisdashboard/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,17 @@ def apply_dict(self, settings_dict):
logger.info("Updating settings")
for key, val in settings_dict.items():
if key not in Config.ALL_KEYS:
logger.info(f'Ignoring unknown option {key} with value {val}.')
logger.info(f'Ignoring unknown setting {key} with value {val}.')
continue
old_val = self.__dict__.get(key)
if key in Config.BOOL_KEYS:
val = self._preprocess_bool(val)
if key in Config.PATH_KEYS:
logger.info(f'Ignoring path option {key}. Change paths by editing default_paths.py instead!')
logger.info(f'Ignoring path setting {key}. Please change paths by editing default_paths.py instead.')
continue
self.__setattr__(key, val)
if val != old_val:
logger.info(f'Updated {key.ljust(25)} {repr(old_val).rjust(8)} -> {repr(val).ljust(8)}')
logger.info(f'Updated setting {key.ljust(28)} {repr(old_val).rjust(8)} -> {repr(val).ljust(8)}')

def write_to_file(self):
fname = _get_settings_file_path()
Expand Down
20 changes: 11 additions & 9 deletions stellarisdashboard/dash_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
timeline_app.css.config.serve_locally = True
timeline_app.scripts.config.serve_locally = True

VERSION_ID = "v0.3"
VERSION_ID = "v0.3-beta"


@flask_app.route("/")
Expand All @@ -40,7 +40,7 @@ def index_page(version=None):
show_old_version_notice = False
if config.CONFIG.check_version and version is not None:
show_old_version_notice = _is_old_version(version)
games = [dict(country=country, game_name=g) for g, country in models.get_available_games_dict().items()]
games = models.get_available_games_dict().values()
return render_template(
"index.html",
games=games,
Expand All @@ -64,13 +64,13 @@ def history_page(
if game_id is None:
game_id = ""

games_dict = models.get_available_games_dict()
matches = models.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]
country = games_dict[game_id]
games_dict = models.get_available_games_dict()
country = games_dict[game_id]["country_name"]

event_filter = get_event_filter()

Expand Down Expand Up @@ -419,7 +419,8 @@ def update_game_header(search):
return "Unknown Game"
game_id = matches[0]
games_dict = models.get_available_games_dict()
return f"{games_dict[game_id]} ({game_id})"
country = games_dict[game_id]['country_name']
return f"{country} ({game_id})"


@timeline_app.callback(Output('tab-content', 'children'),
Expand All @@ -435,9 +436,9 @@ def update_content(tab_value, search, date_fraction, dash_plot_checklist):
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 = models.get_available_games_dict()
game_id = matches[0]
if game_id not in games_dict:
logger.warning(f"Game ID {game_id} does not match any known game!")
return []
Expand Down Expand Up @@ -488,7 +489,7 @@ def get_figure_data(plot_data: visualization_data.EmpireProgressionPlotData, plo
start = time.time()
plot_list = get_raw_plot_data_dicts(plot_data, plot_spec)
end = time.time()
logger.debug(f"Update took {end - start} seconds!")
logger.debug(f"Prepared data for figure {plot_spec.title} in {end - start} seconds.")
return plot_list


Expand Down Expand Up @@ -522,7 +523,7 @@ def _get_raw_data_for_line_plot(plot_data: visualization_data.EmpireProgressionP
line = dict(
x=x_values,
y=y_values,
name=key,
name=dict_key_to_legend_label(key),
line={"color": get_country_color(key, 1.0)},
text=get_plot_value_labels(x_values, y_values, key),
hoverinfo='text',
Expand Down Expand Up @@ -587,7 +588,8 @@ def dict_key_to_legend_label(key: str):


def get_plot_value_labels(x_values, y_values, key):
return [f'{models.days_to_date(360 * x)}: {y:.2f} - {dict_key_to_legend_label(key)}' if (y and y == y) else "" for (x, y) in zip(x_values, y_values)]
return [f'{models.days_to_date(360 * x)}: {y:.2f} - {dict_key_to_legend_label(key)}' if (y and y == y) else ""
for (x, y) in zip(x_values, y_values)]


def get_galaxy(game_id: str, date: float) -> dcc.Graph:
Expand Down
4 changes: 4 additions & 0 deletions stellarisdashboard/default_paths.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# *_save_path refers to the location of the Stellaris save files. It is given relative to the user's home directory.
# *_output_path referse to the location where database files and other output should be stored. It should be given relative to the install location.


linux_save_path = ".local/share/Paradox Interactive/Stellaris/save games/"
linux_output_path = "output/"

Expand Down
44 changes: 38 additions & 6 deletions stellarisdashboard/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import contextlib
import datetime
import enum
import logging
import pathlib
Expand Down Expand Up @@ -140,7 +141,7 @@ class HistoricalEventType(enum.Enum):
leader_died = enum.auto() # TODO
level_up = enum.auto()

# civilizational advancement:
# empire progress:
researched_technology = enum.auto()
tradition = enum.auto()
ascension_perk = enum.auto()
Expand Down Expand Up @@ -282,15 +283,21 @@ def get_known_games(game_name_prefix: str = "") -> List[str]:
return [fname.stem for fname in files]


def get_available_games_dict() -> Dict[str, str]:
def get_available_games_dict() -> Dict[str, Dict[str, str]]:
""" Returns a dictionary mapping game id to the name of the game's player country. """
games = {}
for game_name in get_known_games():
with get_db_session(game_name) as session:
for game_id in get_known_games():
with get_db_session(game_id) as session:
game = session.query(Game).one_or_none()
if game is None:
continue
games[game_name] = game.player_country_name
games[game_id] = dict(
game_id=game_id,
country_name=game.player_country_name,
difficulty=game.difficulty,
galaxy=game.galaxy,
last_updated=game.last_updated,
)
return games


Expand All @@ -313,13 +320,39 @@ class Game(Base):
game_name = Column(String(50))
player_country_name = Column(String(100))

db_galaxy_template = Column(String(100))
db_galaxy_shape = Column(String(100))
db_difficulty = Column(String(100))

db_last_updated = Column(sqlalchemy.DateTime, default=None)

systems = relationship("System", back_populates="game", cascade="all,delete,delete-orphan")
countries = relationship("Country", back_populates="game", cascade="all,delete,delete-orphan")
species = relationship("Species", back_populates="game", cascade="all,delete,delete-orphan")
game_states = relationship("GameState", back_populates="game", cascade="all,delete,delete-orphan")
wars = relationship("War", back_populates="game", cascade="all,delete,delete-orphan")
leaders = relationship("Leader", back_populates="game", cascade="all,delete,delete-orphan")

@property
def galaxy(self):
return f"{self.galaxy_template} {self.galaxy_shape}"

@property
def galaxy_template(self):
return game_info.convert_id_to_name(self.db_galaxy_template)

@property
def galaxy_shape(self):
return game_info.convert_id_to_name(self.db_galaxy_shape)

@property
def difficulty(self):
return game_info.convert_id_to_name(self.db_difficulty)

@property
def last_updated(self):
return f"{self.db_last_updated:%Y.%m.%d %H:%M}"


class SharedDescription(Base):
""" Represents short descriptions like technology names that are likely to occur many times for various empires. """
Expand Down Expand Up @@ -1049,4 +1082,3 @@ def description(self) -> str:
return game_info.convert_id_to_name(self.db_description.text)
else:
return "Unknown Event"

4 changes: 2 additions & 2 deletions stellarisdashboard/templates/history_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ <h2 class="eventlist_header">{{title[object] | safe}}</h2>
<span class="dateblock">{{event["start_date"]}}:</span>
<span class="eventtext">
{% if "leader" in event %} Under ruler {{links[event["leader"]]|safe}}, the {% endif %}{{ links[event["country"]] | safe }}
negotiated peace in the "{{links[event["war"]] | safe}}" conflict.
made peace in the "{{links[event["war"]] | safe}}" conflict.
</span>
</div>
</li>
Expand Down Expand Up @@ -440,7 +440,7 @@ <h2 class="eventlist_header">{{title[object] | safe}}</h2>
<div class="eventdescription">
<span class="dateblock">{{event["start_date"]}}:</span>
<span class="eventtext">
{{ event["leader"].leader_class.capitalize() }} {{links[event["leader"]]|safe}} has died or was fired.
{{ event["leader"].leader_class.capitalize() }} {{links[event["leader"]]|safe}} died or was fired.
</span>
</div>
</li>
Expand Down
9 changes: 6 additions & 3 deletions stellarisdashboard/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
<ul class=entries>
<h1>Available Games</h1>
{% for game in games %}
<li class="game"><h3>{{ game["country"] }} ({{ game["game_name"] }})</h3>
<a class="button" href={{url_for("/timeline/", game_name=game["game_name"])}}>Timeline Graphs</a>
<a class="button" href={{url_for("history_page", game_id=game["game_name"])}}>Event Ledger</a>
<li class="game"><h3>{{ game["country_name"] }} ({{ game["game_id"] }})</h3>
<p>
Galaxy: {{game["galaxy"]}}; Difficulty: {{game["difficulty"]}}; Last Updated: {{game["last_updated"]}}
</p>
<a class="button" href={{url_for("/timeline/", game_name=game["game_id"])}}>Timeline Graphs</a>
<a class="button" href={{url_for("history_page", game_id=game["game_id"])}}>Event Ledger</a>
</li>
{% endfor %}
</ul>
Expand Down
Loading

0 comments on commit a6c462f

Please sign in to comment.