Temporarily disable brother-ql + friends, update to python 3.13
This commit is contained in:
@@ -1,71 +1,71 @@
|
||||
import os
|
||||
# import os
|
||||
|
||||
from PIL import ImageFont
|
||||
from barcode.writer import ImageWriter, mm2px
|
||||
from brother_ql.labels import ALL_LABELS
|
||||
# from PIL import ImageFont
|
||||
# from barcode.writer import ImageWriter, mm2px
|
||||
# from brother_ql.labels import ALL_LABELS
|
||||
|
||||
|
||||
def px2mm(px, dpi=300):
|
||||
return (25.4 * px) / dpi
|
||||
# def px2mm(px, dpi=300):
|
||||
# return (25.4 * px) / dpi
|
||||
|
||||
|
||||
class BrotherLabelWriter(ImageWriter):
|
||||
def __init__(self, typ="62", max_height=350, rot=False, text=None):
|
||||
super(BrotherLabelWriter, self).__init__()
|
||||
label = next([l for l in ALL_LABELS if l.identifier == typ])
|
||||
assert label is not None
|
||||
self.rot = rot
|
||||
if self.rot:
|
||||
self._h, self._w = label.dots_printable
|
||||
if self._w == 0 or self._w > max_height:
|
||||
self._w = min(max_height, self._h / 2)
|
||||
else:
|
||||
self._w, self._h = label.dots_printable
|
||||
if self._h == 0 or self._h > max_height:
|
||||
self._h = min(max_height, self._w / 2)
|
||||
self._xo = 0.0
|
||||
self._yo = 0.0
|
||||
self._title = text
|
||||
# class BrotherLabelWriter(ImageWriter):
|
||||
# def __init__(self, typ="62", max_height=350, rot=False, text=None):
|
||||
# super(BrotherLabelWriter, self).__init__()
|
||||
# label = next([l for l in ALL_LABELS if l.identifier == typ])
|
||||
# assert label is not None
|
||||
# self.rot = rot
|
||||
# if self.rot:
|
||||
# self._h, self._w = label.dots_printable
|
||||
# if self._w == 0 or self._w > max_height:
|
||||
# self._w = min(max_height, self._h / 2)
|
||||
# else:
|
||||
# self._w, self._h = label.dots_printable
|
||||
# if self._h == 0 or self._h > max_height:
|
||||
# self._h = min(max_height, self._w / 2)
|
||||
# self._xo = 0.0
|
||||
# self._yo = 0.0
|
||||
# self._title = text
|
||||
|
||||
def _init(self, code):
|
||||
self.text = None
|
||||
super(BrotherLabelWriter, self)._init(code)
|
||||
# def _init(self, code):
|
||||
# self.text = None
|
||||
# super(BrotherLabelWriter, self)._init(code)
|
||||
|
||||
def calculate_size(self, modules_per_line, number_of_lines, dpi=300):
|
||||
x, y = super(BrotherLabelWriter, self).calculate_size(
|
||||
modules_per_line, number_of_lines, dpi
|
||||
)
|
||||
# def calculate_size(self, modules_per_line, number_of_lines, dpi=300):
|
||||
# x, y = super(BrotherLabelWriter, self).calculate_size(
|
||||
# modules_per_line, number_of_lines, dpi
|
||||
# )
|
||||
|
||||
self._xo = (px2mm(self._w) - px2mm(x)) / 2
|
||||
self._yo = px2mm(self._h) - px2mm(y)
|
||||
assert self._xo >= 0
|
||||
assert self._yo >= 0
|
||||
# self._xo = (px2mm(self._w) - px2mm(x)) / 2
|
||||
# self._yo = px2mm(self._h) - px2mm(y)
|
||||
# assert self._xo >= 0
|
||||
# assert self._yo >= 0
|
||||
|
||||
return int(self._w), int(self._h)
|
||||
# return int(self._w), int(self._h)
|
||||
|
||||
def _paint_module(self, xpos, ypos, width, color):
|
||||
super(BrotherLabelWriter, self)._paint_module(
|
||||
xpos + self._xo, ypos + self._yo, width, color
|
||||
)
|
||||
# def _paint_module(self, xpos, ypos, width, color):
|
||||
# super(BrotherLabelWriter, self)._paint_module(
|
||||
# xpos + self._xo, ypos + self._yo, width, color
|
||||
# )
|
||||
|
||||
def _paint_text(self, xpos, ypos):
|
||||
super(BrotherLabelWriter, self)._paint_text(xpos + self._xo, ypos + self._yo)
|
||||
# def _paint_text(self, xpos, ypos):
|
||||
# super(BrotherLabelWriter, self)._paint_text(xpos + self._xo, ypos + self._yo)
|
||||
|
||||
def _finish(self):
|
||||
if self._title:
|
||||
width = self._w + 1
|
||||
height = 0
|
||||
max_h = self._h - mm2px(self._yo, self.dpi)
|
||||
fs = int(max_h / 1.2)
|
||||
font_path = os.path.join(
|
||||
os.path.dirname(os.path.realpath(__file__)),
|
||||
"Stranger back in the Night.ttf",
|
||||
)
|
||||
font = ImageFont.truetype(font_path, 10)
|
||||
while width > self._w or height > max_h:
|
||||
font = ImageFont.truetype(font_path, fs)
|
||||
width, height = font.getsize(self._title)
|
||||
fs -= 1
|
||||
pos = ((self._w - width) // 2, 0 - (height // 8))
|
||||
self._draw.text(pos, self._title, font=font, fill=self.foreground)
|
||||
return self._image
|
||||
# def _finish(self):
|
||||
# if self._title:
|
||||
# width = self._w + 1
|
||||
# height = 0
|
||||
# max_h = self._h - mm2px(self._yo, self.dpi)
|
||||
# fs = int(max_h / 1.2)
|
||||
# font_path = os.path.join(
|
||||
# os.path.dirname(os.path.realpath(__file__)),
|
||||
# "Stranger back in the Night.ttf",
|
||||
# )
|
||||
# font = ImageFont.truetype(font_path, 10)
|
||||
# while width > self._w or height > max_h:
|
||||
# font = ImageFont.truetype(font_path, fs)
|
||||
# width, height = font.getsize(self._title)
|
||||
# fs -= 1
|
||||
# pos = ((self._w - width) // 2, 0 - (height // 8))
|
||||
# self._draw.text(pos, self._title, font=font, fill=self.foreground)
|
||||
# return self._image
|
||||
|
||||
@@ -1,98 +1,98 @@
|
||||
import os
|
||||
import datetime
|
||||
|
||||
import barcode
|
||||
from brother_ql.brother_ql_create import create_label
|
||||
from brother_ql.raster import BrotherQLRaster
|
||||
from brother_ql.backends import backend_factory
|
||||
from brother_ql.labels import ALL_LABELS
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
# import barcode
|
||||
# from brother_ql.brother_ql_create import create_label
|
||||
# from brother_ql.raster import BrotherQLRaster
|
||||
# from brother_ql.backends import backend_factory
|
||||
# from brother_ql.labels import ALL_LABELS
|
||||
# from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
from .barcode_helpers import BrotherLabelWriter
|
||||
# from .barcode_helpers import BrotherLabelWriter
|
||||
|
||||
|
||||
def print_name_label(
|
||||
text,
|
||||
margin=10,
|
||||
rotate=False,
|
||||
label_type="62",
|
||||
printer_type="QL-700",
|
||||
):
|
||||
label = next([l for l in ALL_LABELS if l.identifier == label_type])
|
||||
if not rotate:
|
||||
width, height = label.dots_printable
|
||||
else:
|
||||
height, width = label.dots_printable
|
||||
# def print_name_label(
|
||||
# text,
|
||||
# margin=10,
|
||||
# rotate=False,
|
||||
# label_type="62",
|
||||
# printer_type="QL-700",
|
||||
# ):
|
||||
# label = next([l for l in ALL_LABELS if l.identifier == label_type])
|
||||
# if not rotate:
|
||||
# width, height = label.dots_printable
|
||||
# else:
|
||||
# height, width = label.dots_printable
|
||||
|
||||
font_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ChopinScript.ttf")
|
||||
fs = 2000
|
||||
tw, th = width, height
|
||||
if width == 0:
|
||||
while th + 2 * margin > height:
|
||||
font = ImageFont.truetype(font_path, fs)
|
||||
tw, th = font.getsize(text)
|
||||
fs -= 1
|
||||
width = tw + 2 * margin
|
||||
elif height == 0:
|
||||
while tw + 2 * margin > width:
|
||||
font = ImageFont.truetype(font_path, fs)
|
||||
tw, th = font.getsize(text)
|
||||
fs -= 1
|
||||
height = th + 2 * margin
|
||||
else:
|
||||
while tw + 2 * margin > width or th + 2 * margin > height:
|
||||
font = ImageFont.truetype(font_path, fs)
|
||||
tw, th = font.getsize(text)
|
||||
fs -= 1
|
||||
# font_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ChopinScript.ttf")
|
||||
# fs = 2000
|
||||
# tw, th = width, height
|
||||
# if width == 0:
|
||||
# while th + 2 * margin > height:
|
||||
# font = ImageFont.truetype(font_path, fs)
|
||||
# tw, th = font.getsize(text)
|
||||
# fs -= 1
|
||||
# width = tw + 2 * margin
|
||||
# elif height == 0:
|
||||
# while tw + 2 * margin > width:
|
||||
# font = ImageFont.truetype(font_path, fs)
|
||||
# tw, th = font.getsize(text)
|
||||
# fs -= 1
|
||||
# height = th + 2 * margin
|
||||
# else:
|
||||
# while tw + 2 * margin > width or th + 2 * margin > height:
|
||||
# font = ImageFont.truetype(font_path, fs)
|
||||
# tw, th = font.getsize(text)
|
||||
# fs -= 1
|
||||
|
||||
xp = (width // 2) - (tw // 2)
|
||||
yp = (height // 2) - (th // 2)
|
||||
# xp = (width // 2) - (tw // 2)
|
||||
# yp = (height // 2) - (th // 2)
|
||||
|
||||
im = Image.new("RGB", (width, height), (255, 255, 255))
|
||||
dr = ImageDraw.Draw(im)
|
||||
# im = Image.new("RGB", (width, height), (255, 255, 255))
|
||||
# dr = ImageDraw.Draw(im)
|
||||
|
||||
dr.text((xp, yp), text, fill=(0, 0, 0), font=font)
|
||||
now = datetime.datetime.now()
|
||||
date = now.strftime("%Y-%m-%d")
|
||||
dr.text((0, 0), date, fill=(0, 0, 0))
|
||||
# dr.text((xp, yp), text, fill=(0, 0, 0), font=font)
|
||||
# now = datetime.datetime.now()
|
||||
# date = now.strftime("%Y-%m-%d")
|
||||
# dr.text((0, 0), date, fill=(0, 0, 0))
|
||||
|
||||
base_path = os.path.dirname(os.path.realpath(__file__))
|
||||
fn = os.path.join(base_path, "bar_codes", text + ".png")
|
||||
# base_path = os.path.dirname(os.path.realpath(__file__))
|
||||
# fn = os.path.join(base_path, "bar_codes", text + ".png")
|
||||
|
||||
im.save(fn, "PNG")
|
||||
print_image(fn, printer_type, label_type)
|
||||
# im.save(fn, "PNG")
|
||||
# print_image(fn, printer_type, label_type)
|
||||
|
||||
|
||||
def print_bar_code(
|
||||
barcode_value,
|
||||
barcode_text,
|
||||
barcode_type="ean13",
|
||||
rotate=False,
|
||||
printer_type="QL-700",
|
||||
label_type="62",
|
||||
):
|
||||
bar_coder = barcode.get_barcode_class(barcode_type)
|
||||
wr = BrotherLabelWriter(typ=label_type, rot=rotate, text=barcode_text, max_height=1000)
|
||||
# def print_bar_code(
|
||||
# barcode_value,
|
||||
# barcode_text,
|
||||
# barcode_type="ean13",
|
||||
# rotate=False,
|
||||
# printer_type="QL-700",
|
||||
# label_type="62",
|
||||
# ):
|
||||
# bar_coder = barcode.get_barcode_class(barcode_type)
|
||||
# wr = BrotherLabelWriter(typ=label_type, rot=rotate, text=barcode_text, max_height=1000)
|
||||
|
||||
test = bar_coder(barcode_value, writer=wr)
|
||||
base_path = os.path.dirname(os.path.realpath(__file__))
|
||||
fn = test.save(os.path.join(base_path, "bar_codes", barcode_value))
|
||||
print_image(fn, printer_type, label_type)
|
||||
# test = bar_coder(barcode_value, writer=wr)
|
||||
# base_path = os.path.dirname(os.path.realpath(__file__))
|
||||
# fn = test.save(os.path.join(base_path, "bar_codes", barcode_value))
|
||||
# print_image(fn, printer_type, label_type)
|
||||
|
||||
|
||||
def print_image(fn, printer_type="QL-700", label_type="62"):
|
||||
qlr = BrotherQLRaster(printer_type)
|
||||
qlr.exception_on_warning = True
|
||||
create_label(qlr, fn, label_type, threshold=70, cut=True)
|
||||
# def print_image(fn, printer_type="QL-700", label_type="62"):
|
||||
# qlr = BrotherQLRaster(printer_type)
|
||||
# qlr.exception_on_warning = True
|
||||
# create_label(qlr, fn, label_type, threshold=70, cut=True)
|
||||
|
||||
be = backend_factory("pyusb")
|
||||
list_available_devices = be["list_available_devices"]
|
||||
BrotherQLBackend = be["backend_class"]
|
||||
# be = backend_factory("pyusb")
|
||||
# list_available_devices = be["list_available_devices"]
|
||||
# BrotherQLBackend = be["backend_class"]
|
||||
|
||||
ad = list_available_devices()
|
||||
assert ad
|
||||
string_descr = ad[0]["string_descr"]
|
||||
# ad = list_available_devices()
|
||||
# assert ad
|
||||
# string_descr = ad[0]["string_descr"]
|
||||
|
||||
printer = BrotherQLBackend(string_descr)
|
||||
# printer = BrotherQLBackend(string_descr)
|
||||
|
||||
printer.write(qlr.data)
|
||||
# printer.write(qlr.data)
|
||||
|
||||
@@ -4,7 +4,7 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from dibbler.conf import config
|
||||
from dibbler.models import Product, User
|
||||
from dibbler.lib.printer_helpers import print_bar_code, print_name_label
|
||||
# from dibbler.lib.printer_helpers import print_bar_code, print_name_label
|
||||
|
||||
from .helpermenus import Menu
|
||||
|
||||
@@ -21,27 +21,31 @@ Put it up somewhere in the vicinity.
|
||||
def _execute(self):
|
||||
self.print_header()
|
||||
|
||||
thing = self.input_thing("Product/User")
|
||||
print("Printer menu is under renovation, please be patient")
|
||||
|
||||
if isinstance(thing, Product):
|
||||
if re.match(r"^[0-9]{13}$", thing.bar_code):
|
||||
bar_type = "ean13"
|
||||
elif re.match(r"^[0-9]{8}$", thing.bar_code):
|
||||
bar_type = "ean8"
|
||||
else:
|
||||
bar_type = "code39"
|
||||
print_bar_code(
|
||||
thing.bar_code,
|
||||
thing.name,
|
||||
barcode_type=bar_type,
|
||||
rotate=config["printer"]["rotate"],
|
||||
printer_type="QL-700",
|
||||
label_type=config.get("printer", "label_type"),
|
||||
)
|
||||
elif isinstance(thing, User):
|
||||
print_name_label(
|
||||
text=thing.name,
|
||||
label_type=config["printer"]["label_type"],
|
||||
rotate=config["printer"]["rotate"],
|
||||
printer_type="QL-700",
|
||||
)
|
||||
return
|
||||
|
||||
# thing = self.input_thing("Product/User")
|
||||
|
||||
# if isinstance(thing, Product):
|
||||
# if re.match(r"^[0-9]{13}$", thing.bar_code):
|
||||
# bar_type = "ean13"
|
||||
# elif re.match(r"^[0-9]{8}$", thing.bar_code):
|
||||
# bar_type = "ean8"
|
||||
# else:
|
||||
# bar_type = "code39"
|
||||
# print_bar_code(
|
||||
# thing.bar_code,
|
||||
# thing.name,
|
||||
# barcode_type=bar_type,
|
||||
# rotate=config["printer"]["rotate"],
|
||||
# printer_type="QL-700",
|
||||
# label_type=config.get("printer", "label_type"),
|
||||
# )
|
||||
# elif isinstance(thing, User):
|
||||
# print_name_label(
|
||||
# text=thing.name,
|
||||
# label_type=config["printer"]["label_type"],
|
||||
# rotate=config["printer"]["rotate"],
|
||||
# printer_type="QL-700",
|
||||
# )
|
||||
|
||||
@@ -1,231 +1,231 @@
|
||||
#! /usr/bin/env python
|
||||
# #! /usr/bin/env python
|
||||
|
||||
# TODO: fixme
|
||||
# # TODO: fixme
|
||||
|
||||
# -*- coding: UTF-8 -*-
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.dates as mdates
|
||||
# # -*- coding: UTF-8 -*-
|
||||
# import matplotlib.pyplot as plt
|
||||
# import matplotlib.dates as mdates
|
||||
|
||||
from dibbler.lib.statistikkHelpers import *
|
||||
# from dibbler.lib.statistikkHelpers import *
|
||||
|
||||
|
||||
def getInputType():
|
||||
inp = 0
|
||||
while not (inp == "1" or inp == "2" or inp == "3" or inp == "4"):
|
||||
print("type 1 for user-statistics")
|
||||
print("type 2 for product-statistics")
|
||||
print("type 3 for global-statistics")
|
||||
print("type 4 to enter loop-mode")
|
||||
inp = input("")
|
||||
return int(inp)
|
||||
# def getInputType():
|
||||
# inp = 0
|
||||
# while not (inp == "1" or inp == "2" or inp == "3" or inp == "4"):
|
||||
# print("type 1 for user-statistics")
|
||||
# print("type 2 for product-statistics")
|
||||
# print("type 3 for global-statistics")
|
||||
# print("type 4 to enter loop-mode")
|
||||
# inp = input("")
|
||||
# return int(inp)
|
||||
|
||||
|
||||
def getDateFile(date, n):
|
||||
try:
|
||||
if n == 0:
|
||||
inp = input("start date? (yyyy-mm-dd) ")
|
||||
elif n == -1:
|
||||
inp = input("end date? (yyyy-mm-dd) ")
|
||||
year = inp.partition("-")
|
||||
month = year[2].partition("-")
|
||||
return datetime.date(int(year[0]), int(month[0]), int(month[2]))
|
||||
except:
|
||||
print("invalid date, setting start start date")
|
||||
if n == 0:
|
||||
print("to date found on first line")
|
||||
elif n == -1:
|
||||
print("to date found on last line")
|
||||
print(date)
|
||||
return datetime.date(
|
||||
int(date.partition("-")[0]),
|
||||
int(date.partition("-")[2].partition("-")[0]),
|
||||
int(date.partition("-")[2].partition("-")[2]),
|
||||
)
|
||||
# def getDateFile(date, n):
|
||||
# try:
|
||||
# if n == 0:
|
||||
# inp = input("start date? (yyyy-mm-dd) ")
|
||||
# elif n == -1:
|
||||
# inp = input("end date? (yyyy-mm-dd) ")
|
||||
# year = inp.partition("-")
|
||||
# month = year[2].partition("-")
|
||||
# return datetime.date(int(year[0]), int(month[0]), int(month[2]))
|
||||
# except:
|
||||
# print("invalid date, setting start start date")
|
||||
# if n == 0:
|
||||
# print("to date found on first line")
|
||||
# elif n == -1:
|
||||
# print("to date found on last line")
|
||||
# print(date)
|
||||
# return datetime.date(
|
||||
# int(date.partition("-")[0]),
|
||||
# int(date.partition("-")[2].partition("-")[0]),
|
||||
# int(date.partition("-")[2].partition("-")[2]),
|
||||
# )
|
||||
|
||||
|
||||
def dateToDateNumFile(date, startDate):
|
||||
year = date.partition("-")
|
||||
month = year[2].partition("-")
|
||||
day = datetime.date(int(year[0]), int(month[0]), int(month[2]))
|
||||
deltaDays = day - startDate
|
||||
return int(deltaDays.days), day.weekday()
|
||||
# def dateToDateNumFile(date, startDate):
|
||||
# year = date.partition("-")
|
||||
# month = year[2].partition("-")
|
||||
# day = datetime.date(int(year[0]), int(month[0]), int(month[2]))
|
||||
# deltaDays = day - startDate
|
||||
# return int(deltaDays.days), day.weekday()
|
||||
|
||||
|
||||
def getProducts(products):
|
||||
product = []
|
||||
products = products.partition("¤")
|
||||
product.append(products[0])
|
||||
while products[1] == "¤":
|
||||
products = products[2].partition("¤")
|
||||
product.append(products[0])
|
||||
return product
|
||||
# def getProducts(products):
|
||||
# product = []
|
||||
# products = products.partition("¤")
|
||||
# product.append(products[0])
|
||||
# while products[1] == "¤":
|
||||
# products = products[2].partition("¤")
|
||||
# product.append(products[0])
|
||||
# return product
|
||||
|
||||
|
||||
def piePlot(dictionary, n):
|
||||
keys = []
|
||||
values = []
|
||||
i = 0
|
||||
for key in sorted(dictionary, key=dictionary.get, reverse=True):
|
||||
values.append(dictionary[key])
|
||||
if i < n:
|
||||
keys.append(key)
|
||||
i += 1
|
||||
else:
|
||||
keys.append("")
|
||||
plt.pie(values, labels=keys)
|
||||
# def piePlot(dictionary, n):
|
||||
# keys = []
|
||||
# values = []
|
||||
# i = 0
|
||||
# for key in sorted(dictionary, key=dictionary.get, reverse=True):
|
||||
# values.append(dictionary[key])
|
||||
# if i < n:
|
||||
# keys.append(key)
|
||||
# i += 1
|
||||
# else:
|
||||
# keys.append("")
|
||||
# plt.pie(values, labels=keys)
|
||||
|
||||
|
||||
def datePlot(array, dateLine):
|
||||
if not array == []:
|
||||
plt.bar(dateLine, array)
|
||||
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter("%b"))
|
||||
# def datePlot(array, dateLine):
|
||||
# if not array == []:
|
||||
# plt.bar(dateLine, array)
|
||||
# plt.gca().xaxis.set_major_formatter(mdates.DateFormatter("%b"))
|
||||
|
||||
|
||||
def dayPlot(array, days):
|
||||
if not array == []:
|
||||
for i in range(7):
|
||||
array[i] = array[i] * 7.0 / days
|
||||
plt.bar(list(range(7)), array)
|
||||
plt.xticks(
|
||||
list(range(7)),
|
||||
[
|
||||
" mon",
|
||||
" tue",
|
||||
" wed",
|
||||
" thu",
|
||||
" fri",
|
||||
" sat",
|
||||
" sun",
|
||||
],
|
||||
)
|
||||
# def dayPlot(array, days):
|
||||
# if not array == []:
|
||||
# for i in range(7):
|
||||
# array[i] = array[i] * 7.0 / days
|
||||
# plt.bar(list(range(7)), array)
|
||||
# plt.xticks(
|
||||
# list(range(7)),
|
||||
# [
|
||||
# " mon",
|
||||
# " tue",
|
||||
# " wed",
|
||||
# " thu",
|
||||
# " fri",
|
||||
# " sat",
|
||||
# " sun",
|
||||
# ],
|
||||
# )
|
||||
|
||||
|
||||
def graphPlot(array, dateLine):
|
||||
if not array == []:
|
||||
plt.plot(dateLine, array)
|
||||
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter("%b"))
|
||||
# def graphPlot(array, dateLine):
|
||||
# if not array == []:
|
||||
# plt.plot(dateLine, array)
|
||||
# plt.gca().xaxis.set_major_formatter(mdates.DateFormatter("%b"))
|
||||
|
||||
|
||||
def plotUser(database, dateLine, user, n):
|
||||
printUser(database, dateLine, user, n)
|
||||
plt.subplot(221)
|
||||
piePlot(database.personVareAntall[user], n)
|
||||
plt.xlabel("antall varer kjøpt gjengitt i antall")
|
||||
plt.subplot(222)
|
||||
datePlot(database.personDatoVerdi[user], dateLine)
|
||||
plt.xlabel("penger brukt over dato")
|
||||
plt.subplot(223)
|
||||
piePlot(database.personVareVerdi[user], n)
|
||||
plt.xlabel("antall varer kjøpt gjengitt i verdi")
|
||||
plt.subplot(224)
|
||||
dayPlot(database.personUkedagVerdi[user], len(dateLine))
|
||||
plt.xlabel("forbruk over ukedager")
|
||||
plt.show()
|
||||
# def plotUser(database, dateLine, user, n):
|
||||
# printUser(database, dateLine, user, n)
|
||||
# plt.subplot(221)
|
||||
# piePlot(database.personVareAntall[user], n)
|
||||
# plt.xlabel("antall varer kjøpt gjengitt i antall")
|
||||
# plt.subplot(222)
|
||||
# datePlot(database.personDatoVerdi[user], dateLine)
|
||||
# plt.xlabel("penger brukt over dato")
|
||||
# plt.subplot(223)
|
||||
# piePlot(database.personVareVerdi[user], n)
|
||||
# plt.xlabel("antall varer kjøpt gjengitt i verdi")
|
||||
# plt.subplot(224)
|
||||
# dayPlot(database.personUkedagVerdi[user], len(dateLine))
|
||||
# plt.xlabel("forbruk over ukedager")
|
||||
# plt.show()
|
||||
|
||||
|
||||
def plotProduct(database, dateLine, product, n):
|
||||
printProduct(database, dateLine, product, n)
|
||||
plt.subplot(221)
|
||||
piePlot(database.varePersonAntall[product], n)
|
||||
plt.xlabel("personer som har handler produktet")
|
||||
plt.subplot(222)
|
||||
datePlot(database.vareDatoAntall[product], dateLine)
|
||||
plt.xlabel("antall produkter handlet per dag")
|
||||
# plt.subplot(223)
|
||||
plt.subplot(224)
|
||||
dayPlot(database.vareUkedagAntall[product], len(dateLine))
|
||||
plt.xlabel("antall over ukedager")
|
||||
plt.show()
|
||||
# def plotProduct(database, dateLine, product, n):
|
||||
# printProduct(database, dateLine, product, n)
|
||||
# plt.subplot(221)
|
||||
# piePlot(database.varePersonAntall[product], n)
|
||||
# plt.xlabel("personer som har handler produktet")
|
||||
# plt.subplot(222)
|
||||
# datePlot(database.vareDatoAntall[product], dateLine)
|
||||
# plt.xlabel("antall produkter handlet per dag")
|
||||
# # plt.subplot(223)
|
||||
# plt.subplot(224)
|
||||
# dayPlot(database.vareUkedagAntall[product], len(dateLine))
|
||||
# plt.xlabel("antall over ukedager")
|
||||
# plt.show()
|
||||
|
||||
|
||||
def plotGlobal(database, dateLine, n):
|
||||
printGlobal(database, dateLine, n)
|
||||
plt.subplot(231)
|
||||
piePlot(database.globalVareVerdi, n)
|
||||
plt.xlabel("varer kjøpt gjengitt som verdi")
|
||||
plt.subplot(232)
|
||||
datePlot(database.globalDatoForbruk, dateLine)
|
||||
plt.xlabel("forbruk over dato")
|
||||
plt.subplot(233)
|
||||
graphPlot(database.pengebeholdning, dateLine)
|
||||
plt.xlabel("pengebeholdning over tid (negativ verdi utgjør samlet kreditt)")
|
||||
plt.subplot(234)
|
||||
piePlot(database.globalPersonForbruk, n)
|
||||
plt.xlabel("penger brukt av personer")
|
||||
plt.subplot(235)
|
||||
dayPlot(database.globalUkedagForbruk, len(dateLine))
|
||||
plt.xlabel("forbruk over ukedager")
|
||||
plt.show()
|
||||
# def plotGlobal(database, dateLine, n):
|
||||
# printGlobal(database, dateLine, n)
|
||||
# plt.subplot(231)
|
||||
# piePlot(database.globalVareVerdi, n)
|
||||
# plt.xlabel("varer kjøpt gjengitt som verdi")
|
||||
# plt.subplot(232)
|
||||
# datePlot(database.globalDatoForbruk, dateLine)
|
||||
# plt.xlabel("forbruk over dato")
|
||||
# plt.subplot(233)
|
||||
# graphPlot(database.pengebeholdning, dateLine)
|
||||
# plt.xlabel("pengebeholdning over tid (negativ verdi utgjør samlet kreditt)")
|
||||
# plt.subplot(234)
|
||||
# piePlot(database.globalPersonForbruk, n)
|
||||
# plt.xlabel("penger brukt av personer")
|
||||
# plt.subplot(235)
|
||||
# dayPlot(database.globalUkedagForbruk, len(dateLine))
|
||||
# plt.xlabel("forbruk over ukedager")
|
||||
# plt.show()
|
||||
|
||||
|
||||
def alt4menu(database, dateLine, useDatabase):
|
||||
n = 10
|
||||
while 1:
|
||||
print(
|
||||
"\n1: user-statistics, 2: product-statistics, 3:global-statistics, n: adjust amount of data shown q:quit"
|
||||
)
|
||||
try:
|
||||
inp = input("")
|
||||
except:
|
||||
continue
|
||||
if inp == "q":
|
||||
break
|
||||
elif inp == "1":
|
||||
if i == "0":
|
||||
user = input("input full username: ")
|
||||
else:
|
||||
user = getUser()
|
||||
plotUser(database, dateLine, user, n)
|
||||
elif inp == "2":
|
||||
if i == "0":
|
||||
product = input("input full product name: ")
|
||||
else:
|
||||
product = getProduct()
|
||||
plotProduct(database, dateLine, product, n)
|
||||
elif inp == "3":
|
||||
plotGlobal(database, dateLine, n)
|
||||
elif inp == "n":
|
||||
try:
|
||||
n = int(input("set number to show "))
|
||||
except:
|
||||
pass
|
||||
# def alt4menu(database, dateLine, useDatabase):
|
||||
# n = 10
|
||||
# while 1:
|
||||
# print(
|
||||
# "\n1: user-statistics, 2: product-statistics, 3:global-statistics, n: adjust amount of data shown q:quit"
|
||||
# )
|
||||
# try:
|
||||
# inp = input("")
|
||||
# except:
|
||||
# continue
|
||||
# if inp == "q":
|
||||
# break
|
||||
# elif inp == "1":
|
||||
# if i == "0":
|
||||
# user = input("input full username: ")
|
||||
# else:
|
||||
# user = getUser()
|
||||
# plotUser(database, dateLine, user, n)
|
||||
# elif inp == "2":
|
||||
# if i == "0":
|
||||
# product = input("input full product name: ")
|
||||
# else:
|
||||
# product = getProduct()
|
||||
# plotProduct(database, dateLine, product, n)
|
||||
# elif inp == "3":
|
||||
# plotGlobal(database, dateLine, n)
|
||||
# elif inp == "n":
|
||||
# try:
|
||||
# n = int(input("set number to show "))
|
||||
# except:
|
||||
# pass
|
||||
|
||||
|
||||
def main():
|
||||
inputType = getInputType()
|
||||
i = input("0:fil, 1:database \n? ")
|
||||
if inputType == 1:
|
||||
if i == "0":
|
||||
user = input("input full username: ")
|
||||
else:
|
||||
user = getUser()
|
||||
product = ""
|
||||
elif inputType == 2:
|
||||
if i == "0":
|
||||
product = input("input full product name: ")
|
||||
else:
|
||||
product = getProduct()
|
||||
user = ""
|
||||
else:
|
||||
product = ""
|
||||
user = ""
|
||||
if i == "0":
|
||||
inputFile = input("logfil? ")
|
||||
if inputFile == "":
|
||||
inputFile = "default.dibblerlog"
|
||||
database, dateLine = buildDatabaseFromFile(inputFile, inputType, product, user)
|
||||
else:
|
||||
database, dateLine = buildDatabaseFromDb(inputType, product, user)
|
||||
# def main():
|
||||
# inputType = getInputType()
|
||||
# i = input("0:fil, 1:database \n? ")
|
||||
# if inputType == 1:
|
||||
# if i == "0":
|
||||
# user = input("input full username: ")
|
||||
# else:
|
||||
# user = getUser()
|
||||
# product = ""
|
||||
# elif inputType == 2:
|
||||
# if i == "0":
|
||||
# product = input("input full product name: ")
|
||||
# else:
|
||||
# product = getProduct()
|
||||
# user = ""
|
||||
# else:
|
||||
# product = ""
|
||||
# user = ""
|
||||
# if i == "0":
|
||||
# inputFile = input("logfil? ")
|
||||
# if inputFile == "":
|
||||
# inputFile = "default.dibblerlog"
|
||||
# database, dateLine = buildDatabaseFromFile(inputFile, inputType, product, user)
|
||||
# else:
|
||||
# database, dateLine = buildDatabaseFromDb(inputType, product, user)
|
||||
|
||||
if inputType == 1:
|
||||
plotUser(database, dateLine, user, 10)
|
||||
if inputType == 2:
|
||||
plotProduct(database, dateLine, product, 10)
|
||||
if inputType == 3:
|
||||
plotGlobal(database, dateLine, 10)
|
||||
if inputType == 4:
|
||||
alt4menu(database, dateLine, i)
|
||||
# if inputType == 1:
|
||||
# plotUser(database, dateLine, user, 10)
|
||||
# if inputType == 2:
|
||||
# plotProduct(database, dateLine, product, 10)
|
||||
# if inputType == 3:
|
||||
# plotGlobal(database, dateLine, 10)
|
||||
# if inputType == 4:
|
||||
# alt4menu(database, dateLine, i)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
# if __name__ == "__main__":
|
||||
# main()
|
||||
|
||||
Reference in New Issue
Block a user