Skip to content

docs:Integrate terminal-sim demo in documentation #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions docs/source/For User/xterm_demo.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Xterm demo
===========

欢迎使用在线演示功能,您可以在下方的终端中进行交互:

.. raw:: html

<iframe src="../_static/main.html" width="100%" height="500px"></iframe>
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Welcome to Geochemistry π
Complete Pull Request <For Developer/A Completed Pull Request.md>
Add New Model To Framework <For Developer/Add New Model To Framework.md>
Docs Link <For Developer/Developer Docs link.md>
Xterm Demo <For Developer/xterm_demo.rst>

Indices and tables
==================
Expand Down
244 changes: 244 additions & 0 deletions docs/source/static/chatbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
{
"steps": [
{
"id": 1,
"prompt": [
"Welcome to Geochemistry π!",
"Initializing...",
"No Training Data File Provided!",
"Built-in Data Loading.",
"No Application Data File Provided!",
"Built-in Application Data Loading.",
"✨ Use Previous Experiment [y/n] (n):"
],
"options": {
"y": {
"message": [
"Previous Experiment Loaded!",
"Proceeding to the next step..."
],
"nextStep": 2
},
"n": {
"message": [
"New Experiment (GeoPi - Rock Classification):",
"'GeoPi - Rock Classification' is activated."
],
"nextStep": 2
}
}
},
{
"id": 2,
"prompt": [
"(Press Enter key to move forward.)",
"-*-*- Built-in Training Data Option -*-*-",
"1 - Data For Regression",
"2 - Data For Classification",
"3 - Data For Clustering",
"4 - Data For Dimensional Reduction",
"(User) ➜ @Number:"
],
"options": {
"1": {
"message": [
"You selected Regression.",
"Loading Regression Data..."
],
"nextStep": 3
},
"2": {
"message": [
"Successfully loading the built-in inference data set",
"'InferenceData_Classification.xlsx'.",
"--------------------",
"Index - Column Name",
"1 - CITATION",
"2 - SAMPLE NAME",
"3 - Label",
"4 - Notes",
"5 - LATITUDE",
"6 - LONGITUDE",
"7 - Unnamed: 6",
"8 - SIO2(WT%)",
"9 - TIO2(WT%)",
"10 - AL2O3(WT%)",
"11 - CR2O3(WT%)",
"12 - FEOT(WT%)",
"13 - CAO(WT%)",
"14 - MGO(WT%)",
"15 - MNO(WT%)",
"16 - NA2O(WT%)",
"17 - Unnamed: 16",
"18 - SC(PPM)",
"19 - TI(PPM)",
"20 - V(PPM)",
"21 - CR(PPM)",
"22 - NI(PPM)",
"23 - RB(PPM)",
"24 - SR(PPM)",
"25 - Y(PPM)",
"26 - ZR(PPM)",
"27 - NB(PPM)",
"28 - BA(PPM)",
"29 - LA(PPM)",
"30 - CE(PPM)",
"31 - PR(PPM)",
"32 - ND(PPM)",
"33 - SM(PPM)",
"34 - EU(PPM)",
"35 - GD(PPM)",
"36 - TB(PPM)",
"37 - DY(PPM)",
"38 - HO(PPM)",
"39 - ER(PPM)",
"40 - TM(PPM)",
"41 - YB(PPM)",
"42 - LU(PPM)",
"43 - HF(PPM)",
"44 - TA(PPM)",
"45 - PB(PPM)",
"46 - TH(PPM)",
"47 - U(PPM)",
"--------------------"
],
"nextStep": 4
},
"3": {
"message": [
"You selected Clustering.",
"Loading Clustering Data..."
],
"nextStep": 3
},
"4": {
"message": [
"You selected Dimensional Reduction.",
"Loading Dimensional Reduction Data..."
],
"nextStep": 3
}
}
},
{
"id": 4,
"prompt": [
"-*-*- World Map Projection -*-*-",
"World Map Projection for A Specific Element Option:",
"1 - Yes",
"2 - No",
"(Plot) ➜ @Number:"
],
"options": {
"1": {
"message": [
"You selected Yes.",
"Generating World Map Projection..."
],
"nextStep": 5
},
"2": {
"message": [
"You selected No.",
"Skipping World Map Projection."
],
"nextStep": 5
}
}
},
{
"id": 5,
"prompt": [
"(Press Enter key to move forward.)",
"-*-*- Data Selection -*-*-",
"Select the data range you want to process.",
"Input format:",
"1. \"[**, **]; **; [**, **]\" e.g. \"[1, 3]; 7; [10, 13]\"",
"2. \"xx\" e.g. \"7\".",
"Provide valid column ranges for processing.",
"@input:"
],
"validate": "columns",
"message": "Valid column ranges provided. Proceeding to the next step.",
"nextStep": 6
},
{
"id": 6,
"prompt": [
"(Press Enter key to move forward.)",
"-*-*- Missing Values Process -*-*-",
"Do you want to deal with the missing values?",
"1 - Yes",
"2 - No",
"(Data) ➜ @Number:"
],
"options": {
"1": {
"message": [
"You selected to handle missing values.",
"Choose an imputation method."
],
"nextStep": 7
},
"2": {
"message": [
"Skipping missing value processing.",
"Proceeding to the next step."
],
"nextStep": 8
}
}
},
{
"id": 7,
"prompt": [
"Choose Imputation Method:",
"1 - Mean",
"2 - Median",
"3 - Most Frequent",
"4 - Constant",
"(Data) ➜ @Number:"
],
"options": {
"1": { "message": "Using Mean Imputation.", "nextStep": 8 },
"2": { "message": "Using Median Imputation.", "nextStep": 8 },
"3": { "message": "Using Most Frequent Imputation.", "nextStep": 8 },
"4": { "message": "Using Constant Value Imputation.", "nextStep": 8 }
}
},
{
"id": 8,
"prompt": [
"(Press Enter key to move forward.)",
"-*-*- Model Selection -*-*-",
"1 - Logistic Regression",
"2 - Support Vector Machine",
"3 - XGBoost",
"(Model) ➜ @Number:"
],
"options": {
"1": {
"message": [
"Running Logistic Regression Model...",
"Generating outputs."
],
"nextStep": null
},
"2": {
"message": [
"Running Support Vector Machine Model...",
"Generating outputs."
],
"nextStep": null
},
"3": {
"message": [
"Running XGBoost Model...",
"Generating outputs."
],
"nextStep": null
}
}
}
]
}
102 changes: 102 additions & 0 deletions docs/source/static/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Xterm.js Example</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm/css/xterm.css" />
</head>
<body>
<div id="terminal-container" style="width: 100%; height: 400px;"></div>
<script src="https://cdn.jsdelivr.net/npm/xterm/lib/xterm.js"></script>
<script>
document.addEventListener("DOMContentLoaded", async function() {
const terminal = new Terminal({ cols: 80, rows: 24, cursorBlink: true });
const terminalContainer = document.getElementById('terminal-container');
terminal.open(terminalContainer);
terminal.write("> ");

let currentStep = 0;
let inputBuffer = "";
let workflow;

// 加载 JSON 文件
try {
const response = await fetch('../_static/chatbox.json'); // 确保 JSON 文件路径正确
workflow = await response.json();
} catch (error) {
terminal.writeln("\nFailed to load the workflow JSON.");
return;
}

// 显示当前步骤
function displayStep(stepIndex) {
const step = workflow.steps[stepIndex];
step.prompt.forEach(line => terminal.writeln(line));
terminal.write("> ");
}

// 验证输入(例如列范围格式)
function validateInput(input, validationType) {
if (validationType === "columns") {
return /^(\[?\d+,\s*\d+\]?\;?\s*)+$/.test(input);
}
return true;
}

// 处理用户输入
terminal.onData(e => {
if (e === '\r') { // Enter 键
const step = workflow.steps[currentStep];
const input = inputBuffer.trim();
inputBuffer = "";

if (step.options) {
const option = step.options[input];
if (option) {
option.message.forEach(line => terminal.writeln(line));

if (option.nextStep !== null) {
currentStep = option.nextStep - 1;
displayStep(currentStep);
console.log(`Current step: ${currentStep}, Next step: ${step.nextStep}`);
} else {
terminal.writeln("Workflow complete.");
}
} else {
terminal.writeln("\nInvalid option. Try again.");
terminal.write("> ");
}
} else if (step.validate) {
if (validateInput(input, step.validate)) {
terminal.writeln(`\n${step.message}`);

console.log(`Current step: ${currentStep}, Next step: ${step.nextStep}`);

currentStep = step.nextStep - 1;
displayStep(currentStep);
} else {
terminal.writeln("\nInvalid input format. Try again.");
terminal.write("> ");
}
}
} else if (e === '\u007F') { // Backspace 键
if (inputBuffer.length > 0) {
inputBuffer = inputBuffer.slice(0, -1);
terminal.write('\b \b');
}
} else {
inputBuffer += e;
terminal.write(e);
}
});

// 开始工作流
displayStep(currentStep);
});



</script>
</body>
</html>