Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
adbcd5e
Keep only one column and replaced -1 sentinels with NULL for compression
SuperB3333 Jul 20, 2026
e940a37
Small cleanup
SuperB3333 Jul 20, 2026
70349fb
Small cleanup
SuperB3333 Jul 20, 2026
61ea2e0
Optimize Rust seed generator math, remove UB in DspRandom, and fix va…
google-labs-jules[bot] Jul 20, 2026
650903e
Merge pull request #19 from SuperB3333/rust-optimizations-cleanup-479…
SuperB3333 Jul 20, 2026
5a5b604
Removed serde dependency and removed name generation and dead rule.rs…
SuperB3333 Jul 23, 2026
99771f4
Removed bython target, cleaned up algo structure and removed dead was…
SuperB3333 Jul 23, 2026
b40e9da
Removed lots of dead code
SuperB3333 Jul 23, 2026
3288f99
Removed unnecessary unsafe blocks
SuperB3333 Jul 23, 2026
4b5f2ac
Implemented API calls in the frontend application
SuperB3333 Jul 25, 2026
60ece98
Merge remote-tracking branch 'origin/main'
SuperB3333 Jul 25, 2026
446d372
Replaced water item id with OceanType enum
SuperB3333 Jul 25, 2026
88d46f8
Removed theme related columns from db and resolve using only theme id…
SuperB3333 Jul 26, 2026
0df70ce
Fixed lots of small warnings like unnecessary cast
SuperB3333 Jul 26, 2026
14f8259
Keep only one column and replaced -1 sentinels with NULL for compression
SuperB3333 Jul 20, 2026
5ec5c2a
Small cleanup
SuperB3333 Jul 20, 2026
637ab94
Small cleanup
SuperB3333 Jul 20, 2026
718ba64
Removed serde dependency and removed name generation and dead rule.rs…
SuperB3333 Jul 23, 2026
f33a257
Removed bython target, cleaned up algo structure and removed dead was…
SuperB3333 Jul 23, 2026
f4ac596
Removed lots of dead code
SuperB3333 Jul 23, 2026
16049b4
Removed unnecessary unsafe blocks
SuperB3333 Jul 23, 2026
626953c
Merge remote-tracking branch 'origin/precise_ores' into precise_ores
SuperB3333 Jul 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More informion here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
#Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk
Expand Down
6 changes: 3 additions & 3 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

glob_return_dict = {}

@app.get("/start_query")
@app.post("/start_query")
def start_query(query: str, params: list):
h = sha256(query.encode())
h.update(bytes(int(time.time())))
Expand All @@ -20,9 +20,9 @@ def start_query(query: str, params: list):

return qid

@app.get("/query_ready")
@app.post("/query_ready")
def query_status(qid: str):
return "true" if glob_return_dict[qid] is not None else "false"
@app.get("/get_result")
@app.post("/get_result")
def query_result(qid: str):
return list(glob_return_dict[qid])
41 changes: 38 additions & 3 deletions create_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,44 @@ def create_schema():
# Clean up old tables
cursor.execute("DROP TABLE IF EXISTS planets;")
cursor.execute("DROP TABLE IF EXISTS stars;")
cursor.execute("DROP TABLE IF EXISTS themes;")

cursor.execute("""
CREATE TABLE themes (
id SMALLINT PRIMARY KEY,
name TEXT,
temperature REAL,
ocean_type SMALLINT
);
""")
cursor.execute("""
INSERT INTO themes (id, name, temperature, ocean_type) VALUES
(1, 'Ocean 1', 0.0, 1000),
(2, 'Gas 1', 2.0, 0),
(3, 'Gas 2', 1.0, 0),
(4, 'Gas 3', -1.0, 0),
(5, 'Gas 4', -2.0, 0),
(6, 'Desert 1', 2.0, 0),
(7, 'Desert 2', -1.0, 0),
(8, 'Ocean 2', 0.0, 1000),
(9, 'Lava 1', 5.0, -1),
(10, 'Ice 1', -5.0, 1000),
(11, 'Desert 3', -2.0, 0),
(12, 'Desert 4', 1.0, 0),
(13, 'Volcanic 1', 4.0, 1116),
(14, 'Ocean 3', 0.0, 1000),
(15, 'Ocean 4', 0.0, 1000),
(16, 'Ocean 5', 0.0, 1000),
(17, 'Desert 5', 1.0, 0),
(18, 'Ocean 6', 0.0, 1000),
(19, 'Desert 6', 1.0, 0),
(20, 'Desert 7', -2.0, -2),
(21, 'Gas 5', 1.0, 0),
(22, 'Desert 8', 0.0, 1000),
(23, 'Desert 9', 0.08, 0),
(24, 'Desert 10', -4.0, 0),
(25, 'Desert 11', 0.0, 1000);
""")

ore_cols = ",\n".join([f"ore_{ore} INT" for ore in veins])

Expand Down Expand Up @@ -47,13 +85,11 @@ def create_schema():
star_id INT,
{vein_cols},
sun_distance REAL,
temperature REAL,
gas_h REAL,
gas_d REAL,
gas_i REAL,
index SMALLINT,
orbiting SMALLINT,
water_item SMALLINT,
satellites SMALLINT,
theme_id SMALLINT,
gas_giant BOOL,
Expand Down Expand Up @@ -88,7 +124,6 @@ def index(table, val):
index("stars", "type")
index("stars", "spectr")
index("planets", "gas_giant")
index("planets", "temperature")

conn.commit()
cursor.close()
Expand Down
5 changes: 5 additions & 0 deletions frontend/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,8 @@ pre {
white-space: pre-wrap;
word-break: break-all;
}
.results-container {
display: flex;
align-items: center;
gap: 10px;
}
10 changes: 9 additions & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>DSP Rule Builder</h1>
<div class="toolbar">
<button onclick="compileRuleset()">Compile Ruleset</button>
<button onclick="clearAndReset()">Reset</button>
<button onclick="call_api()">Start Request</button>
</div>

<div id="rule-tree-container"></div>
Expand All @@ -21,13 +22,20 @@ <h2>Generated SQL</h2>
<pre id="sql-output"></pre>
<h2>Parameters</h2>
<pre id="params-output"></pre>

<h2>Results</h2>
<div class="results-container">
<h2>Status: </h2>
<h2 id="status-str" style="color: #FF0000">not queried</h2>
</div>
<pre id="results-seeds" hidden></pre>
</div>
</div>

<script src="js/rules.js"></script>
<script src="js/metadata.js"></script>
<script src="js/storage.js"></script>
<script src="js/ui.js"></script>
<script src="js/main.js"></script>
<script src="js/api.js"></script>
</body>
</html>
76 changes: 76 additions & 0 deletions frontend/js/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
function call_api() {
const params = JSON.parse(document.getElementById('params-output').textContent)
const data = {
"query": document.getElementById('sql-output').textContent,
"params": params
}
fetch("/start_query", {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
})
.then(result => {
setStatus("Awaiting results...", "#CDAD00")
status_loop(result.text())
})
.catch(error => {
setStatus("Error while calling API: " + error, "#FF0000")
})

}



function setStatus(text, col) {
const element = document.getElementById("status-str")

element.textContent = text
element.style = "color: " + col
}

function status_loop(qid) {
fetch("/query_ready", {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: '{"qid": "' + qid + '" }'
})
.then(response => response.text())
.then(body => body === "true")
.then(is_ready => {
if (is_ready) {
retrieve_seeds(qid)
}
else {
setTimeout(() => {
status_loop(qid)
}, 5_000);
}
})
.catch(error => {
setStatus("Error while checking status: " + error, "#FF0000")
})
}

function retrieve_seeds(qid) {
fetch("/get_result", {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: '{"qid": "' + qid + '" }'
})
.then(response => response.json())
.then(seed_list => {
let field = document.getElementById("results-seeds")
if (seed_list.length === 0) {
setStatus("No seeds found with the matching criteria", "#CDAD00")
}
else {
field.hidden = false
field.textContent = seed_list.join(", ")

setStatus("Found Seeds", "#00FF00")
}
})
.catch(error => {
setStatus("Error while retrieving seeds: " + error, "#FF0000")
})
}
6 changes: 3 additions & 3 deletions frontend/js/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ class GasGiantRule extends GenericRule {
}
toSql(alias = "p") {
if (this.ice === null) return { sql: `${alias}.gas_giant = %s`, params: [true] };
else if (this.ice === false) return { sql: `(${alias}.gas_giant = %s AND ${alias}.temperature >= %s)`, params: [true, 0.0] };
else if (this.ice === true) return { sql: `(${alias}.gas_giant = %s AND ${alias}.temperature < %s)`, params: [true, 0.0] };
else if (this.ice === false) return { sql: `(${alias}.gas_giant = %s AND (SELECT t.temperature FROM themes t WHERE t.id = ${alias}.theme_id) >= %s)`, params: [true, 0.0] };
else if (this.ice === true) return { sql: `(${alias}.gas_giant = %s AND (SELECT t.temperature FROM themes t WHERE t.id = ${alias}.theme_id) < %s)`, params: [true, 0.0] };
else throw new TypeError("this.ice was neither true, false or null");
}
}
Expand Down Expand Up @@ -360,7 +360,7 @@ class XDistRule extends AmountRule {

class PlanetWaterIdRule extends AmountRule {
toSqlRaw(alias = "p") {
return { sql: `${alias}.water_item`, params: [] };
return { sql: `(SELECT t.ocean_type FROM themes t WHERE t.id = ${alias}.theme_id)`, params: [] };
}
}

Expand Down
Loading
Loading