sample-ui-component-library 0.0.48-dev → 0.0.49-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.48-dev",
3
+ "version": "0.0.49-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",
@@ -46,7 +46,7 @@
46
46
  "@storybook/test": "^8.6.11",
47
47
  "@storybook/theming": "^8.6.11",
48
48
  "css-loader": "^7.1.2",
49
- "dal-engine-core-js-lib-dev": "^0.0.4",
49
+ "dal-engine-core-js-lib-dev": "^0.0.15-dev",
50
50
  "gh-pages": "^6.3.0",
51
51
  "prop-types": "^15.8.1",
52
52
  "raw-loader": "^4.0.2",
@@ -17,11 +17,6 @@ import { EditorContext } from "./EditorContext";
17
17
 
18
18
  import { editorReducer, initialState } from "./EditorReducer";
19
19
 
20
- const MODES = {
21
- MAPPING: 1,
22
- IMPLEMENTATION: 2
23
- }
24
-
25
20
  /**
26
21
  * Renders the editor component with support for tabs.
27
22
  *
@@ -50,10 +45,6 @@ export const Editor = forwardRef(({ }, ref) => {
50
45
  dispatch({ type: "RESET_STATE"});
51
46
  dispatch({ type: "SET_PARENT_TAB_GROUP_ID", payload: id });
52
47
  }, []);
53
-
54
- const setMapping = useCallback((fileName, mapping) => {
55
- dispatch({ type: "SET_MAPPING", payload: { fileName, mapping } });
56
- }, []);
57
48
 
58
49
  const api = useMemo(() => {
59
50
  return {
@@ -62,10 +53,9 @@ export const Editor = forwardRef(({ }, ref) => {
62
53
  setTabGroupId,
63
54
  selectTab,
64
55
  closeTab,
65
- moveTab,
66
- setMapping
56
+ moveTab
67
57
  };
68
- }, [state, addTab, selectTab, closeTab, moveTab, setTabGroupId, setMapping]);
58
+ }, [state, addTab, selectTab, closeTab, moveTab, setTabGroupId]);
69
59
 
70
60
  useImperativeHandle(ref, () => api, [api]);
71
61
 
@@ -99,25 +99,6 @@ export const editorReducer = (state, action) => {
99
99
  tabs: prevTabs
100
100
  };
101
101
  }
102
-
103
- case "SET_MAPPING": {
104
- const { mapping, fileName } = action.payload;
105
- console.log(state);
106
- for (let i = 0; i < state.tabs.length; i++) {
107
- const tab = state.tabs[i];
108
- if (tab.name === fileName) {
109
- const updatedTab = { ...tab, mapping: mapping };
110
- const newTabs = [...state.tabs];
111
- newTabs[i] = updatedTab;
112
- return {
113
- ...state,
114
- tabs: newTabs,
115
- activeTab: updatedTab
116
- };
117
- }
118
- }
119
- return state;
120
- }
121
102
 
122
103
  case "RESET_STATE": {
123
104
  return initialState;
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useLayoutEffect, useEffect, useRef, useState } from 'react';
1
+ import React, { useEffect, useRef, useState } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
 
4
4
  import Editor from '@monaco-editor/react';
@@ -17,22 +17,14 @@ export const MonacoInstance = ({ }) => {
17
17
  const containerRef = useRef(null);
18
18
  const frameRef = useRef(0);
19
19
 
20
- const [overlayDivs, setOverlayDivs] = useState();
21
- const [overlayRanges, setOverlayRanges] = useState();
22
-
23
- useLayoutEffect(() => {
20
+ useEffect(() => {
24
21
  if (state.activeTab) {
25
22
  setEditorContent(state.activeTab.content);
26
23
  setShowEditor(true);
27
- if (state.activeTab.mapping) {
28
- addOverlays(state.activeTab.mapping);
29
- } else {
30
- setOverlayDivs([]);
31
- }
32
24
  } else {
33
25
  setShowEditor(false);
34
26
  }
35
- }, [state.activeTab, editorRef]);
27
+ }, [state.activeTab]);
36
28
 
37
29
  useEffect(() => {
38
30
  content.current = editorContent;
@@ -46,53 +38,13 @@ export const MonacoInstance = ({ }) => {
46
38
  * @param {Object} editor
47
39
  * @param {Object} monaco
48
40
  */
49
- const handleEditorDidMount = useCallback((editor, monaco) => {
41
+ const handleEditorDidMount = (editor, monaco) => {
50
42
  editorRef.current = editor;
51
43
  if (content?.current) {
52
44
  editorRef.current.setValue(content.current);
53
45
  }
54
46
  editorRef.current.layout();
55
- if (state.activeTab?.mapping) {
56
- addOverlays(state.activeTab.mapping);
57
- } else {
58
- setOverlayDivs([]);
59
- }
60
- }, [state.activeTab]);
61
-
62
- // Add overlays to editor for the given line ranges.
63
- const addOverlays = useCallback((ranges) => {
64
- if (!editorRef.current) return;
65
-
66
- const lineCount = editorRef.current.getModel().getLineCount();
67
- const lineHeight = editorRef.current.getOption(monaco.editor.EditorOption.lineHeight);
68
-
69
- const divs = [];
70
- ranges.forEach((entry) => {
71
- const top = editorRef.current.getTopForLineNumber(entry.start_line) - editorRef.current.getScrollTop();
72
- let bottom = editorRef.current.getTopForLineNumber(entry.end_line + 1) - editorRef.current.getScrollTop();
73
- if (entry.end_line >= lineCount) {
74
- bottom = bottom + lineHeight;
75
- }
76
- const overlayDiv = <div className="line-block-overlay" style={{ top: top + "px", height: (bottom - top) + "px" }}></div>;
77
- divs.push(overlayDiv);
78
- });
79
- setOverlayDivs(divs);
80
- }, [editorRef?.current]);
81
-
82
- // Scroll the editor and update overlays on wheel event.
83
- const handleWheel = useCallback((e) => {
84
- if (!editorRef.current) return;
85
- const deltaY = e.deltaY;
86
- const currentScrollTop = editorRef.current.getScrollTop();
87
- editorRef.current.setScrollTop(currentScrollTop + deltaY);
88
- if (state.activeTab?.mapping) {
89
- addOverlays(state.activeTab.mapping);
90
- } else {
91
- setOverlayDivs([]);
92
- }
93
- }, [overlayRanges, state.activeTab]);
94
-
95
-
47
+ }
96
48
 
97
49
  // Editor options for Monaco Editor.
98
50
  const editorOptions = {
@@ -118,7 +70,6 @@ export const MonacoInstance = ({ }) => {
118
70
  cancelAnimationFrame(frameRef.current);
119
71
  frameRef.current = requestAnimationFrame(() => {
120
72
  editorRef.current?.layout();
121
- addOverlays(state.activeTab.mapping);
122
73
  });
123
74
  });
124
75
 
@@ -128,7 +79,7 @@ export const MonacoInstance = ({ }) => {
128
79
  cancelAnimationFrame(frameRef.current);
129
80
  ro.disconnect();
130
81
  };
131
- }, [state.activeTab, addOverlays]);
82
+ }, []);
132
83
 
133
84
  /**
134
85
  * Render the editor if there is an active tab, otherwise render a placeholder message.
@@ -153,9 +104,6 @@ export const MonacoInstance = ({ }) => {
153
104
  return (
154
105
  <div className="editor-container" ref={containerRef}>
155
106
  {renderEditor()}
156
- <div className="overlay-layer" onWheel={handleWheel}>
157
- {overlayDivs}
158
- </div>
159
107
  </div>
160
108
  )
161
109
  }
@@ -11,24 +11,4 @@
11
11
  position:relative;
12
12
  width:100%;
13
13
  height: 100%;
14
- }
15
-
16
- .overlay-layer {
17
- position: absolute;
18
- left: 0;
19
- right: 0;
20
- inset: 0;
21
- overflow:hidden;
22
- }
23
-
24
- .line-block-overlay {
25
- z-index: 999;
26
- position: absolute;
27
- left: 0;
28
- right: 0;
29
- }
30
-
31
- .line-block-overlay:hover {
32
- background-color: rgba(255, 166, 0, 0.3);
33
- cursor: pointer;
34
14
  }
@@ -11,8 +11,6 @@ import {
11
11
  } from "@dnd-kit/core";
12
12
 
13
13
  import WorkspaceSampleTree from "./data/FileBrowser/workspace_sample.json"
14
- import transactiondb_mapping from "./data/Mapping/TransactionDB_mapping.json"
15
- import mapping from "./data/Mapping/mapping.json"
16
14
 
17
15
  import "./EditorStories.scss"
18
16
 
@@ -54,12 +52,15 @@ const Template = (args) => {
54
52
  }
55
53
  });
56
54
 
57
- const result = flattenTree(WorkspaceSampleTree.tree).find(
58
- (obj) => obj.name === "TransactionDB.py"
59
- );
60
- editorRef.current.addTab(result);
61
- // editorRef.current.setMapping("FrenchTranslator.py", mapping);
62
- editorRef.current.setMapping("TransactionDB.py", transactiondb_mapping);
55
+
56
+ const node = {
57
+ "name": "SAMPLE",
58
+ "type": "file",
59
+ "uid": "dissr-f6459410-1634-4dbc-8d76-35896822158d",
60
+ "content": "1234"
61
+ }
62
+
63
+ editorRef.current.addTab(node,2);
63
64
  }, []);
64
65
 
65
66
  const [dragging, setDragging] = useState(false);
@@ -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
+ {"tree":[{"name":"library_manager_single_threaded","type":"folder","uid":"dir-ba56de84-31dd-4ccf-ae98-a98b0581f803","children":[{"name":"library_manager.py","type":"file","uid":"dir-3d7aaf8e-6224-4eb7-8301-936447fef430","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 "},{"name":"readme","type":"file","uid":"dir-5aa507ee-e43d-4d77-b49a-b6e0b1da36f5","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."}]},{"name":"text_translator","type":"folder","uid":"dir-cbb97582-e3da-403e-aa7f-a524a5a7cff7","children":[{"name":"FrenchTranslator.py","type":"file","uid":"dir-516008b2-e80c-4a3a-bb00-d651885ac15d","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 })"},{"name":"Packer.py","type":"file","uid":"dir-e5085241-ff4f-434d-85ab-7f50e673ea4d","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\"])"},{"name":"SpanishTranslator.py","type":"file","uid":"dir-b2a78dfd-aa94-4068-a5f7-24c396d88825","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 })"},{"name":"TamilTranslator.py","type":"file","uid":"dir-594ff411-b916-4a88-9077-3d5b8ff7f871","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 })"},{"name":"readme","type":"file","uid":"dir-f6459410-1634-4dbc-8d76-35896822158d","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."}]}]}
@@ -1,149 +0,0 @@
1
- [
2
- {
3
- "type": "Import",
4
- "uid": "41375952-c2b0-4d81-9833-f7e38afe5130",
5
- "start_line": 1,
6
- "end_line": 1,
7
- "source": "import sqlite3"
8
- },
9
- {
10
- "type": "Import",
11
- "uid": "a8ceb80a-390d-4d0e-a3b4-db9f299a067b",
12
- "start_line": 2,
13
- "end_line": 2,
14
- "source": "import atexit"
15
- },
16
- {
17
- "type": "Import",
18
- "uid": "eccfad0c-1487-4d39-84e2-24107925be66",
19
- "start_line": 3,
20
- "end_line": 3,
21
- "source": "import uuid"
22
- },
23
- {
24
- "type": "Expr",
25
- "uid": "b13d053d-b448-42cf-adce-2720d7026c28",
26
- "start_line": 8,
27
- "end_line": 8,
28
- "source": "atexit.register(self.cleanup_function)"
29
- },
30
- {
31
- "type": "Expr",
32
- "uid": "d735f8a9-b2d9-4af7-b8d0-021bbb8a8945",
33
- "start_line": 9,
34
- "end_line": 9,
35
- "source": "self.initializeDB()"
36
- },
37
- {
38
- "type": "Expr",
39
- "uid": "f96705c3-5afb-4ad2-ad3b-66e0f8c1fa44",
40
- "start_line": 12,
41
- "end_line": 12,
42
- "source": "self.conn.close()"
43
- },
44
- {
45
- "type": "Assign",
46
- "uid": "3597725d-8fba-486f-9788-4f346ba91be9",
47
- "start_line": 16,
48
- "end_line": 16,
49
- "source": "self.conn = sqlite3.connect(\"translations.db\")"
50
- },
51
- {
52
- "type": "Assign",
53
- "uid": "8e34543e-d1a8-4f0b-9945-9fc61b192e88",
54
- "start_line": 17,
55
- "end_line": 17,
56
- "source": "self.cursor = self.conn.cursor()"
57
- },
58
- {
59
- "type": "Expr",
60
- "uid": "3071e179-638f-428c-9afc-e7c92997cec8",
61
- "start_line": 19,
62
- "end_line": 29,
63
- "source": "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 \"\"\")"
64
- },
65
- {
66
- "type": "Expr",
67
- "uid": "053a69cc-9959-4011-83b9-9cd01948d560",
68
- "start_line": 30,
69
- "end_line": 30,
70
- "source": "self.conn.commit()"
71
- },
72
- {
73
- "type": "Assign",
74
- "uid": "c0c88646-99fc-45de-b441-1efbfb617467",
75
- "start_line": 33,
76
- "end_line": 33,
77
- "source": "uid = str(uuid.uuid4())"
78
- },
79
- {
80
- "type": "Expr",
81
- "uid": "a0dc4483-bf8d-4790-b6ee-11d4c3ff6747",
82
- "start_line": 34,
83
- "end_line": 40,
84
- "source": "self.conn.execute(\n \"\"\"\n INSERT INTO translation_jobs (uid, english)\n VALUES (?, ?)\n \"\"\",\n (uid, data)\n )"
85
- },
86
- {
87
- "type": "Expr",
88
- "uid": "5daf0842-9da2-473f-906f-177b2297e42a",
89
- "start_line": 41,
90
- "end_line": 41,
91
- "source": "self.conn.commit()"
92
- },
93
- {
94
- "type": "Return",
95
- "uid": "e5507376-e78c-49a8-953f-a50f7d534e91",
96
- "start_line": 43,
97
- "end_line": 46,
98
- "source": "return {\n \"uid\": uid,\n \"value\": {\"data\": data}\n }"
99
- },
100
- {
101
- "type": "Expr",
102
- "uid": "5c91cc00-0bab-45f4-8c44-52b9cbba0033",
103
- "start_line": 49,
104
- "end_line": 56,
105
- "source": "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 )"
106
- },
107
- {
108
- "type": "Expr",
109
- "uid": "50dbde63-e2af-4788-bba3-72ce9aa6cd4b",
110
- "start_line": 57,
111
- "end_line": 57,
112
- "source": "self.conn.commit()"
113
- },
114
- {
115
- "type": "Assign",
116
- "uid": "709389e7-985b-433e-b2cb-e77d5a4b8b54",
117
- "start_line": 61,
118
- "end_line": 71,
119
- "source": "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 )"
120
- },
121
- {
122
- "type": "Assign",
123
- "uid": "31c90fb9-89a3-45d9-a2cf-ab0941b26668",
124
- "start_line": 72,
125
- "end_line": 72,
126
- "source": "row = cur.fetchone()"
127
- },
128
- {
129
- "type": "Return",
130
- "uid": "2273d6fc-aa36-4abf-9f98-8259a9d3fd0b",
131
- "start_line": 73,
132
- "end_line": 73,
133
- "source": "return bool(row[0]) if row else False"
134
- },
135
- {
136
- "type": "Expr",
137
- "uid": "695d4481-ba24-458d-80db-0e600296cf2b",
138
- "start_line": 76,
139
- "end_line": 83,
140
- "source": "self.conn.execute(\n \"\"\"\n UPDATE translation_jobs\n SET done = 1\n WHERE uid = ?\n \"\"\",\n (uid,)\n )"
141
- },
142
- {
143
- "type": "Expr",
144
- "uid": "7d6571df-d51f-461a-8a2f-59ce793a3444",
145
- "start_line": 84,
146
- "end_line": 84,
147
- "source": "self.conn.commit()"
148
- }
149
- ]
@@ -1,131 +0,0 @@
1
- [
2
- {
3
- "type": "Import",
4
- "uid": "039c9c46-3788-4017-84cf-2abeb3932507",
5
- "start_line": 1,
6
- "end_line": 1,
7
- "source": "import threading"
8
- },
9
- {
10
- "type": "Import",
11
- "uid": "bf733fea-d7c8-4794-8fd1-cfc6fd2bca62",
12
- "start_line": 2,
13
- "end_line": 2,
14
- "source": "import queue"
15
- },
16
- {
17
- "type": "ImportFrom",
18
- "uid": "9a0f0e12-558d-4304-ad22-f4ebd2b91928",
19
- "start_line": 3,
20
- "end_line": 3,
21
- "source": "from deep_translator import GoogleTranslator"
22
- },
23
- {
24
- "type": "ClassDef",
25
- "uid": "c4a41b12-0ac1-4032-ab1b-5437ed633eb1",
26
- "start_line": 5,
27
- "end_line": 5,
28
- "source": [
29
- "class FrenchTranslator(threading.Thread):"
30
- ]
31
- },
32
- {
33
- "type": "FunctionDef",
34
- "uid": "74e069aa-bcb8-4323-be03-20b55491659e",
35
- "start_line": 6,
36
- "end_line": 6,
37
- "source": [
38
- " def __init__(self, id, queue, packerQueue):"
39
- ]
40
- },
41
- {
42
- "type": "FunctionDef",
43
- "uid": "daf299b9-7a1e-421f-a0ee-91c5f8da02e1",
44
- "start_line": 13,
45
- "end_line": 13,
46
- "source": [
47
- " def run(self):"
48
- ]
49
- },
50
- {
51
- "type": "Expr",
52
- "uid": "06d8f1f0-580f-47c1-9fd6-9f8a8995d419",
53
- "start_line": 7,
54
- "end_line": 7,
55
- "source": "super().__init__(daemon=True)"
56
- },
57
- {
58
- "type": "Assign",
59
- "uid": "f6a558d1-977f-4881-ab8e-0365c35e1c91",
60
- "start_line": 8,
61
- "end_line": 8,
62
- "source": "self.queue = queue"
63
- },
64
- {
65
- "type": "Assign",
66
- "uid": "1da17a50-6792-4fe1-8a1d-de37a0042ba5",
67
- "start_line": 9,
68
- "end_line": 9,
69
- "source": "self.id = id"
70
- },
71
- {
72
- "type": "Assign",
73
- "uid": "5d8e18b0-7520-494d-9511-c707402733e6",
74
- "start_line": 10,
75
- "end_line": 10,
76
- "source": "self.packerQueue = packerQueue"
77
- },
78
- {
79
- "type": "Expr",
80
- "uid": "613a77d5-8adb-4a62-be61-96b121dbb03f",
81
- "start_line": 11,
82
- "end_line": 11,
83
- "source": "self.start()"
84
- },
85
- {
86
- "type": "While",
87
- "uid": "4b76898c-ead0-4f47-b3f5-28130cfaa2d2",
88
- "start_line": 14,
89
- "end_line": 14,
90
- "source": [
91
- " while True:"
92
- ]
93
- },
94
- {
95
- "type": "Try",
96
- "uid": "944b63bf-01ba-45cc-a24a-9b20aa7e753a",
97
- "start_line": 15,
98
- "end_line": 15,
99
- "source": [
100
- " try:"
101
- ]
102
- },
103
- {
104
- "type": "Assign",
105
- "uid": "cb68a874-432e-4d5b-8a3b-1674a19b73d9",
106
- "start_line": 20,
107
- "end_line": 20,
108
- "source": "translatedMsg = GoogleTranslator(source=\"auto\", target=\"french\").translate(job[\"value\"][\"data\"])"
109
- },
110
- {
111
- "type": "Expr",
112
- "uid": "b03928c0-673e-4ff5-a205-89207ec8a26c",
113
- "start_line": 21,
114
- "end_line": 28,
115
- "source": "self.packerQueue.put({\n \"uid\": job[\"uid\"],\n \"value\": {\n \"language\": \"french\",\n \"original\": job[\"value\"][\"data\"],\n \"translated\": translatedMsg\n }\n })"
116
- },
117
- {
118
- "type": "Assign",
119
- "uid": "145c185d-8e8c-427b-a192-cb1da0f79f53",
120
- "start_line": 16,
121
- "end_line": 16,
122
- "source": "job = self.queue.get(timeout=10)"
123
- },
124
- {
125
- "type": "Continue",
126
- "uid": "7cbe5c90-9bf8-49de-a952-0b8e601828f7",
127
- "start_line": 18,
128
- "end_line": 18,
129
- "source": "continue"
130
- }
131
- ]