Files
hsa/Html/backboardManager.py
2024-12-28 17:11:24 +08:00

75 lines
2.4 KiB
Python

import time
class BackBoardManager:
def __init__(self):
self.backboards = {} # user_id: Backboard
def add_backboard(self, user_id, folder):
self.backboards[user_id] = Backboard(user_id, folder)
def get_backboard(self, user_id):
if user_id not in self.backboards:
return None
return self.backboards[user_id]
class Backboard:
def __init__(self, user_id, folder):
self.user_id = user_id
self.folder = folder
self.create_time = time.time()
self.enter_chapter_time = time.time()
self.history = []
self.file_tree = "[]"
self.active_file_path = ""
self.active_file_content = ""
self.pasted_file_path = ""
self.pasted_content = ""
def next_chapter(self):
self.enter_chapter_time = time.time()
def get_info_prompt(self):
five_history = ""
for h in self.history[-5:]:
five_history += h['type'] + "\n" + h.get('filePath', '') + "\n\n"
endl = "\n"
return (f"###Global Info:###{endl}"
f"Here are some info about now user's IDE, refer to it when you need to handle some code.{endl}"
f"- User's total study time is {self.get_deltatime_mmss(self.create_time, time.time())}{endl}"
f"- User's current chapter study time is {self.get_deltatime_mmss(self.enter_chapter_time, time.time())}{endl}"
f"- Activated file path: {self.active_file_path}{endl}"
f"- Activated file content (current editing 10 lines): {endl}"
f"```{endl}"
f"{self.active_file_content[-10:]}{endl}"
f"```{endl}"
f"- Last five action:{five_history}{endl}"
f"- File tree: {self.file_tree}{endl}")
def add_history(self, realtime_action):
if(realtime_action['type']=='config'):return
if len(self.history)!=0:
if (self.history[-1]['type']=='fileEdit'):
if(self.history[-1]['filePath'] == realtime_action['filePath']):
self.history[-1]['content'] = realtime_action['content']
return
self.history.append(realtime_action)
def get_deltatime_mmss(self, start_time, end_time):
elapsed_time = end_time - start_time
hours = int(elapsed_time // 3600)
minutes = int((elapsed_time % 3600) // 60)
seconds = int(elapsed_time % 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"