Statistikk!

Foreløpig kan man få produkter sortert etter antall solgt og etter
total inntekt.  Flere ting som kan legges til: totalt salg per ukedag,
per time i døgnet, per måned etc.
This commit is contained in:
Øystein Ingmar Skartsæterhagen 2011-01-30 21:54:23 +00:00
parent 768be1bfbf
commit 8d777ffb9a
1 changed files with 64 additions and 22 deletions

View File

@ -2,6 +2,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sqlalchemy import sqlalchemy
from sqlalchemy.sql import func
from sqlalchemy import desc
import re import re
import sys import sys
import os import os
@ -907,24 +909,55 @@ class ProductSearchMenu(Menu):
self.pause() self.pause()
# def dwim_search(string, session): class ProductPopularityMenu(Menu):
# typ = guess_data_type(string) def __init__(self):
# if typ == None: Menu.__init__(self, 'Products by popularity', uses_db=True)
# print 'This does not make sense'
# return def _execute(self):
# retriever = {'card': retrieve_user, self.print_header()
# 'username': retrieve_user, text = ''
# 'bar_code': retrieve_product, sub = \
# 'product_name': retrieve_product} self.session.query(PurchaseEntry.product_bar_code,
# value_type = {'card': 'user', func.count('*').label('purchase_count'))\
# 'username': 'user', .group_by(PurchaseEntry.product_bar_code)\
# 'bar_code': 'product', .subquery()
# 'product_name': 'product'} product_list = \
# value = retriever[typ](string, session) self.session.query(Product, sub.c.purchase_count)\
# # if value == None: .outerjoin((sub, Product.bar_code==sub.c.product_bar_code))\
# # print 'Input "%s" interpreted as %s; no matching %s found.' \ .order_by(desc(sub.c.purchase_count))\
# # % (string, typ, value_type[typ]) .filter(sub.c.purchase_count != None)\
# return (value_type[typ], value) .all()
line_format = '%10s | %-'+str(Product.name_length)+'s\n'
text += line_format % ('items sold', 'product')
text += '-'*58 + '\n'
for product, number in product_list:
text += line_format % (number, product.name)
less(text)
class ProductRevenueMenu(Menu):
def __init__(self):
Menu.__init__(self, 'Products by revenue', uses_db=True)
def _execute(self):
self.print_header()
text = ''
sub = \
self.session.query(PurchaseEntry.product_bar_code,
func.count('*').label('purchase_count'))\
.group_by(PurchaseEntry.product_bar_code)\
.subquery()
product_list = \
self.session.query(Product, sub.c.purchase_count)\
.outerjoin((sub, Product.bar_code==sub.c.product_bar_code))\
.order_by(desc(sub.c.purchase_count*Product.price))\
.filter(sub.c.purchase_count != None)\
.all()
line_format = '%7s | %10s | %5s | %-'+str(Product.name_length)+'s\n'
text += line_format % ('revenue', 'items sold', 'price', 'product')
text += '-'*76 + '\n'
for product, number in product_list:
text += line_format % (number*product.price, number, product.price, product.name)
less(text)
def restart(): def restart():
@ -936,12 +969,21 @@ def restart():
if not conf.stop_allowed: if not conf.stop_allowed:
signal.signal(signal.SIGTSTP, signal.SIG_IGN) signal.signal(signal.SIGTSTP, signal.SIG_IGN)
main = Menu('Dibbler main menu', main = Menu('Dibbler main menu',
items=[BuyMenu(), ProductListMenu(), ShowUserMenu(), UserListMenu(), items=[BuyMenu(),
AdjustCreditMenu(), TransferMenu(), ProductListMenu(),
ShowUserMenu(),
UserListMenu(),
AdjustCreditMenu(),
TransferMenu(),
Menu('Add/edit', Menu('Add/edit',
items=[AddUserMenu(), EditUserMenu(), items=[AddUserMenu(),
AddProductMenu(), EditProductMenu()]), EditUserMenu(),
AddProductMenu(),
EditProductMenu()]),
ProductSearchMenu(), ProductSearchMenu(),
Menu('Statistics',
items=[ProductPopularityMenu(),
ProductRevenueMenu()]),
FAQMenu() FAQMenu()
], ],
exit_msg='happy happy joy joy', exit_msg='happy happy joy joy',