Skip to content

Commit

Permalink
Stealables!
Browse files Browse the repository at this point in the history
  • Loading branch information
sbeaumont committed Nov 6, 2023
1 parent 4ad88f1 commit 07afc16
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
7 changes: 7 additions & 0 deletions facade/odinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ def realmies(self) -> list[Dominion]:
realm = realm_of_dom(self._db, current_player_id)
return doms_of_realm(self._db, realm)

def stealables(self) -> list:
logger.debug("Listing stealables")
since = add_duration(current_od_time(as_str=True), -12, True)
result = query_stealables(self._db, since)
print(result)
return result

# ---------------------------------------- QUERIES - Utility

def name_for_dom_code(self, domcode):
Expand Down
7 changes: 7 additions & 0 deletions flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ def realmies():
realmies=facade().realmies())


@app.route('/stealables')
def stealables():
return render_template('stealables.html',
feature_toggles=feature_toggles,
stealables = facade().stealables())


@app.teardown_appcontext
def teardown_app(exception):
facade = getattr(g, '_facade', None)
Expand Down
31 changes: 29 additions & 2 deletions opsdata/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,35 @@ def update_clearsight(ops, db, dom_code):
update_dom_history(ops, db, dom_code, timestamp)


qry_stealables = """
select
max(c.timestamp),
c.dominion,
c.resource_platinum as platinum,
c.resource_food as food,
c.resource_gems as gems,
c.resource_mana as mana
from
ClearSight c
where
c.timestamp > :timestamp
group by
c.dominion
order by
c.resource_platinum desc,
c.resource_food desc,
c.resource_mana desc,
c.resource_gems desc
"""


def query_stealables(db, timestamp):
params = {
'timestamp': cleanup_timestamp(timestamp)
}
return db.query(qry_stealables, params)


# ------------------------------------------------------------ CastleSpy

CASTLE_SPY_MAPPING = {
Expand Down Expand Up @@ -450,5 +479,3 @@ def update_revelation(ops, db, dom_code):

def query_town_crier(db):
return db.query('SELECT * FROM TownCrier ORDER BY timestamp DESC')


46 changes: 46 additions & 0 deletions templates/stealables.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% extends "odinfo-base.html" %}
{% block extrascripts %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.5/css/jquery.dataTables.css" />
<script src="https://cdn.datatables.net/1.13.5/js/jquery.dataTables.js"></script>
{% endblock %}

{% block content %}
<div class="w3-container">
<h5>Stealables</h5>
<table id="stealables_table" class="w3-table w3-striped w3-bordered w3-border w3-hoverable w3-white">
<thead>
<tr class="w3-black">
<th>Dominion</th>
<th>Platinum</th>
<th>Food</th>
<th>Mana</th>
<th>Gems</th>
</tr>
</thead>
{% for row in stealables %}
<tr>
<td>
<a href="{{ url_for('dominfo', domcode=row.dominion) }}">{{ row.dominion }}</a>
</td>
<td>{{ row.platinum }}</td>
<td>{{ row.food }}</td>
<td>{{ row.mana }}</td>
<td>{{ row.gems }}</td>
</tr>
{% endfor %}
</table><br>
</div>

<script>
$(document).ready( function () {
$('#stealables_table').DataTable({
'paging': false,
'order': [[1, 'desc']],
'columnDefs': [
{ "type": "num", "targets": [1, 2, 3, 4]}
]
});
} );
</script>
{% endblock %}

0 comments on commit 07afc16

Please sign in to comment.