sample-ui-component-library 0.0.57-dev → 0.0.58-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sample-ui-component-library",
3
- "version": "0.0.57-dev",
3
+ "version": "0.0.58-dev",
4
4
  "description": "A library which contains sample UI elements that can be used for populating layouts.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -35,7 +35,6 @@ export const Editor = forwardRef(({ onSelectAbstraction, onSelectTab, onUpdateCo
35
35
 
36
36
  useEffect(() => {
37
37
  if (onSelectTab) {
38
- console.log(state.activeTab);
39
38
  onSelectTab(state.activeTab);
40
39
  }
41
40
  }, [state.activeTab]);
@@ -4,7 +4,7 @@ export const initialState = {
4
4
  uid: crypto.randomUUID(),
5
5
  tabs: [],
6
6
  activeTab: null,
7
- mode: EDITOR_MODES.DESIGN,
7
+ mode: EDITOR_MODES.MAPPING,
8
8
  mapping: new Map(),
9
9
  parentTabGroupId: null,
10
10
  mappedIds: [],
@@ -22,6 +22,8 @@ export const MonacoInstance = forwardRef(({ onSelectAbstraction }, ref) => {
22
22
  const { state, setUpdatedContent } = useEditor();
23
23
  const [showEditor, setShowEditor] = useState(false);
24
24
  const activeTabRef = useRef(state.activeTab);
25
+
26
+ const [overlayDivs, setOverlayDivs] = useState();
25
27
 
26
28
  const editorRef = useRef(null);
27
29
  const modelsRef = useRef(new Map());
@@ -31,6 +33,7 @@ export const MonacoInstance = forwardRef(({ onSelectAbstraction }, ref) => {
31
33
  if (state.activeTab) {
32
34
  activeTabRef.current = state.activeTab;
33
35
  editorRef.current && editorRef.current.setModel(getModel(state.activeTab));
36
+ updateOverlays();
34
37
  setShowEditor(true);
35
38
  } else {
36
39
  activeTabRef.current = null;
@@ -38,6 +41,42 @@ export const MonacoInstance = forwardRef(({ onSelectAbstraction }, ref) => {
38
41
  }
39
42
  }, [state.activeTab, editorRef]);
40
43
 
44
+ // Update overlays for mapping mode.
45
+ const updateOverlays = useCallback(() => {
46
+ if (state.mode !== EDITOR_MODES.MAPPING) return;
47
+ if (!editorRef.current || !activeTabRef?.current?.mapping) return;
48
+
49
+ const mapping = activeTabRef.current.mapping;
50
+ const lineCount = editorRef.current.getModel().getLineCount();
51
+ const lineHeight = editorRef.current.getOption(monaco.editor.EditorOption.lineHeight);
52
+ const divs = [];
53
+
54
+ mapping.forEach((entry) => {
55
+ const top = editorRef.current.getTopForLineNumber(entry.start_line) - editorRef.current.getScrollTop();
56
+ let bottom = editorRef.current.getTopForLineNumber(entry.end_line + 1) - editorRef.current.getScrollTop();
57
+ if (entry.end_line >= lineCount) {
58
+ bottom = bottom + lineHeight;
59
+ }
60
+
61
+ const style= {};
62
+ style["top"] = top + "px";
63
+ style["height"] = (bottom - top) + "px";
64
+
65
+ divs.push(<div className="line-block-overlay" onClick={(e) => onSelectAbstraction(entry)} style={style}></div>);
66
+ });
67
+ setOverlayDivs(divs);
68
+ }, [editorRef, state.activeTab]);
69
+
70
+ // Scroll the editor and update overlays on wheel event in mapping mode.
71
+ const handleWheel = useCallback((e) => {
72
+ if (!editorRef.current) return;
73
+ const deltaY = e.deltaY;
74
+ const currentScrollTop = editorRef.current.getScrollTop();
75
+ editorRef.current.setScrollTop(currentScrollTop + deltaY);
76
+ updateOverlays();
77
+ }, [state.activeTab, updateOverlays]);
78
+
79
+
41
80
  useEffect(() => {
42
81
  return () => {
43
82
  // Dispose all models on unmount to prevent memory leaks.
@@ -55,7 +55,7 @@ const Template = (args) => {
55
55
 
56
56
  useLayoutEffect(() => {
57
57
  editorRef.current.setTabGroupId("tab-group-1");
58
- flattenTree(WorkspaceSampleTree.tree).slice(1,5).forEach((node, index) => {
58
+ WorkspaceSampleTree.forEach((node, index) => {
59
59
  if (node.type === "file") {
60
60
  editorRef.current.addTab(node);
61
61
  }
@@ -143,11 +143,9 @@ const Template = (args) => {
143
143
 
144
144
  const onSelectTool = useCallback((tool) => {
145
145
  if (tool === "mapping-mode") {
146
- editorRef.current.addTab(
147
- flattenTree(WorkspaceSampleTree.tree).slice(2,2)
148
- );
149
- } else if (tool === "implementation-mode") {
150
- editorRef.current.saveAll();
146
+ editorRef.current.setMode(EDITOR_MODES.MAPPING);
147
+ } else if (tool === "implementation-mode") {
148
+ editorRef.current.setMode(EDITOR_MODES.DESIGN);
151
149
  }
152
150
  }, [editorRef]);
153
151
 
@@ -1,66 +1 @@
1
- {
2
- "tree": [
3
- {
4
- "name": "library_manager_single_threaded",
5
- "type": "folder",
6
- "uid": "dir-ba56de84-31dd-4ccf-ae98-a98b0581f803",
7
- "children": [
8
- {
9
- "name": "library_manager.py",
10
- "type": "file",
11
- "uid": "dir-3d7aaf8e-6224-4eb7-8301-936447fef430",
12
- "content": "import sys\n\ndef place_book_on_shelf(book_shelf, name, genre):\n '''\n This function places the given book on the shelf \n in a slot determined by the first letter of its name.\n \n :param book_shelf: Bookshelf to place the book on.\n :param name: Name of the book.\n :param genre: Genre of the book.\n '''\n print(f\"Accepted book: {name} (Genre: {genre})\")\n \n firstLetter = name[0].upper()\n\n if (firstLetter not in book_shelf):\n book_shelf[firstLetter] = []\n else:\n print(\"Slot for book already exists.\")\n\n book_shelf[firstLetter].append(name)\n\n return book_shelf\n\ndef accept_book():\n '''\n Accepts a book and genre from the user and returns it.\n '''\n print(\"\\nEnter book details:\")\n \n name = input(\"Book name: \")\n\n genre = input(\"Genre: \")\n\n return {\"name\":name, \"genre\":genre}\n\n\ndef library_manager():\n '''\n Runs the library manager to accept books until the user decides to stop.\n '''\n book_shelf = {}\n\n while True:\n book_details = accept_book()\n book_shelf = place_book_on_shelf(\n book_shelf, \n book_details[\"name\"], \n book_details[\"genre\"]\n )\n\n more = input(\"Add another book? (y): \").lower()\n \n if more != \"y\":\n break\n\n print(\"Exiting library manager, goodbye.\")\n\nif __name__ == \"__main__\":\n sys.exit(library_manager())\n "
13
- },
14
- {
15
- "name": "readme",
16
- "type": "file",
17
- "uid": "dir-5aa507ee-e43d-4d77-b49a-b6e0b1da36f5",
18
- "content": "This is version 1 of the library manager and it contains a simple implementation that accepts a book name and genre before placing it on the shelf. It places it on the shelf using the first letter of the book name. It continues to accept books until the user decides to stop.\n\nThis version of the library manager will also use instrumentation to identify abstractions by line to overcome the limitations of existing techniques."
19
- }
20
- ]
21
- },
22
- {
23
- "name": "text_translator",
24
- "type": "folder",
25
- "uid": "dir-cbb97582-e3da-403e-aa7f-a524a5a7cff7",
26
- "children": [
27
- {
28
- "name": "FrenchTranslator.py",
29
- "type": "file",
30
- "uid": "dir-516008b2-e80c-4a3a-bb00-d651885ac15d",
31
- "content": "import threading\nimport queue\nfrom deep_translator import GoogleTranslator # type: ignore\n\nclass FrenchTranslator(threading.Thread):\n def __init__(self, id, queue, packerQueue):\n super().__init__(daemon=True)\n self.queue = queue\n self.id = id\n self.packerQueue = packerQueue\n self.start()\n\n def run(self):\n while True:\n try:\n job = self.queue.get(timeout=10)\n except queue.Empty:\n continue\n\n translatedMsg = GoogleTranslator(source=\"auto\", target=\"french\").translate(job[\"value\"][\"data\"])\n self.packerQueue.put({\n \"uid\": job[\"uid\"],\n \"value\": {\n \"language\": \"french\",\n \"original\": job[\"value\"][\"data\"],\n \"translated\": translatedMsg\n }\n })"
32
- },
33
- {
34
- "name": "Packer.py",
35
- "type": "file",
36
- "uid": "dir-e5085241-ff4f-434d-85ab-7f50e673ea4d",
37
- "content": "import threading\nimport queue\nfrom TransactionDB import TransactionDB\n\nclass PackerThread(threading.Thread):\n def __init__(self, queue):\n super().__init__(daemon=True)\n self.queue = queue\n self.items = {}\n self.start()\n\n def run(self):\n self.db = TransactionDB()\n while True:\n try:\n translatedJobPart = self.queue.get(timeout=10)\n except queue.Empty:\n continue\n\n self.db.addTranslation(translatedJobPart)\n\n if self.db.isDone(translatedJobPart[\"uid\"]):\n self.db.setDone(translatedJobPart[\"uid\"])"
38
- },
39
- {
40
- "name": "SpanishTranslator.py",
41
- "type": "file",
42
- "uid": "dir-b2a78dfd-aa94-4068-a5f7-24c396d88825",
43
- "content": "import threading\nimport queue\nfrom deep_translator import GoogleTranslator # type: ignore\n\nclass SpanishTranslator(threading.Thread):\n def __init__(self, id, queue, packerQueue):\n super().__init__(daemon=True)\n self.queue = queue\n self.id = id\n self.packerQueue = packerQueue\n self.start()\n\n def run(self):\n while True:\n try:\n job = self.queue.get(timeout=10)\n except queue.Empty:\n continue\n\n translatedMsg = GoogleTranslator(source=\"auto\", target=\"spanish\").translate(job[\"value\"][\"data\"])\n self.packerQueue.put({\n \"uid\": job[\"uid\"],\n \"value\": {\n \"language\": \"spanish\",\n \"original\": job[\"value\"][\"data\"],\n \"translated\": translatedMsg\n }\n })"
44
- },
45
- {
46
- "name": "TamilTranslator.py",
47
- "type": "file",
48
- "uid": "dir-594ff411-b916-4a88-9077-3d5b8ff7f871",
49
- "content": "import threading\nimport queue\nfrom deep_translator import GoogleTranslator # type: ignore\n\nclass TamilTranslator(threading.Thread):\n def __init__(self, id, queue, packerQueue):\n super().__init__(daemon=True)\n self.queue = queue\n self.id = id\n self.packerQueue = packerQueue\n self.start()\n\n def run(self):\n while True:\n try:\n job = self.queue.get(timeout=10)\n except queue.Empty:\n continue\n\n translatedMsg = GoogleTranslator(source=\"auto\", target=\"tamil\").translate(job[\"value\"][\"data\"])\n self.packerQueue.put({\n \"uid\": job[\"uid\"],\n \"value\": {\n \"language\": \"tamil\",\n \"original\": job[\"value\"][\"data\"],\n \"translated\": translatedMsg\n }\n })"
50
- },
51
- {
52
- "name": "readme",
53
- "type": "file",
54
- "uid": "dir-f6459410-1634-4dbc-8d76-35896822158d",
55
- "content": "This folder contains a text translator that uses three workers to translate the text and uses a packer to add the results to a cabinet."
56
- },
57
- {
58
- "name": "TransactionDB.py",
59
- "type": "file",
60
- "uid": "dir-f6459410-1634-4dbc-8d76-35sfdvsd6822158d",
61
- "content": "import sqlite3\nimport atexit\nimport uuid\n\nclass TransactionDB():\n\n def __init__(self):\n atexit.register(self.cleanup_function)\n self.initializeDB()\n\n def cleanup_function(self):\n self.conn.close()\n\n def initializeDB(self):\n\n self.conn = sqlite3.connect(\"translations.db\")\n self.cursor = self.conn.cursor()\n\n self.cursor.execute(\"\"\"\n CREATE TABLE IF NOT EXISTS translation_jobs (\n job_id INTEGER PRIMARY KEY AUTOINCREMENT,\n uid TEXT NOT NULL UNIQUE,\n english TEXT NOT NULL,\n french TEXT,\n spanish TEXT,\n tamil TEXT,\n done INTEGER NOT NULL DEFAULT 0\n );\n \"\"\")\n self.conn.commit()\n\n def addJob(self, data):\n uid = str(uuid.uuid4())\n self.conn.execute(\n \"\"\"\n INSERT INTO translation_jobs (uid, english)\n VALUES (?, ?)\n \"\"\",\n (uid, data)\n )\n self.conn.commit()\n\n return {\n \"uid\": uid,\n \"value\": {\"data\": data}\n }\n \n def addTranslation(self, msg):\n self.conn.execute(\n f\"\"\"\n UPDATE translation_jobs\n SET {msg[\"value\"][\"language\"]} = ?\n WHERE uid = ?\n \"\"\",\n (msg[\"value\"][\"translated\"], msg[\"uid\"])\n )\n self.conn.commit()\n\n\n def isDone(self, uid):\n cur = self.conn.execute(\n \"\"\"\n SELECT\n french IS NOT NULL\n AND spanish IS NOT NULL\n AND tamil IS NOT NULL\n FROM translation_jobs\n WHERE uid = ?\n \"\"\",\n (uid,)\n )\n row = cur.fetchone()\n return bool(row[0]) if row else False\n \n def setDone(self, uid):\n self.conn.execute(\n \"\"\"\n UPDATE translation_jobs\n SET done = 1\n WHERE uid = ?\n \"\"\",\n (uid,)\n )\n self.conn.commit()\n\n\n "
62
- }
63
- ]
64
- }
65
- ]
66
- }
1
+ [{"name":"library_manager.py","path":"library_manager.py","content":"import sys\r\nimport uuid\r\nimport json\r\n\r\ndef place_books_on_shelf_from_basket(book_shelf, basket):\r\n '''\r\n This function checks to see if there are books in the\r\n basket and places it on the shelf. It continues until\r\n there are no more books left.\r\n \r\n :param book_shelf: Object representing the bookshelf.\r\n :param basket: Array representing the basket.\r\n '''\r\n while len(basket[\"value\"]) > 0:\r\n book = basket[\"value\"].pop()\r\n print(f\"Accepted book: {book['value']['name']} (Genre: {book['value']['genre']})\")\r\n \r\n firstLetter = book[\"value\"]['name'][0]\r\n\r\n if (firstLetter not in book_shelf[\"value\"]):\r\n book_shelf[\"value\"][firstLetter] = []\r\n\r\n book_shelf[\"value\"][firstLetter].append(book)\r\n\r\n return book_shelf\r\n\r\ndef accept_book():\r\n '''\r\n This function accepts the book from the user.\r\n '''\r\n print(\"\\nEnter book details:\") \r\n name = input(\"Book name: \")\r\n genre = input(\"Genre: \")\r\n book_details = {\"uid\": str(uuid.uuid4()), \"value\": {\"name\": name, \"genre\":genre}}\r\n return book_details\r\n\r\ndef library_manager():\r\n '''\r\n This function serves the library manager. \r\n\r\n It provides a menu that lets users add books to a basket and \r\n place the books from the basket onto the shelf. It also allows\r\n the user to display the contents of the library and finally, it\r\n allows the user to exit the library.\r\n '''\r\n\r\n book_shelf = {\"uid\": str(uuid.uuid4()), \"value\":{}}\r\n\r\n basket = {\"uid\": str(uuid.uuid4()), \"value\":[]}\r\n\r\n while True:\r\n \r\n response = input(\r\n \"\\n==========================\\n\"\\\r\n \" Menu:\\n\" \\\r\n \"==========================\\n\"\\\r\n \"Enter a: Add book.\\n\" \\\r\n \"Enter p: Place books on shelf and continue.\\n\" \\\r\n \"Enter d: Display contents of basket and book shelf.\\n\" \\\r\n \"Enter any other key: Exit\\n\" \\\r\n \"\\nResponse:\"\r\n ).lower()\r\n\r\n if response == \"a\":\r\n book_details = accept_book()\r\n basket[\"value\"].append(book_details)\r\n\r\n elif response == \"p\":\r\n if (len(basket) > 5):\r\n raise Exception(\"Basket is too heavy, I can't bring it to the shelf.\")\r\n book_shelf = place_books_on_shelf_from_basket(book_shelf, basket)\r\n\r\n elif response == \"d\":\r\n audit = {\"uid\": str(uuid.uuid4()), \"value\":{\"Book Shelf\": book_shelf, \"Basket\": basket}}\r\n print(\"\\nLibrary Audit:\", json.dumps(audit[\"value\"], indent=2))\r\n\r\n else: \r\n break\r\n\r\nif __name__ == \"__main__\":\r\n sys.exit(library_manager())\r\n ","updatedContent":"import sys\r\nimport uuid\r\nimport json\r\n\r\ndef place_books_on_shelf_from_basket(book_shelf, basket):\r\n '''\r\n This function checks to see if there are books in the\r\n basket and places it on the shelf. It continues until\r\n there are no more books left.\r\n \r\n :param book_shelf: Object representing the bookshelf.\r\n :param basket: Array representing the basket.\r\n '''\r\n while len(basket[\"value\"]) > 0:\r\n book = basket[\"value\"].pop()\r\n print(f\"Accepted book: {book['value']['name']} (Genre: {book['value']['genre']})\")\r\n \r\n firstLetter = book[\"value\"]['name'][0]\r\n\r\n if (firstLetter not in book_shelf[\"value\"]):\r\n book_shelf[\"value\"][firstLetter] = []\r\n\r\n book_shelf[\"value\"][firstLetter].append(book)\r\n\r\n return book_shelf\r\n\r\ndef accept_book():\r\n '''\r\n This function accepts the book from the user.\r\n '''\r\n print(\"\\nEnter book details:\") \r\n name = input(\"Book name: \")\r\n genre = input(\"Genre: \")\r\n book_details = {\"uid\": str(uuid.uuid4()), \"value\": {\"name\": name, \"genre\":genre}}\r\n return book_details\r\n\r\ndef library_manager():\r\n '''\r\n This function serves the library manager. \r\n\r\n It provides a menu that lets users add books to a basket and \r\n place the books from the basket onto the shelf. It also allows\r\n the user to display the contents of the library and finally, it\r\n allows the user to exit the library.\r\n '''\r\n\r\n book_shelf = {\"uid\": str(uuid.uuid4()), \"value\":{}}\r\n\r\n basket = {\"uid\": str(uuid.uuid4()), \"value\":[]}\r\n\r\n while True:\r\n \r\n response = input(\r\n \"\\n==========================\\n\"\\\r\n \" Menu:\\n\" \\\r\n \"==========================\\n\"\\\r\n \"Enter a: Add book.\\n\" \\\r\n \"Enter p: Place books on shelf and continue.\\n\" \\\r\n \"Enter d: Display contents of basket and book shelf.\\n\" \\\r\n \"Enter any other key: Exit\\n\" \\\r\n \"\\nResponse:\"\r\n ).lower()\r\n\r\n if response == \"a\":\r\n book_details = accept_book()\r\n basket[\"value\"].append(book_details)\r\n\r\n elif response == \"p\":\r\n if (len(basket) > 5):\r\n raise Exception(\"Basket is too heavy, I can't bring it to the shelf.\")\r\n book_shelf = place_books_on_shelf_from_basket(book_shelf, basket)\r\n\r\n elif response == \"d\":\r\n audit = {\"uid\": str(uuid.uuid4()), \"value\":{\"Book Shelf\": book_shelf, \"Basket\": basket}}\r\n print(\"\\nLibrary Audit:\", json.dumps(audit[\"value\"], indent=2))\r\n\r\n else: \r\n break\r\n\r\nif __name__ == \"__main__\":\r\n sys.exit(library_manager())\r\n ","type":"file","uid":"9f7368cb-7972-4516-8f60-3f7b75f575c3","level":0,"collapsed":false,"isDirty":false,"mapping":[{"type":"Import","source_path":null,"uid":"b308ce7a-8b78-4f84-a7df-97fc150167e8","start_line":1,"end_line":1,"source":"import sys"},{"type":"Import","source_path":null,"uid":"ec8a3226-785d-44ac-ae07-b688f158aa58","start_line":2,"end_line":2,"source":"import uuid"},{"type":"Import","source_path":null,"uid":"0c1e1aef-b698-4396-bfc6-fdd57f186797","start_line":3,"end_line":3,"source":"import json"},{"type":"Expr","source_path":null,"uid":"35d89687-bf11-4b0c-8597-b92b3af5c316","start_line":6,"end_line":13,"source":"'''\r\n This function checks to see if there are books in the\r\n basket and places it on the shelf. It continues until\r\n there are no more books left.\r\n \r\n :param book_shelf: Object representing the bookshelf.\r\n :param basket: Array representing the basket.\r\n '''"},{"type":"While","source_path":null,"uid":"b7222c08-4d4b-40d2-b7da-3333086bc1a5","start_line":14,"end_line":14,"source":[" while len(basket[\"value\"]) > 0:"]},{"type":"Assign","source_path":null,"uid":"3059ee92-68a6-4696-ade6-a7491d363654","start_line":15,"end_line":15,"source":"book = basket[\"value\"].pop()"},{"type":"Expr","source_path":null,"uid":"08059761-6bd4-4e05-b737-be5469892978","start_line":16,"end_line":16,"source":"print(f\"Accepted book: {book['value']['name']} (Genre: {book['value']['genre']})\")"},{"type":"Assign","source_path":null,"uid":"f303481d-2a2b-45b1-aebc-bbd23168c3aa","start_line":18,"end_line":18,"source":"firstLetter = book[\"value\"]['name'][0]"},{"type":"If","source_path":null,"uid":"7b15a438-1601-4cd7-a4a6-b364a587aa7e","start_line":20,"end_line":20,"source":[" if (firstLetter not in book_shelf[\"value\"]):"]},{"type":"Assign","source_path":null,"uid":"8f60ac1a-c220-4140-bea1-0426aca1cfab","start_line":21,"end_line":21,"source":"book_shelf[\"value\"][firstLetter] = []"},{"type":"Expr","source_path":null,"uid":"9edb7b1b-efda-41f4-bb63-dc8aa1d1fa1d","start_line":23,"end_line":23,"source":"book_shelf[\"value\"][firstLetter].append(book)"},{"type":"Return","source_path":null,"uid":"3f9a5d2a-3aa4-4984-8dcc-190121bb73a8","start_line":25,"end_line":25,"source":"return book_shelf"},{"type":"Expr","source_path":null,"uid":"ca556739-e968-49f5-a36c-e10a06ebc617","start_line":28,"end_line":30,"source":"'''\r\n This function accepts the book from the user.\r\n '''"},{"type":"Expr","source_path":null,"uid":"f91e1c8b-e34f-46c3-925e-1e5b4a8fa95b","start_line":31,"end_line":31,"source":"print(\"\\nEnter book details:\")"},{"type":"Assign","source_path":null,"uid":"5e5f568d-bc06-47b5-b3e8-d1cfde0afe93","start_line":32,"end_line":32,"source":"name = input(\"Book name: \")"},{"type":"Assign","source_path":null,"uid":"649e0c60-a132-4c6b-9d72-ac290a5041c9","start_line":33,"end_line":33,"source":"genre = input(\"Genre: \")"},{"type":"Assign","source_path":null,"uid":"af6c7457-516c-4d39-8813-d744b1223515","start_line":34,"end_line":34,"source":"book_details = {\"uid\": str(uuid.uuid4()), \"value\": {\"name\": name, \"genre\":genre}}"},{"type":"Return","source_path":null,"uid":"0623dcb5-296e-45c0-b1fa-0818ecc94c62","start_line":35,"end_line":35,"source":"return book_details"},{"type":"Expr","source_path":null,"uid":"968e3d32-232d-450c-88ce-eb1d4b97ae64","start_line":38,"end_line":45,"source":"'''\r\n This function serves the library manager. \r\n\r\n It provides a menu that lets users add books to a basket and \r\n place the books from the basket onto the shelf. It also allows\r\n the user to display the contents of the library and finally, it\r\n allows the user to exit the library.\r\n '''"},{"type":"Assign","source_path":null,"uid":"e72691b6-e418-44af-8924-26b856f4996d","start_line":47,"end_line":47,"source":"book_shelf = {\"uid\": str(uuid.uuid4()), \"value\":{}}"},{"type":"Assign","source_path":null,"uid":"8a95a24c-62d7-47ee-b3ec-7886f6e7db37","start_line":49,"end_line":49,"source":"basket = {\"uid\": str(uuid.uuid4()), \"value\":[]}"},{"type":"While","source_path":null,"uid":"71544ac9-3c6c-45f5-9a53-d1abd3e47d84","start_line":51,"end_line":51,"source":[" while True:"]},{"type":"Assign","source_path":null,"uid":"90d619ec-708d-4ada-8d62-c70e03fa755b","start_line":53,"end_line":62,"source":"response = input(\r\n \"\\n==========================\\n\"\\\r\n \" Menu:\\n\" \\\r\n \"==========================\\n\"\\\r\n \"Enter a: Add book.\\n\" \\\r\n \"Enter p: Place books on shelf and continue.\\n\" \\\r\n \"Enter d: Display contents of basket and book shelf.\\n\" \\\r\n \"Enter any other key: Exit\\n\" \\\r\n \"\\nResponse:\"\r\n ).lower()"},{"type":"If","source_path":null,"uid":"2aa8eb4c-fdf8-4674-acac-281759d42509","start_line":64,"end_line":64,"source":[" if response == \"a\":"]},{"type":"Assign","source_path":null,"uid":"6fd18da6-4edd-4956-92aa-5ee50a970377","start_line":65,"end_line":65,"source":"book_details = accept_book()"},{"type":"Expr","source_path":null,"uid":"d0b0a744-5ac1-4f64-ae75-b2af0f468d1f","start_line":66,"end_line":66,"source":"basket[\"value\"].append(book_details)"},{"type":"If","source_path":null,"uid":"4a1d0ef6-3b30-4177-b556-e72c28dacbb8","start_line":68,"end_line":68,"source":[" elif response == \"p\":"]},{"type":"If","source_path":null,"uid":"a7c808f7-e44d-465f-b2df-415e19862a18","start_line":69,"end_line":69,"source":[" if (len(basket) > 5):"]},{"type":"Raise","source_path":null,"uid":"3579c14b-016c-4f9d-9ed7-f474f450e2f3","start_line":70,"end_line":70,"source":"raise Exception(\"Basket is too heavy, I can't bring it to the shelf.\")"},{"type":"Assign","source_path":null,"uid":"915ae10a-aab9-4003-9dbc-45772015b366","start_line":71,"end_line":71,"source":"book_shelf = place_books_on_shelf_from_basket(book_shelf, basket)"},{"type":"If","source_path":null,"uid":"f8690f15-63a4-4839-ae67-369f01ff7f83","start_line":73,"end_line":73,"source":[" elif response == \"d\":"]},{"type":"Assign","source_path":null,"uid":"15bc2199-2234-47e1-a8a0-84e16728aa1e","start_line":74,"end_line":74,"source":"audit = {\"uid\": str(uuid.uuid4()), \"value\":{\"Book Shelf\": book_shelf, \"Basket\": basket}}"},{"type":"Expr","source_path":null,"uid":"f9fff770-f748-407e-99ac-e94246a9d4d3","start_line":75,"end_line":75,"source":"print(\"\\nLibrary Audit:\", json.dumps(audit[\"value\"], indent=2))"},{"type":"Break","source_path":null,"uid":"c8123785-c38f-4085-858f-18ec19a09f75","start_line":78,"end_line":78,"source":"break"},{"type":"If","source_path":null,"uid":"75bef5bd-c735-4d91-9fbb-3021089ac938","start_line":80,"end_line":80,"source":["if __name__ == \"__main__\":"]},{"type":"Expr","source_path":null,"uid":"b12c3697-642d-46aa-902e-8c0a563eefa3","start_line":81,"end_line":81,"source":"sys.exit(library_manager())"}]},{"name":"README.md","path":"README.md","content":"- The files in the workspace are loaded from the implementation contained in the engine. \r\n\r\n- The implementation realizes the design contained in the engines graphs. \r\n\r\n- Anytime that the implementation is saved, the program will be parsed to extract the mappable statements, allowing the design to be mapped onto the implementation in the workbench.\r\n\r\n- The mapping will be instrumented onto the implementation, executed and the resulting trace will be transformed back into the behavior of the design, allowing it to be automatically debugged.","updatedContent":"- The files in the workspace are loaded from the implementation contained in the engine. \r\n\r\n- The implementation realizes the design contained in the engines graphs. \r\n\r\n- Anytime that the implementation is saved, the program will be parsed to extract the mappable statements, allowing the design to be mapped onto the implementation in the workbench.\r\n\r\n- The mapping will be instrumented onto the implementation, executed and the resulting trace will be transformed back into the behavior of the design, allowing it to be automatically debugged.","type":"file","uid":"2c5385dd-7c17-4216-b564-47c941e9a623","level":0,"collapsed":false,"isDirty":true}]
@@ -0,0 +1,66 @@
1
+ {
2
+ "tree": [
3
+ {
4
+ "name": "library_manager_single_threaded",
5
+ "type": "folder",
6
+ "uid": "dir-ba56de84-31dd-4ccf-ae98-a98b0581f803",
7
+ "children": [
8
+ {
9
+ "name": "library_manager.py",
10
+ "type": "file",
11
+ "uid": "dir-3d7aaf8e-6224-4eb7-8301-936447fef430",
12
+ "content": "import sys\n\ndef place_book_on_shelf(book_shelf, name, genre):\n '''\n This function places the given book on the shelf \n in a slot determined by the first letter of its name.\n \n :param book_shelf: Bookshelf to place the book on.\n :param name: Name of the book.\n :param genre: Genre of the book.\n '''\n print(f\"Accepted book: {name} (Genre: {genre})\")\n \n firstLetter = name[0].upper()\n\n if (firstLetter not in book_shelf):\n book_shelf[firstLetter] = []\n else:\n print(\"Slot for book already exists.\")\n\n book_shelf[firstLetter].append(name)\n\n return book_shelf\n\ndef accept_book():\n '''\n Accepts a book and genre from the user and returns it.\n '''\n print(\"\\nEnter book details:\")\n \n name = input(\"Book name: \")\n\n genre = input(\"Genre: \")\n\n return {\"name\":name, \"genre\":genre}\n\n\ndef library_manager():\n '''\n Runs the library manager to accept books until the user decides to stop.\n '''\n book_shelf = {}\n\n while True:\n book_details = accept_book()\n book_shelf = place_book_on_shelf(\n book_shelf, \n book_details[\"name\"], \n book_details[\"genre\"]\n )\n\n more = input(\"Add another book? (y): \").lower()\n \n if more != \"y\":\n break\n\n print(\"Exiting library manager, goodbye.\")\n\nif __name__ == \"__main__\":\n sys.exit(library_manager())\n "
13
+ },
14
+ {
15
+ "name": "readme",
16
+ "type": "file",
17
+ "uid": "dir-5aa507ee-e43d-4d77-b49a-b6e0b1da36f5",
18
+ "content": "This is version 1 of the library manager and it contains a simple implementation that accepts a book name and genre before placing it on the shelf. It places it on the shelf using the first letter of the book name. It continues to accept books until the user decides to stop.\n\nThis version of the library manager will also use instrumentation to identify abstractions by line to overcome the limitations of existing techniques."
19
+ }
20
+ ]
21
+ },
22
+ {
23
+ "name": "text_translator",
24
+ "type": "folder",
25
+ "uid": "dir-cbb97582-e3da-403e-aa7f-a524a5a7cff7",
26
+ "children": [
27
+ {
28
+ "name": "FrenchTranslator.py",
29
+ "type": "file",
30
+ "uid": "dir-516008b2-e80c-4a3a-bb00-d651885ac15d",
31
+ "content": "import threading\nimport queue\nfrom deep_translator import GoogleTranslator # type: ignore\n\nclass FrenchTranslator(threading.Thread):\n def __init__(self, id, queue, packerQueue):\n super().__init__(daemon=True)\n self.queue = queue\n self.id = id\n self.packerQueue = packerQueue\n self.start()\n\n def run(self):\n while True:\n try:\n job = self.queue.get(timeout=10)\n except queue.Empty:\n continue\n\n translatedMsg = GoogleTranslator(source=\"auto\", target=\"french\").translate(job[\"value\"][\"data\"])\n self.packerQueue.put({\n \"uid\": job[\"uid\"],\n \"value\": {\n \"language\": \"french\",\n \"original\": job[\"value\"][\"data\"],\n \"translated\": translatedMsg\n }\n })"
32
+ },
33
+ {
34
+ "name": "Packer.py",
35
+ "type": "file",
36
+ "uid": "dir-e5085241-ff4f-434d-85ab-7f50e673ea4d",
37
+ "content": "import threading\nimport queue\nfrom TransactionDB import TransactionDB\n\nclass PackerThread(threading.Thread):\n def __init__(self, queue):\n super().__init__(daemon=True)\n self.queue = queue\n self.items = {}\n self.start()\n\n def run(self):\n self.db = TransactionDB()\n while True:\n try:\n translatedJobPart = self.queue.get(timeout=10)\n except queue.Empty:\n continue\n\n self.db.addTranslation(translatedJobPart)\n\n if self.db.isDone(translatedJobPart[\"uid\"]):\n self.db.setDone(translatedJobPart[\"uid\"])"
38
+ },
39
+ {
40
+ "name": "SpanishTranslator.py",
41
+ "type": "file",
42
+ "uid": "dir-b2a78dfd-aa94-4068-a5f7-24c396d88825",
43
+ "content": "import threading\nimport queue\nfrom deep_translator import GoogleTranslator # type: ignore\n\nclass SpanishTranslator(threading.Thread):\n def __init__(self, id, queue, packerQueue):\n super().__init__(daemon=True)\n self.queue = queue\n self.id = id\n self.packerQueue = packerQueue\n self.start()\n\n def run(self):\n while True:\n try:\n job = self.queue.get(timeout=10)\n except queue.Empty:\n continue\n\n translatedMsg = GoogleTranslator(source=\"auto\", target=\"spanish\").translate(job[\"value\"][\"data\"])\n self.packerQueue.put({\n \"uid\": job[\"uid\"],\n \"value\": {\n \"language\": \"spanish\",\n \"original\": job[\"value\"][\"data\"],\n \"translated\": translatedMsg\n }\n })"
44
+ },
45
+ {
46
+ "name": "TamilTranslator.py",
47
+ "type": "file",
48
+ "uid": "dir-594ff411-b916-4a88-9077-3d5b8ff7f871",
49
+ "content": "import threading\nimport queue\nfrom deep_translator import GoogleTranslator # type: ignore\n\nclass TamilTranslator(threading.Thread):\n def __init__(self, id, queue, packerQueue):\n super().__init__(daemon=True)\n self.queue = queue\n self.id = id\n self.packerQueue = packerQueue\n self.start()\n\n def run(self):\n while True:\n try:\n job = self.queue.get(timeout=10)\n except queue.Empty:\n continue\n\n translatedMsg = GoogleTranslator(source=\"auto\", target=\"tamil\").translate(job[\"value\"][\"data\"])\n self.packerQueue.put({\n \"uid\": job[\"uid\"],\n \"value\": {\n \"language\": \"tamil\",\n \"original\": job[\"value\"][\"data\"],\n \"translated\": translatedMsg\n }\n })"
50
+ },
51
+ {
52
+ "name": "readme",
53
+ "type": "file",
54
+ "uid": "dir-f6459410-1634-4dbc-8d76-35896822158d",
55
+ "content": "This folder contains a text translator that uses three workers to translate the text and uses a packer to add the results to a cabinet."
56
+ },
57
+ {
58
+ "name": "TransactionDB.py",
59
+ "type": "file",
60
+ "uid": "dir-f6459410-1634-4dbc-8d76-35sfdvsd6822158d",
61
+ "content": "import sqlite3\nimport atexit\nimport uuid\n\nclass TransactionDB():\n\n def __init__(self):\n atexit.register(self.cleanup_function)\n self.initializeDB()\n\n def cleanup_function(self):\n self.conn.close()\n\n def initializeDB(self):\n\n self.conn = sqlite3.connect(\"translations.db\")\n self.cursor = self.conn.cursor()\n\n self.cursor.execute(\"\"\"\n CREATE TABLE IF NOT EXISTS translation_jobs (\n job_id INTEGER PRIMARY KEY AUTOINCREMENT,\n uid TEXT NOT NULL UNIQUE,\n english TEXT NOT NULL,\n french TEXT,\n spanish TEXT,\n tamil TEXT,\n done INTEGER NOT NULL DEFAULT 0\n );\n \"\"\")\n self.conn.commit()\n\n def addJob(self, data):\n uid = str(uuid.uuid4())\n self.conn.execute(\n \"\"\"\n INSERT INTO translation_jobs (uid, english)\n VALUES (?, ?)\n \"\"\",\n (uid, data)\n )\n self.conn.commit()\n\n return {\n \"uid\": uid,\n \"value\": {\"data\": data}\n }\n \n def addTranslation(self, msg):\n self.conn.execute(\n f\"\"\"\n UPDATE translation_jobs\n SET {msg[\"value\"][\"language\"]} = ?\n WHERE uid = ?\n \"\"\",\n (msg[\"value\"][\"translated\"], msg[\"uid\"])\n )\n self.conn.commit()\n\n\n def isDone(self, uid):\n cur = self.conn.execute(\n \"\"\"\n SELECT\n french IS NOT NULL\n AND spanish IS NOT NULL\n AND tamil IS NOT NULL\n FROM translation_jobs\n WHERE uid = ?\n \"\"\",\n (uid,)\n )\n row = cur.fetchone()\n return bool(row[0]) if row else False\n \n def setDone(self, uid):\n self.conn.execute(\n \"\"\"\n UPDATE translation_jobs\n SET done = 1\n WHERE uid = ?\n \"\"\",\n (uid,)\n )\n self.conn.commit()\n\n\n "
62
+ }
63
+ ]
64
+ }
65
+ ]
66
+ }