diff --git a/facade/odinfo.py b/facade/odinfo.py index 10ff23c..1fb8ce7 100644 --- a/facade/odinfo.py +++ b/facade/odinfo.py @@ -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): diff --git a/flask_app.py b/flask_app.py index adb9548..cc3a61e 100644 --- a/flask_app.py +++ b/flask_app.py @@ -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) diff --git a/opsdata/schema.py b/opsdata/schema.py index 9116eab..64b2d4f 100644 --- a/opsdata/schema.py +++ b/opsdata/schema.py @@ -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 = { @@ -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') - - diff --git a/templates/stealables.html b/templates/stealables.html new file mode 100644 index 0000000..39ec53b --- /dev/null +++ b/templates/stealables.html @@ -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 %} \ No newline at end of file