Source code for turberfield.eargain.types

#!/usr/bin/env python3
# encoding: UTF-8

# This file is part of turberfield.
#
# Turberfield is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Turberfield is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with turberfield.  If not, see <http://www.gnu.org/licenses/>.

from collections import OrderedDict
from collections import namedtuple
import enum

from tallywallet.common.ledger import Column
from tallywallet.common.ledger import Role

from turberfield.common.dramatics import Drama
from turberfield.common.tricks import fields_of

SEC = 1
HOUR = 60 * 60 * SEC
DAY = 24 * HOUR
WEEK = 7 * DAY
SEASON = 13 * WEEK
YEAR = 52 * WEEK

HONOUR = int(1E3)
NUTS_PER_KG = int(1E3 / 1.4)  # 1.4g per nut
STONE_KG_RATE = 8 / HOUR


Lodge = namedtuple("Lodge", ["name", "capacity"])

@enum.unique
class Commodity(enum.Enum):
    STON = "stone"
    SILV = "silver"
    COIN = "coin"
    FOOD = "food"
    SCRP = "scrip"
    NUTS = "nuts"


@enum.unique
[docs]class CreditRelationship(enum.Enum): inactive = "inactive" welcome = "welcome" """A new customer with favourable credit""" established = "established" """Established customer under credit control"""
@enum.unique class TradePosition(enum.Enum): buying = "buying" selling = "selling" class Scrip(enum.Enum): seed = 1 nut = 2 class DecimalCoin(enum.Enum): penny = 1 twopence = 2 five = 5 ten = 10 twenty = 20 fifty = 50 pound = 100 twopound = 200 class ImperialCoin(enum.Enum): p = 1 # penny t = 6 # tanner f = 10 # florin s = 12 # shilling d = 100 # dollar l = 240 # pound g = 252 # guinea @enum.unique class Mass(enum.Enum): g = 1 Kg = 1000 @enum.unique class BorrowingToDevelopStates(enum.Enum): inactive = 1 pending = 2 arranging_funds = 3 agreed_funds = 4 developing = 5 BorrowingToDevelop = namedtuple("BorrowingToDevelop", fields_of(Drama)) Borrowing = namedtuple("Borrowing", fields_of(Drama) + ["val", "fee", "rate"]) # See tallywallet.common.dramatics #Exchange = namedtuple("Exchange", fields_of(Drama) + ["val", "path", "fee"]) # See tallywallet.common.trade Trade = namedtuple("Trade", fields_of(Drama) + ["val", "path", "fee"]) columns = OrderedDict( (i.name, i) for i in ( Column("honour", Commodity.SILV, Role.asset), Column("reserves", Commodity.SILV, Role.asset), Column("loans", Commodity.SILV, Role.asset), Column("vault", Commodity.SILV, Role.liability), Column("firms", Commodity.SILV, Role.liability), Column("workers", Commodity.SILV, Role.liability), Column("currency", Commodity.SILV, Role.liability), Column("chest", Commodity.SILV, Role.income), Column("nuts", Commodity.NUTS, Role.capital), ))