Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Sheet9// File : Packages/SheetTemplates/Tests/SheetTemplatesTests/GeneratorInputs.swift10// Module : SheetTemplatesTests11// Repository : https://git.spboucher.ai/orix-sheet12// Created : 2026-11-2113// Last Modified : 2026-11-2114//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author : Simon-Pierre Boucher20// Position : Professor of Finance21// Institution : Université du Québec en Outaouais (UQO)22// Department : Département des sciences administratives23// Organization : SP Boucher24//25// Website : https://spboucher.ai26// Git : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General : info@spboucher.ai33// Professional : contact@spboucher.ai34// Direct : simon@spboucher.ai35// Research : research@spboucher.ai36// Development : dev@spboucher.ai37// Support : support@spboucher.ai38// Security/Admin : admin@spboucher.ai39// Notifications : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification : Public66// Distribution : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License : None specified (no license file in this repository)80// Maintainer : Simon-Pierre Boucher81// Technical Contact: dev@spboucher.ai82//83// =============================================================================84// END OF SP BOUCHER SOURCE HEADER85// =============================================================================8687import Foundation88import Testing89import SheetCore90@testable import SheetTemplates9192/// Writes the raw sample inputs of the templates for Generators/gen_expected.py, which recomputes the key outputs93/// with numpy / scipy, independently of the formula engine:94///95/// ORIX_TEMPLATES_INPUTS=Tests/SheetTemplatesTests/Generators/inputs.json swift test --filter exportGeneratorInputs96/// /opt/homebrew/bin/python3 Tests/SheetTemplatesTests/Generators/gen_expected.py97@Suite struct GeneratorInputs {98 static func inputs() -> [String: Any] {99 func ymd(_ d: (Int, Int, Int)) -> [Int] { [d.0, d.1, d.2] }100 let pb = Sample.PersonalBudget.self, bb = Sample.BusinessBudget.self, fs = Sample.Statements.self, cf = Sample.CashForecast.self101 let mo = Sample.Mortgage.self, inv = Sample.Investment.self, dcf = Sample.DCF.self, pr = Sample.Project.self, it = Sample.Inventory.self102 let sa = Sample.Sales.self, rs = Sample.Research.self, st = Sample.Stats.self, rg = Sample.Regression.self, db = Sample.Dashboard.self, gb = Sample.Gradebook.self103 return [104 "personal-budget": ["income": pb.income.map(\.monthly), "plan": pb.expensePlan.map(\.plan), "expenses": pb.expenses],105 "business-budget": ["budget": bb.budget, "actual": bb.actual, "months_closed": bb.monthsClosed],106 "financial-statements": ["years": fs.years, "revenue1": fs.revenue1, "growth": fs.growth, "cogs": fs.cogsPct, "opex": fs.opexPct, "dep": fs.depRate, "interest": fs.interestRate,107 "tax": fs.taxRate, "payout": fs.payout, "capex": fs.capex, "repayment": fs.repayment, "ar_days": fs.arDays, "inv_days": fs.invDays, "ap_days": fs.apDays,108 "cash0": fs.cash0, "ar0": fs.ar0, "inv0": fs.inv0, "ppe0": fs.ppe0, "ap0": fs.ap0, "debt0": fs.debt0, "capital0": fs.capital0, "retained0": fs.retained0],109 "cash-flow-forecast": ["opening": cf.openingCash, "minimum": cf.minimumCash, "receipts": cf.receipts.map(\.values), "payments": cf.payments.map(\.values)],110 "mortgage": ["price": mo.price, "down": mo.downPct, "rate": mo.rate, "years": mo.years, "per_year": mo.perYear],111 "investment-analysis": ["discount": inv.discount, "finance": inv.finance, "reinvest": inv.reinvest, "flows": inv.flows, "dates": inv.dates.map(ymd), "sensitivity": inv.sensitivity],112 "dcf-valuation": ["base": dcf.baseRevenue, "growth": dcf.growth, "margin": dcf.margin, "da": dcf.daPct, "capex": dcf.capexPct, "nwc": dcf.nwcPct, "tax": dcf.taxRate,113 "rf": dcf.riskFree, "beta": dcf.beta, "premium": dcf.premium, "kd": dcf.costOfDebt, "wd": dcf.debtWeight, "g": dcf.terminalGrowth, "multiple": dcf.exitMultiple,114 "debt": dcf.debt, "cash": dcf.cash, "shares": dcf.shares, "steps": dcf.steps],115 "project-plan": ["start": ymd(pr.start), "status": ymd(pr.statusDate), "holidays": pr.holidays.map(ymd), "pred": pr.tasks.map(\.pred), "days": pr.tasks.map(\.days), "done": pr.tasks.map(\.done)],116 "inventory": ["cat": it.items.map(\.cat), "cost": it.items.map(\.cost), "opening": it.items.map(\.opening), "point": it.items.map(\.point),117 "mv_item": it.movements.map(\.item), "mv_in": it.movements.map(\.incoming), "mv_qty": it.movements.map(\.qty), "categories": it.categories.count],118 "sales-tracking": ["month": sa.rows.map(\.month), "rep": sa.rows.map(\.rep), "product": sa.rows.map(\.product), "units": sa.rows.map(\.units), "price": sa.products.map(\.price), "top": sa.topN],119 "research-dataset": ["group": rs.rows.map(\.group), "site": rs.rows.map(\.site), "age": rs.rows.map { $0.age as Any? ?? NSNull() }, "pre": rs.rows.map { $0.pre as Any? ?? NSNull() },120 "post": rs.rows.map { $0.post as Any? ?? NSNull() }],121 "statistical-analysis": ["alpha": st.alpha, "a": st.a, "b": st.b, "hours": st.hours, "score": st.score, "bins": st.bins],122 "regression-report": ["y": rg.y, "x": rg.x],123 "dashboard": ["key": db.rows.map(\.key), "revenue": db.rows.map(\.revenue), "cost": db.rows.map(\.cost), "orders": db.rows.map(\.orders), "new": db.rows.map(\.new),124 "active": db.rows.map(\.active), "period": db.period],125 "gradebook": ["max": gb.assessments.map(\.max), "weight": gb.assessments.map(\.weight), "late": gb.lateDays, "penalty": gb.latePenalty, "at_risk": gb.atRisk,126 "scale_min": gb.scale.map(\.min), "scale_letter": gb.scale.map(\.letter),127 "scores": gb.scores.map { row in row.map { e -> Any in switch e { case .score(let v): return v; case .exempt: return "EX"; case .missing: return NSNull() } } }],128 ]129 }130131 @Test func exportGeneratorInputs() throws {132 guard let path = ProcessInfo.processInfo.environment["ORIX_TEMPLATES_INPUTS"] else { return }133 let data = try JSONSerialization.data(withJSONObject: Self.inputs(), options: [.prettyPrinted, .sortedKeys])134 try data.write(to: URL(fileURLWithPath: path))135 }136137 /// Debug aid: ORIX_TEMPLATES_DUMP=<file> writes the value of every defined name of every template.138 @Test func dumpNamedValues() throws {139 guard let path = ProcessInfo.processInfo.environment["ORIX_TEMPLATES_DUMP"] else { return }140 var out = ""141 for c in Case.all where c.locale == english {142 let wb = BuildCache.shared.get(c).workbook143 out += "== \(c.id)\n"144 for dn in wb.names.values.sorted(by: { $0.name < $1.name }) {145 let v = wb.eval(dn.name)146 if case .array(let a) = v { out += " \(dn.name) = [\(a.rows)x\(a.cols)] \(a.items.prefix(6).map(\.description).joined(separator: ", "))\n" } else { out += " \(dn.name) = \(v)\n" }147 }148 }149 try out.write(toFile: path, atomically: true, encoding: .utf8)150 }151}152153154