Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
p.x_timeline_end *= 0.7
p.x_width = p.x_timeline_end + p.x_margin + p.x_balance_width + p.x_margin
p.x_timeline_before = 100
draw_diagram(p, [sbalances[0:len(sbalances)//3]], 'svg1.html')
p = Params()
random.seed(args.seed+1)
group_dict = groupby(balances, lambda item: item[0].split(':', 1)[0])
group_dict['Equity'].reverse()
groups = [group_dict[x] for x in 'Assets Liabilities Equity Income Expenses'.split()]
draw_diagram(p, groups, 'svg5.html')
random.seed(args.seed+1)
p.draw_clearing = True
draw_diagram(p, groups, 'svg6.html', scale_income=D('0.3'))
random.seed(args.seed+1)
p.draw_opening = True
draw_diagram(p, groups, 'svg7.html')
random.seed(args.seed+1)
p.draw_before = False
draw_diagram(p, groups, 'svg8.html')
random.seed(args.seed+1)
p.draw_after = False
draw_diagram(p, groups, 'svg9.html')
random.seed(args.seed+1)
p.draw_close = True
draw_diagram(p, groups, 'svgA.html')
def extract(self, file):
# Open the CSV file and create directives.
entries = []
index = 0
for index, row in enumerate(csv.DictReader(open(file.name))):
meta = data.new_metadata(file.name, index)
date = parse(row['DATE']).date()
rtype = row['TYPE']
link = "ut{0[REF #]}".format(row)
desc = "({0[TYPE]}) {0[DESCRIPTION]}".format(row)
units = amount.Amount(D(row['AMOUNT']), self.currency)
fees = amount.Amount(D(row['FEES']), self.currency)
other = amount.add(units, fees)
if rtype == 'XFER':
assert fees.number == ZERO
txn = data.Transaction(meta, date, self.FLAG, None, desc, None, {link}, [
data.Posting(self.account_cash, units, None, None, None, None),
data.Posting(self.account_external, -other, None, None, None, None),
])
elif rtype == 'DIV':
assert fees.number == ZERO
# Extract the instrument name from its description.
match = re.search(r'~([A-Z]+)$', row['DESCRIPTION'])
if not match:
logging.error("Missing instrument name in '%s'", row['DESCRIPTION'])
tag = get(row, Col.TAG)
tags = {tag} if tag is not None else data.EMPTY_SET
last4 = get(row, Col.LAST4)
balance = get(row, Col.BALANCE)
# Create a transaction
meta = data.new_metadata(file.name, index)
if txn_date is not None:
meta['date'] = parse_date_liberally(txn_date,
self.dateutil_kwds)
if txn_time is not None:
meta['time'] = str(dateutil.parser.parse(txn_time).time())
if balance is not None:
meta['balance'] = D(balance)
if last4:
last4_friendly = self.last4_map.get(last4.strip())
meta['card'] = last4_friendly if last4_friendly else last4
date = parse_date_liberally(date, self.dateutil_kwds)
txn = data.Transaction(meta, date, self.FLAG, payee, narration,
tags, data.EMPTY_SET, [])
# Attach one posting to the transaction
amount_debit, amount_credit = get_amounts(iconfig, row)
# Skip empty transactions
if amount_debit is None and amount_credit is None:
continue
for amount in [amount_debit, amount_credit]:
if amount is None:
def parse_hours(x: Optional[str]) -> Optional[Decimal]:
if x is None:
return None
return D(x)
url = url_template.format(app_id, from_currency, to_currency)
logging.info("Fetching %s", url)
try:
response = net_utils.retrying_urlopen(url)
if response is None:
return None
response = response.read().decode('utf-8').strip()
response = json.loads(response)
except error.HTTPError:
return None
# we use quantize because otherwise the conversion from an float to a Decimal
# leaves tons of cruft (i.e. dozens of digits of meaningless precision) that
# just clutters up the price file
price = D(response['rates'][to_currency]).quantize(D('1.000000'))
trade_date = datetime.datetime.fromtimestamp(response['timestamp'], datetime.timezone.utc)
return source.SourcePrice(price, trade_date, from_currency)
;{date_begin} open Expenses:Vacation:Employer
""", **locals())
date_prev = None
contrib_retirement = ZERO
contrib_socsec = ZERO
biweekly_pay = annual_salary / 26
gross = biweekly_pay
medicare = gross * D('0.0231')
federal = gross * D('0.2303')
state = gross * D('0.0791')
city = gross * D('0.0379')
sdi = D('1.12')
lifeinsurance = D('24.32')
dental = D('2.90')
medical = D('27.38')
vision = D('42.30')
fixed = (medicare + federal + state + city + sdi +
dental + medical + vision)
# Calculate vacation hours per-pay.
with decimal.localcontext() as ctx:
ctx.prec = 4
vacation_hrs = (ANNUAL_VACATION_DAYS * D('8')) / D('26')
memo = find_child(stmttrn, 'memo', saxutils.unescape)
# Remove memos duplicated from the name.
if memo == name:
memo = None
# Add the transaction type to the description, unless it's not useful.
trntype = find_child(stmttrn, 'trntype', saxutils.unescape)
if trntype in ('DEBIT', 'CREDIT'):
trntype = None
narration = ' / '.join(filter(None, [name, memo, trntype]))
# Create a single posting for it; the user will have to manually categorize
# the other side.
number = find_child(stmttrn, 'trnamt', D)
units = amount.Amount(number, currency)
posting = data.Posting(account, units, None, None, None, None)
# Build the transaction with a single leg.
fileloc = data.new_metadata('', 0)
return data.Transaction(fileloc, date, flag, payee, narration,
data.EMPTY_SET, data.EMPTY_SET, [posting])
lambda: D('120.00'))
match = re.match('a(\d+)', time_str)
if match:
# Create time from the UNIX timestamp. Note: This must be
# initialized in UTC coordinates.
time_marker = datetime.datetime.fromtimestamp(int(match.group(1)),
tz.tzutc())
# Convert to the local timezone if required.
if zone is not None:
time_marker = time_marker.astimezone(zone)
time = time_marker
else:
# Add time as relative from previous timestamp.
seconds = int(time_str) * interval
time = time_marker + datetime.timedelta(seconds=seconds)
price = D(price_str)
return source.SourcePrice(price, time, quote_currency)
],
"san-francisco": [
("Bar Crudo", "Expenses:Food:Restaurant", (70, 20)),
("Pizza Delfina", "Expenses:Food:Restaurant", (20, 6)),
("Waterbar", "Expenses:Food:Restaurant", (50, 20)),
("Mission Chinese Food", "Expenses:Food:Restaurant", (27, 12)),
("Starbucks", "Expenses:Food:Coffee", (6, 2)),
],
}
# Limits on allowed retirement contributions.
RETIREMENT_LIMITS = {2000: D('10500'),
2001: D('10500'),
2002: D('11000'),
2003: D('12000'),
2004: D('13000'),
2005: D('14000'),
2006: D('15000'),
2007: D('15500'),
2008: D('15500'),
2009: D('16500'),
2010: D('16500'),
2011: D('16500'),
2012: D('17000'),
2013: D('17500'),
2014: D('17500'),
2015: D('18000'),
2016: D('18000'),
None: D('18500')}
FILE_PREAMBLE = """\