Permalink
Browse files

Redesigned character sheet

  • Loading branch information...
1 parent 0a16c17 commit afcd9db9e68d0005d9a6b7a40ffdae97d054a241 @westmark committed Jun 7, 2012
View
@@ -21,6 +21,12 @@ handlers:
static_dir: static
secure: always
+#Admin
+- url: /admin/.*
+ script: maeve.admin.app
+ login: admin
+ secure: always
+
#Profile
- url: /profile.*
script: maeve.profile_view.app
View
@@ -0,0 +1,4 @@
+cron:
+- description: 15 minute sync task
+ url: /_cron
+ schedule: every 15 minutes
View
@@ -0,0 +1,25 @@
+# -*- coding: UTF-8 -*-
+
+from maeve.web import BaseHandler
+from maeve.settings import webapp2_config
+from maeve.utils import is_prod_environment
+from maeve.models import Profile
+from google.appengine.ext.ndb import toplevel
+from google.appengine.api import users
+import webapp2
+
+
+class ProfileAdminHandler(BaseHandler):
+
+ def get(self,):
+ self.render_response('admin/index.html')
+
+ def post(self):
+
+
+app = webapp2.WSGIApplication([
+ (r'/admin/profile/?$', ProfileAdminHandler),
+ ],
+ debug=(not is_prod_environment()),
+ config=webapp2_config
+ )
@@ -1,6 +1,6 @@
# -*- coding: UTF-8 -*-
-from maeve.web import BaseHandler, profile_required
+from maeve.web import BaseHandler, profile_required, character_view
from maeve.settings import webapp2_config
from maeve.utils import is_prod_environment
from maeve.models import Account, Character, WalletTransaction
@@ -11,38 +11,36 @@
class CharacterHandler(BaseHandler):
- def get(self, char_id):
+ @character_view
+ def get(self):
env = {}
- char = Character.by_char_id(char_id)
+ char = self.character
- if char:
- env.update(dict(character=char,
- account=char.account,
- current='dashboard'))
+ env.update(dict(character=char,
+ account=char.account,
+ current='dashboard'))
- if char.active:
- pass
+ if char.active:
+ pass
- self.render_response('character/index.html', env)
- else:
- self.session.add_flash('No character with that id found', key='top_messages')
- self.redirect('/profile')
+ self.render_response('character/index.html', env)
class CharacterActivationHandler(BaseHandler):
- def post(self, char_id, action):
+ @character_view
+ def post(self, action):
- char = Character.by_char_id(char_id)
+ char = self.character
if char:
if action == 'activate':
char.active = True
self.session.add_flash('Character {0} activated!'.format(char.name), key='top_messages', level='success')
char.put_async()
- self.redirect('/character/{0}'.format(char.char_id))
+ self.redirect('/character?char={0}'.format(char.char_id))
else:
self.session.add_flash('No character with that id found', key='top_messages', level='warning')
@@ -51,27 +49,40 @@ def post(self, char_id, action):
class CharacterTransactionsHandler(BaseHandler):
- def get(self, char_id):
+ @character_view
+ def get(self):
env = {}
- char = Character.by_char_id(char_id)
- if char:
- env.update(dict(character=char,
- account=char.account,
- current='transactions',
- WalletTransaction=WalletTransaction))
+ env.update(dict(character=self.character,
+ account=self.character.account,
+ current='transactions'))
- if char.active:
- pass
+ if self.character.active:
+ pass
self.render_response('character/transactions.html', env)
- else:
- self.session.add_flash('No character with that id found', key='top_messages')
- self.redirect('/profile')
+
+
+class CharacterItemAnalysisHandler(BaseHandler):
+
+ @character_view
+ def get(self):
+ env = {}
+ env.update(dict(character=self.character,
+ account=self.character.account,
+ current='analysis',
+ WalletTransaction=WalletTransaction))
+
+ if self.character.active:
+ pass
+
+ self.render_response('character/analysis.html', env)
+
app = webapp2.WSGIApplication([
- (r'/character/(\d+)/?$', CharacterHandler),
- (r'/character/(\d+)/(activate)/?$', CharacterActivationHandler),
- (r'/character/(\d+)/transactions/?$', CharacterTransactionsHandler),
+ (r'/character/?$', CharacterHandler),
+ (r'/character/(activate)/?$', CharacterActivationHandler),
+ (r'/character/transactions/?$', CharacterTransactionsHandler),
+ (r'/character/analysis/?$', CharacterItemAnalysisHandler),
],
debug=(not is_prod_environment()),
config=webapp2_config
View
@@ -97,8 +97,8 @@ class WalletTransaction(model.Model):
transaction_id = model.IntegerProperty('ti', required=True)
transaction_date = model.DateTimeProperty('td', required=True)
quantity = model.IntegerProperty('q', required=True, indexed=False)
- type_name = model.StringProperty('tn', required=True, indexed=False)
type_id = model.StringProperty('tyi', required=True)
+ station_id = model.StringProperty('si', required=True)
unit_price = model.FloatProperty('up', required=True, indexed=False)
client_id = model.StringProperty('cli', required=True, indexed=False)
client_name = model.StringProperty('cln', required=True, indexed=False)
@@ -137,11 +137,6 @@ class ItemTypeIndex(model.Model):
items = model.JsonProperty(default={})
- @classmethod
- def get(cls, item_id):
- idx = ItemTypeIndex.query().get()
- return (idx.items or {}).get(item_id, None)
-
def find(cls, name_part):
import re
name_re = re.compile('^.*?{0}.*$'.format(name_part.lower()), flags=re.IGNORECASE)
@@ -150,6 +145,11 @@ def find(cls, name_part):
return matches
+class StationIndex(model.Model):
+
+ stations = model.JsonProperty(default={})
+
+
class ItemStats(model.Model):
user = model.UserProperty('u', required=True)
character_key = model.KeyProperty('ck', kind='Character', required=True)
@@ -1,66 +1,86 @@
# -*- coding: UTF-8 -*-
-from maeve.web import BaseHandler, profile_required
+from maeve.web import BaseHandler, character_view
from maeve.settings import webapp2_config
from maeve.utils import is_prod_environment, GenericModelEncoder, price_fmt, to_jstime
-from maeve.models import Character, WalletTransaction, ItemTypeIndex
-from maeve.statistics import get_filtered_transactions, extend_transactions_query_result
-from google.appengine.ext.ndb import toplevel
-from google.appengine.api import users
+from maeve.models import WalletTransaction, ItemTypeIndex, StationIndex
+from maeve.statistics import get_filtered_transactions
import webapp2
import json
import numpy
+class CoreItemStatsHandler(BaseHandler):
+ @character_view
+ def get(self):
+ env = {
+ 'WalletTransaction': WalletTransaction
+ }
+ self.render_response('character/itemanalysis.html', env)
+
+
class TransactionsHandler(BaseHandler):
+ @character_view
def get(self):
- char_id = self.request.get('char', None)
filters = json.loads(self.request.get('filters', '{}'))
- result = get_filtered_transactions(Character.by_char_id(char_id), filters)
+ item_index, station_index = ItemTypeIndex.query().get_async(), StationIndex.query().get_async()
+ result = get_filtered_transactions(self.character, filters)
results_as_dct = [r.to_dict() for r in result]
+ item_index, station_index = item_index.get_result().items, station_index.get_result().stations
+
for dct in results_as_dct:
dct['balance_change'] = dct['unit_price'] * dct['quantity']
if dct['transaction_type'] == WalletTransaction.BUY:
dct['balance_change'] *= -1
dct['balance_change_str'] = price_fmt(dct['balance_change'])
dct['unit_price_str'] = price_fmt(dct['unit_price'])
+ dct['type_name'] = item_index.get(dct['type_id'], '<Unknown item>')
+ dct['station_name'] = station_index.get(dct['station_id'], '<Unknown station>')
self.render_json(results_as_dct, cls=GenericModelEncoder)
-class TransactionsAverageHandler(BaseHandler):
+class TransactionsMeanPriceHandler(BaseHandler):
+ @character_view
def get(self):
try:
- char_id = self.request.get('char', None)
type_id = self.request.get('type_id', None)
- quantity = int(self.request.get('quantity', 10))
+ item_index = ItemTypeIndex.query().get_async()
+ quantity = int(self.request.get('quantity', 10) or 10)
transaction_type = int(self.request.get('transaction_type', WalletTransaction.BUY))
- result = get_filtered_transactions(Character.by_char_id(char_id),
+ result = get_filtered_transactions(self.character,
filters=dict(transaction_type=transaction_type,
type_id=type_id,
limit=quantity))
- oldest_date, prices, i = None, [], 0
+ oldest_date, prices, i, item_name = None, [], 0, None
+ item_index = item_index.get_result().items
+
for t in result:
- if i > quantity:
+ if not item_name:
+ item_name = item_index.get(t.type_id, '<Unknown item>')
+ if i >= quantity:
break
oldest_date = t.transaction_date
for j in range(t.quantity):
prices.append(t.unit_price)
i += 1
- if i > quantity:
+ if i >= quantity:
break
self.render_json(dict(prices=prices,
+ item_name=item_name,
+ transaction_type=transaction_type,
+ transaction_type_name=(transaction_type == WalletTransaction.BUY and 'Buy' or 'Sell'),
oldest_date=to_jstime(oldest_date),
- median=numpy.median(prices),
- mean=numpy.mean(prices)))
+ median=price_fmt(numpy.median(prices)),
+ mean=price_fmt(numpy.mean(prices))))
except:
import traceback
@@ -78,9 +98,10 @@ def get(self):
self.render_json(dict(matches=index.find(query)))
app = webapp2.WSGIApplication([
+ (r'/stat/commodity/stats/?', CoreItemStatsHandler),
(r'/stat/commodity/search/?$', SeachCommodityHandler),
(r'/stat/transactions/?$', TransactionsHandler),
- (r'/stat/transactions/average/?$', TransactionsAverageHandler),
+ (r'/stat/transactions/mean/?$', TransactionsMeanPriceHandler),
],
debug=(not is_prod_environment()),
config=webapp2_config
View
@@ -3,7 +3,7 @@
from maeve.web import BaseHandler
from maeve.settings import webapp2_config
from maeve.utils import is_prod_environment
-from maeve.tasks import index_all_characters, index_character, update_item_index
+from maeve.tasks import index_all_characters, index_character, update_index
from maeve.models import Character, Account
from google.appengine.ext.ndb import toplevel, model
from google.appengine.api import taskqueue
@@ -30,10 +30,13 @@ def post(self):
character = model.Key(urlsafe=char_key).get()
if character and character.active:
account = character.account_key.get()
- items = index_character(character, account)
+ items, stations = index_character(character, account)
if items:
taskqueue.add(url='/_task/index',
- params={'values': json.dumps(items)},
+ params={
+ 'items': json.dumps(items),
+ 'stations': json.dumps(stations)
+ },
queue_name='index-update')
@@ -45,8 +48,9 @@ def get(self):
@toplevel
def post(self):
- new_values = json.loads(self.request.get('values', '{}'))
- update_item_index(new_values)
+ new_items = json.loads(self.request.get('items', '{}'))
+ new_stations = json.loads(self.request.get('stations', '{}'))
+ update_index(new_items, new_stations)
app = webapp2.WSGIApplication([
Oops, something went wrong.

0 comments on commit afcd9db

Please sign in to comment.