Skip to content

Commit 85619b0

Browse files
committed
Initial checkin of a UI for developers of the core.
1 parent eab8917 commit 85619b0

9 files changed

+24906
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# This is Bene specific
1212
.DS_Store
1313

14+
elm-stuff/
15+
1416
## Non LocalZero specific standard python project gitignore
1517

1618
# Byte-compiled / optimized / DLL files

commands/cmd_explorer.py

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
###### WORDS OF WARNING
2+
# This implements a simple http JSON "RPC" server for the generator
3+
#
4+
# The keyword here is simple! You do NOT want to run this open on the
5+
# internet. It is purely a way to get a UI for developers of the generator
6+
# up and running, easily without having to spin up docker or anything else.
7+
#
8+
# More specifically this is not intented to be the RPC server that we will
9+
# offer to the outside world. This is just a quick-dirty test bed for RPCs
10+
# + the thing needed to provide the UI.
11+
import sys
12+
import json
13+
from generatorcore.inputs import Inputs
14+
from generatorcore.generator import calculate
15+
from generatorcore.refdata import RefData
16+
from generatorcore.makeentries import make_entries
17+
from http.server import HTTPServer, BaseHTTPRequestHandler
18+
19+
20+
def cmd_explorer(args):
21+
rd = RefData.load()
22+
with open("explorer/index.html") as index_file:
23+
index = index_file.read()
24+
25+
class ExplorerHandler(BaseHTTPRequestHandler):
26+
def handle_index(self):
27+
self.send_response(200)
28+
self.send_header("Content-type", "text/html")
29+
self.end_headers()
30+
self.wfile.write(index.encode())
31+
32+
def handle_calculate(self, ags, year):
33+
error = None
34+
response = ""
35+
try:
36+
e = make_entries(rd, ags, year)
37+
inputs = Inputs(
38+
facts_and_assumptions=rd.facts_and_assumptions(), entries=e
39+
)
40+
g = calculate(inputs)
41+
response = json.dumps(g.result_dict())
42+
except Exception as e:
43+
error = e
44+
45+
if error is None:
46+
self.send_response(200)
47+
self.send_header("Content-type", "application/json")
48+
self.end_headers()
49+
self.wfile.write(response.encode())
50+
else:
51+
self.send_response(500)
52+
print(error)
53+
54+
def do_GET(self):
55+
print(self.command)
56+
print(self.path.split("/"))
57+
match self.path.split("/"):
58+
case ["", "calculate", ags, year]:
59+
self.handle_calculate(ags, int(year))
60+
61+
case ["", ""]:
62+
self.handle_index()
63+
64+
case other:
65+
self.send_response(404)
66+
self.end_headers()
67+
return
68+
69+
httpd = HTTPServer(("", 4070), ExplorerHandler)
70+
httpd.serve_forever()

devtool.py

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
cmd_test_end_to_end_create_expectation,
2626
cmd_test_end_to_end_run_all_ags,
2727
)
28+
from commands.cmd_explorer import cmd_explorer
2829

2930

3031
def main():
@@ -38,6 +39,11 @@ def main():
3839
cmd_run_parser.add_argument("-o", default=None)
3940
cmd_run_parser.set_defaults(func=cmd_run)
4041

42+
cmd_explorer_parser = subcmd_parsers.add_parser(
43+
"explorer", help="Start the LocalZero Explorer"
44+
)
45+
cmd_explorer_parser.set_defaults(func=cmd_explorer)
46+
4147
cmd_make_entries_parser = subcmd_parsers.add_parser("make", help="Run make entries")
4248
cmd_make_entries_parser.add_argument("-ags", default="03159016")
4349
cmd_make_entries_parser.add_argument("-year", default=2035)

explorer/elm.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"type": "application",
3+
"source-directories": [
4+
"src"
5+
],
6+
"elm-version": "0.19.1",
7+
"dependencies": {
8+
"direct": {
9+
"coinop-logan/elm-format-number": "1.0.0",
10+
"elm/browser": "1.0.2",
11+
"elm/core": "1.0.5",
12+
"elm/html": "1.0.0",
13+
"elm/http": "2.0.0",
14+
"elm/json": "1.1.3",
15+
"elm-community/array-extra": "2.4.0",
16+
"elm-community/list-extra": "8.5.2",
17+
"feathericons/elm-feather": "1.5.0",
18+
"mdgriffith/elm-ui": "1.1.8",
19+
"terezka/elm-charts": "3.0.0"
20+
},
21+
"indirect": {
22+
"danhandrea/elm-time-extra": "1.1.0",
23+
"debois/elm-dom": "1.3.0",
24+
"elm/bytes": "1.0.8",
25+
"elm/file": "1.0.5",
26+
"elm/parser": "1.1.0",
27+
"elm/svg": "1.0.1",
28+
"elm/time": "1.0.0",
29+
"elm/url": "1.0.0",
30+
"elm/virtual-dom": "1.0.2",
31+
"justinmimbs/date": "4.0.1",
32+
"justinmimbs/time-extra": "1.1.1",
33+
"myrho/elm-round": "1.0.4",
34+
"ryannhg/date-format": "2.3.0",
35+
"terezka/intervals": "2.0.1"
36+
}
37+
},
38+
"test-dependencies": {
39+
"direct": {},
40+
"indirect": {}
41+
}
42+
}

0 commit comments

Comments
 (0)