Эх сурвалжийг харах

most expensive kills on homepage

raylu 12 жил өмнө
parent
commit
29d0528ec6

+ 20 - 1
db/queries.py

@@ -23,7 +23,7 @@ def kill_list(entity_type, entity_id):
 	with db.cursor() as c:
 		kills = db.query(c, '''
 			SELECT DISTINCT(kills.kill_id), kill_time, cost,
-				solarSystemName as system_name, security, regionName as region
+				solarSystemName AS system_name, security, regionName AS region
 			FROM kills
 			JOIN characters ON characters.kill_id = kills.kill_id
 			JOIN kill_costs ON kill_costs.kill_id = kills.kill_id
@@ -154,5 +154,24 @@ def kill(kill_id):
 		'slots': slots,
 	}
 
+def top_cost():
+	with db.cursor() as c:
+		kills = db.query(c, '''
+			SELECT kills.kill_id, cost,
+				ship_type_id, typeName as ship_name,
+				solarSystemName AS system_name, security
+			FROM kills
+			JOIN kill_costs ON kill_costs.kill_id = kills.kill_id
+			JOIN characters ON characters.kill_id = kills.kill_id
+			JOIN eve.invTypes ON typeID = ship_type_id
+			JOIN eve.mapSolarSystems ON solar_system_id = solarSystemID
+			WHERE victim = 1
+			ORDER BY cost DESC
+			LIMIT 25
+			''')
+	#for kill in kills:
+	#	kill['kill_time'] = _format_kill_time(kill['kill_time'])
+	return kills
+
 def _format_kill_time(kill_time):
 	return kill_time.strftime('%Y-%m-%d %H:%m')

+ 6 - 0
web/api.py

@@ -39,12 +39,18 @@ class KillHandler(APIHandler):
 		kill = db.queries.kill(kill_id)
 		self.respond_json(kill)
 
+class TopCostHandler(APIHandler):
+	def get(self):
+		kills = db.queries.top_cost()
+		self.respond_json(kills)
+
 def start():
 	tornado.web.Application(
 		handlers=[
 			(r'/search', SearchHandler),
 			(r'/(alliance|corporation|character)/(.+)', KillListHandler),
 			(r'/kill/(.+)', KillHandler),
+			(r'/top/cost', TopCostHandler),
 		],
 		debug=config.debug,
 	).listen(config.api_port)

+ 33 - 6
web/static/css/base.ccss

@@ -16,11 +16,14 @@ a:
 	text-decoration: none
 	color: #38c
 
-form:
-	input:
-		background: #fff
-		border: 1px solid #cdd
-		padding: 5px 10px
+form input:
+	background: #111
+	border: 1px solid #444
+	padding: 3px 10px
+	color: #ccc
+	height: 2em
+	vertical-align: middle
+	margin: 0
 
 table:
 	border-collapse: collapse
@@ -33,7 +36,31 @@ table:
 .clear:
 	clear: both
 
+#topbar:
+	width: 900px
+	margin: 50px auto 2px
+
+	h1:
+		display: inline-block
+		margin: 0 40px 0 10px
+
+	#nav:
+		display: inline-block
+
+		a:
+			display: inline-block
+			background-color: #111
+			margin: 0 2px
+			padding: 4px
+
+	form:
+		display: inline-block
+		float: right
+
+		input[type="search"]:
+			margin-right: 5px
+
 #wrapper:
 	width: 900px
-	margin: 50px auto
+	margin: 0 auto 50px
 	background: #111

+ 8 - 0
web/static/css/home.ccss

@@ -0,0 +1,8 @@
+#wrapper:
+	padding: 20px
+
+#expensive:
+	margin: 0 auto
+
+	caption, tr:nth-child(odd):
+		background-color: #181818

+ 17 - 0
web/static/js/home.js

@@ -0,0 +1,17 @@
+window.addEvent('domready', function() {
+	var table = $('expensive');
+	ykill.api('/top/cost', function(kills) {
+		kills.each(function(kill) {
+			table.grab(new Element('tr').adopt(
+				new Element('td').grab(ykill.portrait(kill['ship_type_id'], kill['ship_name'], 'type', '_32.png')),
+				new Element('td', {'html': kill['ship_name']}),
+				new Element('td').grab(
+					new Element('a', {
+						'href': '/kill/' + kill['kill_id'],
+						'html': ykill.format_isk(kill['cost'] / (100 * 1000 * 1000 * 1000))
+					})
+				)
+			));
+		});
+	});
+});

+ 9 - 6
web/templates/base.html

@@ -15,13 +15,16 @@
 	{% block js %}{% end %}
 </head>
 <body>
-	<div id="wrapper">
-		<div id="topbar">
-			<div id="title"></div>
-			<div id="nav">
-			</div>
+	<div id="topbar">
+		<h1><a href="/">u r ded</a></h1>
+		<div id="nav">
 		</div>
-
+		<form method="get" action="/search">
+			<input type="search" name="q">
+			<input type="submit" value="search">
+		</form>
+	</div>
+	<div id="wrapper">
 		{% block main %}{% end %}
 	</div>
 </body>

+ 11 - 4
web/templates/home.html

@@ -1,8 +1,15 @@
 {% extends "base.html" %}
 
+{% block js %}
+	<script src="/static/js/home.js"></script>
+{% end %}
+
+{% block css %}
+	<link rel="stylesheet" type="text/css" href="/css/home.css" />
+{% end %}
+
 {% block main %}
-<form method="get" action="/search">
-	<input type="text" name="q">
-	<input type="submit">
-</form>
+<table id="expensive">
+	<caption>most expensive kills</caption>
+</table>
 {% end %}