/ is a helper page
parent
cca0b163b7
commit
228f916283
|
|
@ -53,44 +53,28 @@ func main() {
|
|||
|
||||
if *httpOutput != "" {
|
||||
foo := func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.HasPrefix(r.URL.Path, "/api") {
|
||||
switch r.URL.Path {
|
||||
case "/api/transactions":
|
||||
reqF := f
|
||||
if queryF := r.URL.Query().Get("f"); queryF != "" {
|
||||
reqF, err = ledger.NewFiles(queryF)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
deltas, err := reqF.Deltas()
|
||||
if !strings.HasPrefix(r.URL.Path, "/api") {
|
||||
http.FileServer(http.Dir("./public")).ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
switch r.URL.Path {
|
||||
case "/api/transactions":
|
||||
reqF := f
|
||||
if queryF := r.URL.Query().Get("f"); queryF != "" {
|
||||
reqF, err = ledger.NewFiles(queryF)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
"deltas": deltas.Like(ledger.LikeAfter(time.Now().Add(-1 * time.Hour * 24 * 365 / 2).Format("2006-01"))),
|
||||
"balances": deltas.Balances().Like("^AssetAccount:").WithBPIs(bpis),
|
||||
})
|
||||
return
|
||||
}
|
||||
} else if strings.HasPrefix(r.URL.Path, "/transactions") {
|
||||
f, err := os.Open("./public/transactions.html")
|
||||
deltas, err := reqF.Deltas()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
io.Copy(w, f)
|
||||
return
|
||||
} else if strings.HasPrefix(r.URL.Path, "/graph") || r.URL.Path == "/" {
|
||||
f, err := os.Open("./public/index.html")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
io.Copy(w, f)
|
||||
return
|
||||
} else {
|
||||
http.NotFound(w, r)
|
||||
json.NewEncoder(w).Encode(map[string]any{
|
||||
"deltas": deltas.Like(ledger.LikeAfter(time.Now().Add(-1 * time.Hour * 24 * 365 / 2).Format("2006-01"))),
|
||||
"balances": deltas.Balances().Like("^AssetAccount:").WithBPIs(bpis),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,92 @@
|
|||
<html style="height: calc(100% - 4em);">
|
||||
<header>
|
||||
<nolink rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/light.css">
|
||||
<script>
|
||||
function http(method, remote, callback, body) {
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
|
||||
callback(xmlhttp.responseText, xmlhttp.status)
|
||||
}
|
||||
};
|
||||
xmlhttp.open(method, remote, true);
|
||||
if (typeof body == "undefined") {
|
||||
body = null
|
||||
}
|
||||
xmlhttp.send(body);
|
||||
}
|
||||
function callback(responseBody, responseStatus) {
|
||||
}
|
||||
function draw(form) {
|
||||
path = "/api/bal"
|
||||
query = "?x=y"
|
||||
Array.from(form.elements).forEach((input) => {
|
||||
query += "&" + input.name + "=" + input.value;
|
||||
if (input.name == "mode") {
|
||||
path = "/api/" + input.value;
|
||||
}
|
||||
});
|
||||
console.log(path, query);
|
||||
document.getElementById("graph").src = window.origin + path + query
|
||||
}
|
||||
</script>
|
||||
</header>
|
||||
<body style="height: 100%;">
|
||||
<div id="grapher" style="width: 100%; height: 100%; display: flex; flex-direction: column;">
|
||||
<form onsubmit="draw(this); return false;" style="display: flex; flex-direction: row; flex-wrap: wrap; gap: 1em;">
|
||||
<span>
|
||||
<label for="mode">mode</label>
|
||||
<input name="mode" type="text" value="bal"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="likeName">likeName</label>
|
||||
<input name="likeName" type="text" value="AssetAccount"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="chart">chart</label>
|
||||
<input name="chart" type="text" value="stack"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="predictionMonths">predictionMonths</label>
|
||||
<input name="predictionMonths" type="text" value="120"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="bpi">bpi</label>
|
||||
<input name="bpi" type="text" value="true"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="zoomStart">zoomStart</label>
|
||||
<input name="zoomStart" type="text" value="2023-06"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="prediction">prediction</label>
|
||||
<input name="prediction" type="text" value="interest=AssetAccount:Cash \$ 0.02&prediction=contributions=AssetAccount:Bonds $ 1875&prediction=interest=AssetAccount:Monthly \$ 0.03&prediction=contributions=AssetAccount:Monthly $ 2500"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="predictFixedGrowth">predictFixedGrowth</label>
|
||||
<input name="predictFixedGrowth" type="text" value="VBTLX=0.02&predictFixedGrowth=GLD=0.02&predictFixedGrowth=FXAIX=0.03&predictFixedGrowth=FSPSX=0.03"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="whatIf">whatIf</label>
|
||||
<input name="whatIf" type="text" value="AssetAccount:Cash $ -.10000"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<input type="submit"/>
|
||||
</span>
|
||||
</form>
|
||||
<iframe id="graph" style="flex-grow: 1;">
|
||||
</iframe>
|
||||
</div>
|
||||
</body>
|
||||
<footer>
|
||||
</footer>
|
||||
</html>
|
||||
|
|
@ -1,91 +1,15 @@
|
|||
<html style="height: calc(100% - 4em);">
|
||||
<header>
|
||||
<nolink rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/light.css">
|
||||
<script>
|
||||
function http(method, remote, callback, body) {
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (xmlhttp.readyState == XMLHttpRequest.DONE) {
|
||||
callback(xmlhttp.responseText, xmlhttp.status)
|
||||
}
|
||||
};
|
||||
xmlhttp.open(method, remote, true);
|
||||
if (typeof body == "undefined") {
|
||||
body = null
|
||||
}
|
||||
xmlhttp.send(body);
|
||||
}
|
||||
function callback(responseBody, responseStatus) {
|
||||
}
|
||||
function draw(form) {
|
||||
path = "/api/bal"
|
||||
query = "?x=y"
|
||||
Array.from(form.elements).forEach((input) => {
|
||||
query += "&" + input.name + "=" + input.value;
|
||||
if (input.name == "mode") {
|
||||
path = "/api/" + input.value;
|
||||
}
|
||||
});
|
||||
console.log(path, query);
|
||||
document.getElementById("graph").src = window.origin + path + query
|
||||
}
|
||||
</script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css">
|
||||
</header>
|
||||
<body style="height: 100%;">
|
||||
<div id="grapher" style="width: 100%; height: 100%; display: flex; flex-direction: column;">
|
||||
<form onsubmit="draw(this); return false;" style="display: flex; flex-direction: row; flex-wrap: wrap; gap: 1em;">
|
||||
<span>
|
||||
<label for="mode">mode</label>
|
||||
<input name="mode" type="text" value="bal"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="likeName">likeName</label>
|
||||
<input name="likeName" type="text" value="AssetAccount"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="chart">chart</label>
|
||||
<input name="chart" type="text" value="stack"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="predictionMonths">predictionMonths</label>
|
||||
<input name="predictionMonths" type="text" value="120"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="bpi">bpi</label>
|
||||
<input name="bpi" type="text" value="true"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="zoomStart">zoomStart</label>
|
||||
<input name="zoomStart" type="text" value="2023-06"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="prediction">prediction</label>
|
||||
<input name="prediction" type="text" value="interest=AssetAccount:Cash \$ 0.02&prediction=contributions=AssetAccount:Bonds $ 1875&prediction=interest=AssetAccount:Monthly \$ 0.03&prediction=contributions=AssetAccount:Monthly $ 2500"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="predictFixedGrowth">predictFixedGrowth</label>
|
||||
<input name="predictFixedGrowth" type="text" value="VBTLX=0.02&predictFixedGrowth=GLD=0.02&predictFixedGrowth=FXAIX=0.03&predictFixedGrowth=FSPSX=0.03"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<label for="whatIf">whatIf</label>
|
||||
<input name="whatIf" type="text" value="AssetAccount:Cash $ -.10000"/>
|
||||
</span>
|
||||
|
||||
<span>
|
||||
<input type="submit"/>
|
||||
</span>
|
||||
</form>
|
||||
<iframe id="graph" style="flex-grow: 1;">
|
||||
</iframe>
|
||||
</div>
|
||||
<h1>Moolah2 Hub</h1>
|
||||
<ul style="line-height: 3em;">
|
||||
<li><a href="/transactions.html">Transactions on Shared Chase</a></li>
|
||||
<li><a href="/explore.html">Explore Bel's Money</a></li>
|
||||
<li><a href="/api/bal?x=y&mode=bal&likeName=AssetAccount&chart=stack&predictionMonths=120&bpi=true&zoomStart=2023-06&prediction=interest=AssetAccount:Cash%20\$%200.02&prediction=contributions=AssetAccount:Bonds%20$%201875&prediction=interest=AssetAccount:Monthly%20\$%200.03&prediction=contributions=AssetAccount:Monthly%20$%202500&predictFixedGrowth=VBTLX=0.02&predictFixedGrowth=GLD=0.02&predictFixedGrowth=FXAIX=0.03&predictFixedGrowth=FSPSX=0.03&whatIf=AssetAccount:Cash%20$%20-.10000&=">Project Bel's Net Worth</a></li>
|
||||
<li><a href="/api/reg?x=y&mode=reg&likeName=Withdrawal:&chart=stack&predictionMonths=3&bpi=false&zoomStart=2023-01&prediction=autoContributions=&predictFixedGrowth=VBTLX=0&whatIf=AssetAccount:Cash%20$%20-.10000&=">Expect Bel's Expenses</a></li>
|
||||
</ul>
|
||||
</body>
|
||||
<footer>
|
||||
</footer>
|
||||
|
|
|
|||
Loading…
Reference in New Issue