From 0dea8f430e4905da98d7009bdf111e0965fedd22 Mon Sep 17 00:00:00 2001 From: raylu Date: Tue, 22 Oct 2013 19:29:47 -0700 Subject: alliance and character pages --- db/queries.py | 14 ++++---- importer.py | 11 +++--- server.py | 8 ++--- web/api.py | 8 ++--- web/static/css/corporation.ccss | 24 ------------- web/static/css/kill_list.ccss | 27 +++++++++++++++ web/static/js/corporation.js | 70 -------------------------------------- web/static/js/kill_list.js | 74 +++++++++++++++++++++++++++++++++++++++++ web/templates/corporation.html | 25 -------------- web/templates/kill_list.html | 25 ++++++++++++++ 10 files changed, 147 insertions(+), 139 deletions(-) delete mode 100644 web/static/css/corporation.ccss create mode 100644 web/static/css/kill_list.ccss delete mode 100644 web/static/js/corporation.js create mode 100644 web/static/js/kill_list.js delete mode 100644 web/templates/corporation.html create mode 100644 web/templates/kill_list.html diff --git a/db/queries.py b/db/queries.py index a770667..1e10629 100644 --- a/db/queries.py +++ b/db/queries.py @@ -19,7 +19,7 @@ def search(q): ''', like_str) return {'alliances': alliances, 'corporations': corps, 'characters': chars} -def corporation(corp_id): +def kill_list(entity_type, entity_id): with db.cursor() as c: kills = db.query(c, ''' SELECT DISTINCT(kills.kill_id), kill_time, cost, @@ -29,8 +29,8 @@ def corporation(corp_id): JOIN kill_costs ON kill_costs.kill_id = kills.kill_id JOIN eve.mapSolarSystems ON solar_system_id = solarSystemID JOIN eve.mapRegions ON mapSolarSystems.regionID = mapRegions.regionID - WHERE corporation_id = ? LIMIT 100 - ''', corp_id) + WHERE {}_id = ? LIMIT 100 + '''.format(entity_type), entity_id) kill_ids = list(map(operator.itemgetter('kill_id'), kills)) char_rows = db.query(c, ''' SELECT @@ -42,7 +42,7 @@ def corporation(corp_id): WHERE kill_id IN ({}) '''.format(','.join(map(str, kill_ids)))) characters = defaultdict(dict) - corp_name = None + entity_name = None for kill_id in kill_ids: characters[kill_id]['attackers'] = 1 # count final_blow now for char in char_rows: @@ -53,15 +53,15 @@ def corporation(corp_id): characters[kill_id]['final_blow'] = char else: characters[kill_id]['attackers'] += 1 - if corp_name is None and char['corporation_id'] == corp_id: - corp_name = char['corporation_name'] + if entity_name is None and char[entity_type + '_id'] == entity_id: + entity_name = char[entity_type + '_name'] for kill in kills: kill['kill_time'] = _format_kill_time(kill['kill_time']) chars = characters[kill['kill_id']] kill['victim'] = chars['victim'] kill['final_blow'] = chars['final_blow'] kill['attackers'] = chars['attackers'] - return {'corporation_name': corp_name, 'kills': kills} + return {'entity_name': entity_name, 'kills': kills} def kill(kill_id): with db.cursor() as c: diff --git a/importer.py b/importer.py index 2ce4877..d735c22 100755 --- a/importer.py +++ b/importer.py @@ -18,9 +18,6 @@ def insert_kill(c, kill): print('duplicate:', kill['killID']) return raise - except TypeError: - print(kill) - raise victim = kill['victim'] parambatch = [( @@ -93,8 +90,12 @@ def main(): print(repr(e)) break print('inserting', len(kills), 'kills') - for kill in kills: - insert_kill(c, kill) + try: + for kill in kills: + insert_kill(c, kill) + except TypeError as e: + print(repr(e), kills) + break db.conn.commit() last_kill_id = kills[-1]['killID'] last_request_time = now diff --git a/server.py b/server.py index c68aaaf..d7f8fae 100755 --- a/server.py +++ b/server.py @@ -27,9 +27,9 @@ class SearchHandler(BaseHandler): def get(self): self.render('search.html') -class CorporationHandler(BaseHandler): - def get(self): - self.render('corporation.html') +class KillListHandler(BaseHandler): + def get(self, entity_type): + self.render('kill_list.html') class KillHandler(BaseHandler): def get(self): @@ -47,7 +47,7 @@ if __name__ == '__main__': handlers=[ (r'/', MainHandler), (r'/search', SearchHandler), - (r'/corporation/.+', CorporationHandler), + (r'/(alliance|corporation|character)/.+', KillListHandler), (r'/kill/.+', KillHandler), (r'/(css/.+)\.css', CSSHandler), ], diff --git a/web/api.py b/web/api.py index 523880b..5f21441 100644 --- a/web/api.py +++ b/web/api.py @@ -29,9 +29,9 @@ class SearchHandler(APIHandler): data = db.queries.search(q) self.respond_json(data) -class CorporationHandler(APIHandler): - def get(self, corp_id): - kills = db.queries.corporation(int(corp_id)) +class KillListHandler(APIHandler): + def get(self, entity_type, entity_id): + kills = db.queries.kill_list(entity_type, int(entity_id)) self.respond_json(kills) class KillHandler(APIHandler): @@ -43,7 +43,7 @@ def start(): tornado.web.Application( handlers=[ (r'/search', SearchHandler), - (r'/corporation/(.+)', CorporationHandler), + (r'/(alliance|corporation|character)/(.+)', KillListHandler), (r'/kill/(.+)', KillHandler), ], debug=config.debug, diff --git a/web/static/css/corporation.ccss b/web/static/css/corporation.ccss deleted file mode 100644 index 575a040..0000000 --- a/web/static/css/corporation.ccss +++ /dev/null @@ -1,24 +0,0 @@ -table#kills: - table-layout: fixed - width: 900px - - tr:nth-child(odd): - background-color: #1a1a1a - - th.time: - width: 90px - th.system: - width: 120px - th.victim_portrait: - width: 64px - th.victim: - width: 250px - th.killer_portrait: - width: 64px - th.killer: - width: 250px - th.value: - width: 62px - - td:nth-child(7): - text-align: right diff --git a/web/static/css/kill_list.ccss b/web/static/css/kill_list.ccss new file mode 100644 index 0000000..3985a58 --- /dev/null +++ b/web/static/css/kill_list.ccss @@ -0,0 +1,27 @@ +table#kills: + table-layout: fixed + width: 900px + + tr:nth-child(odd): + background-color: #1a1a1a + + th.time: + width: 90px + th.system: + width: 120px + th.victim_portrait: + width: 64px + th.victim: + width: 250px + th.killer_portrait: + width: 64px + th.killer: + width: 250px + th.value: + width: 62px + + td:nth-child(7): + text-align: right + + .loss: + color: #a44 diff --git a/web/static/js/corporation.js b/web/static/js/corporation.js deleted file mode 100644 index 606ce3e..0000000 --- a/web/static/js/corporation.js +++ /dev/null @@ -1,70 +0,0 @@ -window.addEvent('domready', function() { - var corp_id = document.location.pathname.split('/').getLast(); - ykill.api('/corporation/' + corp_id, function(data) { - if (data['corporation_name']) - document.title += ' - ' + data['corporation_name']; - - var table = $('kills').getChildren('tbody')[0]; - data['kills'].each(function(kill) { - var tr = new Element('tr'); - - var kill_time = kill['kill_time'].split(' ', 2); - var a = new Element('a', {'href': '/kill/' + kill['kill_id']}); - a.appendText(kill_time[0]); - a.grab(new Element('br')); - a.appendText(kill_time[1]); - var td = new Element('td').grab(a); - tr.grab(td); - - td = new Element('td'); - td.appendText(kill['system_name'] + ' '); - td.grab(new Element('span', {'html': kill['security'].toFixed(1)})); - td.grab(new Element('br')); - td.appendText(kill['region']); - tr.grab(td); - - td = new Element('td'); - var victim = kill['victim']; - td.adopt( - ykill.portrait(victim['ship_type_id'], victim['ship_name'], 'type', '_32.png'), - ykill.portrait(victim['character_id'], victim['character_name'], 'character', '_32.jpg') - ); - tr.grab(td); - - td = new Element('td'); - td.appendText(victim['character_name']); - td.grab(new Element('br')); - td.appendText(victim['corporation_name']); - if (victim['alliance_id']) - td.appendText(' / ' + victim['alliance_name']); - if (victim['faction_id']) - td.appendText(' / ' + victim['faction_name']); - tr.grab(td); - - td = new Element('td'); - var final_blow = kill['final_blow']; - td.adopt( - ykill.portrait(final_blow['ship_type_id'], final_blow['ship_name'], 'type', '_32.png'), - ykill.portrait(final_blow['character_id'], final_blow['character_name'], 'character', '_32.jpg') - ); - tr.grab(td); - - td = new Element('td'); - td.appendText(final_blow['character_name'] + ' (' + kill['attackers'] + ')'); - td.grab(new Element('br')); - td.appendText(final_blow['corporation_name']); - if (final_blow['alliance_id']) - td.appendText(' / ' + final_blow['alliance_name']); - if (final_blow['faction_id']) - td.appendText(' / ' + final_blow['faction_name']); - tr.grab(td); - - td = new Element('td'); - var millions = kill['cost'] / (100 * 1000000); - td.appendText(ykill.format_isk(millions)); - tr.grab(td); - - table.grab(tr); - }); - }); -}); diff --git a/web/static/js/kill_list.js b/web/static/js/kill_list.js new file mode 100644 index 0000000..c8341c8 --- /dev/null +++ b/web/static/js/kill_list.js @@ -0,0 +1,74 @@ +window.addEvent('domready', function() { + var split = document.location.pathname.split('/'); + var entity_type = split[1]; + var entity_id = split[2]; + ykill.api(document.location.pathname, function(data) { + if (data['entity_name']) + document.title += ' - ' + data['entity_name']; + + var table = $('kills').getChildren('tbody')[0]; + data['kills'].each(function(kill) { + var tr = new Element('tr'); + + var kill_time = kill['kill_time'].split(' ', 2); + var a = new Element('a', {'href': '/kill/' + kill['kill_id']}); + a.appendText(kill_time[0]); + a.grab(new Element('br')); + a.appendText(kill_time[1]); + var td = new Element('td').grab(a); + tr.grab(td); + + td = new Element('td'); + td.appendText(kill['system_name'] + ' '); + td.grab(new Element('span', {'html': kill['security'].toFixed(1)})); + td.grab(new Element('br')); + td.appendText(kill['region']); + tr.grab(td); + + td = new Element('td'); + var victim = kill['victim']; + td.adopt( + ykill.portrait(victim['ship_type_id'], victim['ship_name'], 'type', '_32.png'), + ykill.portrait(victim['character_id'], victim['character_name'], 'character', '_32.jpg') + ); + tr.grab(td); + + td = new Element('td'); + td.appendText(victim['character_name']); + td.grab(new Element('br')); + td.appendText(victim['corporation_name']); + if (victim['alliance_id']) + td.appendText(' / ' + victim['alliance_name']); + if (victim['faction_id']) + td.appendText(' / ' + victim['faction_name']); + tr.grab(td); + + td = new Element('td'); + var final_blow = kill['final_blow']; + td.adopt( + ykill.portrait(final_blow['ship_type_id'], final_blow['ship_name'], 'type', '_32.png'), + ykill.portrait(final_blow['character_id'], final_blow['character_name'], 'character', '_32.jpg') + ); + tr.grab(td); + + td = new Element('td'); + td.appendText(final_blow['character_name'] + ' (' + kill['attackers'] + ')'); + td.grab(new Element('br')); + td.appendText(final_blow['corporation_name']); + if (final_blow['alliance_id']) + td.appendText(' / ' + final_blow['alliance_name']); + if (final_blow['faction_id']) + td.appendText(' / ' + final_blow['faction_name']); + tr.grab(td); + + td = new Element('td'); + var millions = kill['cost'] / (100 * 1000000); + td.appendText(ykill.format_isk(millions)); + if (victim[entity_type + '_id'] == entity_id) + td.addClass('loss'); + tr.grab(td); + + table.grab(tr); + }); + }); +}); diff --git a/web/templates/corporation.html b/web/templates/corporation.html deleted file mode 100644 index c8550d7..0000000 --- a/web/templates/corporation.html +++ /dev/null @@ -1,25 +0,0 @@ -{% extends "base.html" %} - -{% block js %} - -{% end %} - -{% block css %} - -{% end %} - -{% block main %} - - - - - - - - - - - -
timesystemvictimkiller(s)value
- -{% end %} diff --git a/web/templates/kill_list.html b/web/templates/kill_list.html new file mode 100644 index 0000000..1c672d3 --- /dev/null +++ b/web/templates/kill_list.html @@ -0,0 +1,25 @@ +{% extends "base.html" %} + +{% block js %} + +{% end %} + +{% block css %} + +{% end %} + +{% block main %} + + + + + + + + + + + +
timesystemvictimkiller(s)value
+ +{% end %} -- cgit v1.2.3