NandHyf vor 1 Jahr
Ursprung
Commit
605914ec5b
5 geänderte Dateien mit 451 neuen und 0 gelöschten Zeilen
  1. 17 0
      Alt.py
  2. 115 0
      Controller.py
  3. 40 0
      Roadmap.md
  4. 198 0
      Stateful.py
  5. 81 0
      dev.toml

+ 17 - 0
Alt.py

@@ -0,0 +1,17 @@
+# ----- Pre notes
+# err 0: correct config not found
+# err 1: correct DB not found
+# -----
+
+def Err(errCode, lang='en'):
+    errText = ""
+    input("err ", errCode, ": ",  errText)
+    exit()
+
+
+def Warn():
+    pass
+
+
+def sec_response():
+    pass

+ 115 - 0
Controller.py

@@ -0,0 +1,115 @@
+import Alt, Stateful
+import datetime
+
+
+class kbc_config():
+    def __init__(self) -> None:
+        global configs
+        configs = {}
+
+    def get_config():
+        pass
+
+    def get_help():
+        pass
+    
+    def rewrite_config():
+        pass
+
+
+class Client():
+
+    def get_config():
+        # [todo 4]
+        c = ['DBType', 'DBPath', 'lang', 'listStyle', 'displayTimeZone']
+        # rl == 'r'eturn 'l'ist
+        rl = Stateful.MatchTomlKeys("dev.toml", c)
+        
+        global lang, listStyle, dbType, dbPath, displayTimeZone, currentPath
+        dbType = rl[0]
+        dbPath = rl[1]
+        lang = rl[2]
+        listStyle = rl[3]
+        displayTimeZone = rl[4]
+        currentPath = ""
+
+
+    # [todo 4]
+    def get_help():
+        print(Stateful.MatchTomlKey("clean_config.toml", lang, "command-help"))
+
+
+    # [todo 3]
+    def InUTC(timeZone=0):
+        dt_now_UTC0 = str(datetime.datetime.now(datetime.timezone.utc))
+        return(dt_now_UTC0)
+    
+
+    # [todo 2]
+    # 前端只检查输入数量正确, 内容正确统一代回后端检查
+    def InputCheck(inputs):
+        pass
+
+
+    def TransitCommand():
+        # do while or for (1)
+        while(1):
+            app_commands = input(currentPath + "/: ", ).split(" ")
+            # Input exception check
+            
+            # [todo 1]
+            # Client.InputCheck(app_commands)
+            if len(app_commands) < 5:
+                # Add CurrentPath && DBType && Path
+                app_commands.append(currentPath)
+                app_commands.append(dbPath)
+                app_commands.append(dbType)
+
+                Stateful.Handler(app_commands)
+
+            elif len(app_commands) >= 5:
+                print("app_commands >5 error")
+
+
+    # [todo 4]
+    def GenDB():# Stateful里面还有一个一样的方法
+        pass
+        # 1. 先检查是否已经存在DB? y/n?
+        # 2. 连接性检查(是否要切换到新建的DB)y/n?
+
+
+    # [todo 4]
+    def start():
+        # 0. init
+        
+        # 1. get config
+        Client.get_config()
+
+        # 2.
+        startState = Stateful.Handler(['/', dbPath, dbType])
+        print(startState)
+        Client.TransitCommand()
+
+
+class View:
+    def ToDisplayTime(utcTime, TimeZone):
+        displayTime = "displayTime translation not finished"
+        return displayTime
+    
+    def Refresh():
+        pass
+
+
+# For ChatGLM3-6B
+class LLM():
+    def call():
+        pass
+
+    def respond():
+        pass
+
+
+if __name__ == "__main__":
+    # Client.start()
+    Stateful.oc["dt"] = "s"
+    

+ 40 - 0
Roadmap.md

@@ -0,0 +1,40 @@
+[Requirement Backlog](#requirement-backlog)
+
+[Future Versions(Roadmap)](#future-versionsroadmap)
+
+[Released Versions](#released-versions)
+
+# Requirement Backlog
+
+[Backlog]
+
+(list up -> down == requirements old -> new)
+- Action log
+- Redirection Board to `Class.relatedBoard`(if necessary)
+- Records randomly auto-generation(for running tests)
+- Add app command: `cp`
+- Strict Mode off support
+- Template
+- Export to `.csv`
+- Search
+- Loop case support
+- Multiple input(add event EV1 EV2 EV3)
+
+
+
+# Future Versions(Roadmap)
+
+(list up -> down == versions new -> old)
+
+[v0.1.2]
+- Secondary response to some cases
+
+[v0.1.1]
+- Global commands
+
+[v0.1]
+- MVP
+
+# Released Versions
+
+(list up -> down == versions new -> old)

+ 198 - 0
Stateful.py

@@ -0,0 +1,198 @@
+# from Controller import kbc_config
+import Alt
+import tomlkit, sqlite3
+
+
+# ----- Operating Cursor -----
+oc = {
+    "dt":str, 
+    "dp":str,
+
+    "cp":list, 
+    "pp":list,
+
+    "next_move":str,
+
+    "tp":list, 
+    "tp_in":list, 
+    "tp_to":list, 
+    "tp_attr":str
+    }
+# some thoughts:
+# class oc():
+#   def get_oc(), def move_oc()
+
+
+# ----- Toml Methods -----
+def GetTomlDoc(tomlName:str):
+    try:
+        with open(tomlName, "rb") as t:
+            doc = tomlkit.load(t)
+
+            if doc == {}:
+                input("error 0: could not found correct config file") 
+                exit()
+
+            return doc
+        
+    except:
+        input("error 0: could not found correct config file") 
+        exit()
+    
+
+def MatchTomlKey(tomlName:str, key:str, table:str="none") -> str:
+    doc = GetTomlDoc(tomlName)
+
+    if table == "none":
+        return str(doc.item(key))
+    
+    elif table != "none":
+        d = doc.unwrap()
+        return str(d[table][key])
+
+
+# no differernt between ↑ MatchTomlKey() ↑ except receives and returns in list
+def MatchTomlKeys(tomlName:str, keys:list, table:str="none") -> list:
+    doc = GetTomlDoc(tomlName)
+
+    if table == "none":
+        # rl == 'r'eturn 'l'ist
+        rl = []
+
+        for key in keys:
+            try:
+                rl.append(doc.item(key))
+            except:
+                pass
+
+        return rl
+    
+
+    elif table != "none":
+        rl = []
+        d = doc.unwrap()
+
+        for key in keys:
+            try:
+                rl.append(d[table][key])
+            except:
+                pass
+
+        return rl
+    
+
+def MatchTomlTable(tomlName:str, tableName:str, returnType:str="list"):
+    d = GetTomlDoc(tomlName).unwrap()
+
+    if returnType == "list":
+        return list(d.get(tableName).values())
+    
+    elif returnType == "dict":
+        return d
+    
+
+# ----- Sqlite Methods -----
+def Exec_one(dbPath:str, commands:list):
+    con = sqlite3.connect(dbPath)
+    cur = con.cursor()
+
+    cur.execute(commands)
+    con.commit()
+    re = cur.fetchall()
+    cur.close()
+    con.close()
+
+    return re
+
+
+def IsExist(dbPath:str, tableName:str, itemName:str, returnBool:bool=True):
+    # [todo 4] 这里面的.capitalize()后面需要根据config.toml里面的内容判断
+    # 可能也不用, 因为KBCLEV的表名和本身并无关系
+    tableName = tableName.capitalize()
+
+    sqls = "SELECT name FROM {table} WHERE name='{name}'".format(table=tableName, name=itemName)
+    ie = Exec_one(dbPath, sqls)
+
+    if ie != [] and returnBool == False:
+        return ie
+    
+    elif ie != [] and returnBool == True:
+        return True
+
+    elif ie == []:
+        return False
+    
+    else:
+        # Alt.Err(errCode)
+        print("err <Code>: unexpected error in existence check")
+
+
+# ----- Record_main(DB record as a class) -----
+class RM():
+    def __init__(self, type:str="", name:str="", dscrp:str="", creator:str="", relatedBoard:str="", relatedClass:str="", status:int=10) -> None:
+        self.id = "null"
+        self.type = type
+        self.name = name
+        self.dscrp = dscrp
+        self.creator = creator
+        self.createdTime = "datetime('now')"
+        self.relatedBoard = relatedBoard
+        self.relatedClass = relatedClass
+        self.status = status
+
+    
+    def select(self, selectColumn:str="name", aliveOnly:bool=True):
+        if aliveOnly == True:
+            sqls = "SELECT {sc} FROM compact_main WHERE type='{s.type}' AND name='{s.name}' AND realatedBoard='{s.relatedBoard}' AND relatedClass='{s.relatedClass}' AND status={s.status};".format(sc=selectColumn, s=self)
+        elif aliveOnly == False:
+            sqls = "SELECT {sc} FROM compact_main WHERE type='{s.type}' AND name='{s.name}' AND realatedBoard='{s.relatedBoard}' AND relatedClass='{s.relatedClass}';".format(sc=selectColumn, s=self)
+        
+        return sqls
+
+
+    def add(self):
+        sqls = "INSERT INTO compact_main VALUES({a.id}, '{a.type}', '{a.name}', '{a.dscrp}', '{a.creator}', '{a.createdTime}', '{a.relatedBoard}', '{a.relatedClass}', {a.status});".format(a=self)
+
+        return sqls
+
+
+    def delete(self): # 1. withStatus:int=10? 2. withStatement >= or > or <?
+        sqls = "UPDATE compact_main SET status=-10 WHERE type='{d.type}' AND name='{d.name}' AND relatedBoard='{d.relatedBoard}' AND relatedClass='{d.relatedClass}';".format(d=self)
+
+        return sqls
+
+
+    def edit(self):
+        pass
+
+    def move(self):
+        pass
+
+    def back(self):
+        pass
+
+    def export():
+        pass
+
+
+# ----- Record_log_action(DB record as a class) -----
+class RLA():
+    pass
+
+
+def GenModel():
+    # model IE?
+    # over write?
+    # exec
+    pass
+
+
+# ----- Interactions Handler(with other .py) -----
+def Handler():
+    pass
+
+
+if __name__ == "__main__":
+    asd = RM("board", "KB", "", "n.HE", "", "", )
+    print(asd.select())
+    input("hold: ")

+ 81 - 0
dev.toml

@@ -0,0 +1,81 @@
+# ----- App Configuration -----
+StrictMode = true
+
+DBType = "sqlite3"
+DBPath = "dev.db"
+
+Lang = "en"
+ListStyle = "tree"
+DisplayTimeZone = "utc+8"
+
+Start_as_LLM_server = false
+
+
+# ----- DB Configuration -----
+# Just a better reference for dev.db, no functional use(yet)
+[compact_main]
+c1_pk = "id INTEGER PRIMARY KEY ASC"
+c2 = "type"
+c3 = "name"
+c4 = "dscrp"
+c5 = "creator"
+c6 = "createdTime"
+c7 = "relatedBoard"
+c8 = "relatedClass"
+c9 = "status"
+
+[log_action]
+c1_pk = "id INTEGER PRIMARY KEY ASC"
+c2 = "uid" # UNIQUE
+c3 = "commitTime"
+c4 = "type"
+c5 = "commitedAction"
+c6 = "operator"
+c7 = "state"
+
+
+# ----- Some Notes -----
+# compact_main.status:
+#   -10 = deleted
+#    10 = alive
+
+# log_action.state:
+#   -10 = committed failed
+#    10 = successfully committed
+
+# Set integer prime key: <columnName> INTEGER PRIMARY KEY ASC
+# status: alive/deleted/unclassified(event only)
+#                                           ↓ Don't foget to write the method(s) for it
+# ListStyle: tree/md_table/LLM_md_table/<customName>
+
+
+# ----- used sqls -----
+# CREATE TABLE "main" (
+# 	"id"	INTEGER NOT NULL,
+# 	"type"	TEXT NOT NULL,
+# 	"name"	TEXT NOT NULL,
+# 	"dscrp"	TEXT NOT NULL,
+# 	"creator"	TEXT NOT NULL,
+# 	"createdTime"	TEXT NOT NULL,
+# 	"relatedBoard"	TEXT NOT NULL,
+# 	"relatedClass"	TEXT NOT NULL,
+# 	"alive"	INTEGER NOT NULL,
+# 	PRIMARY KEY("id" AUTOINCREMENT)
+# );
+
+# INSERT INTO compact_main VALUES(null, 'class', 'CL1', 'dscrp', 'n.HE', datetime('now'), 'KB1, KB2', '', 'alive');
+
+# SELECT name FROM compact_main WHERE belongBoard like '%KB1%'
+# SELECT name, dscrp FROM compact_main WHERE dscrp like '%KB1%'
+# SELECT name, dscrp FROM compact_main WHERE dscrp like '%_%KB1%'
+
+# INSERT INTO compact_main VALUES(null, 'class', 'CL2', '_usingBoard:KB1, KB2', 'n.HE', datetime('now'), '', '', 'alive');
+# UPDATE main SET relatedBoard='KB1, KB2' WHERE type='class' AND name='CL2'
+# SELECT name FROM main WHERE type='class' AND relatedBoard like '%KB2%'
+
+# delete class 3 combo:
+# UPDATE compact_main SET relatedBoard = replace(relatedBoard, 'KB2, ', '')  WHERE type='class' AND relatedBoard like '%KB2, %';
+# UPDATE compact_main SET relatedBoard = replace(relatedBoard, ', KB2', '')  WHERE type='class' AND relatedBoard like '%, KB2%';
+# UPDATE compact_main SET relatedBoard = replace(relatedBoard, 'KB2', '')  WHERE type='class' AND relatedBoard like '%KB2%';
+
+# Explanation of abbreviations