diff options
author | Sunil Shetye | 2024-10-24 22:40:51 +0530 |
---|---|---|
committer | Sunil Shetye | 2024-10-25 10:56:46 +0530 |
commit | e8039242b81a10e28bfe64f568f8693fbc07a8b2 (patch) | |
tree | 8aeaf29c92ad2a765314beee629e7ef05f507364 | |
parent | 80e2d3e410e4c9f481a2375ec03edf2469a39b7e (diff) | |
download | Common-Interface-Project-e8039242b81a10e28bfe64f568f8693fbc07a8b2.tar.gz Common-Interface-Project-e8039242b81a10e28bfe64f568f8693fbc07a8b2.tar.bz2 Common-Interface-Project-e8039242b81a10e28bfe64f568f8693fbc07a8b2.zip |
code cleanup
-rw-r--r-- | blocks/.flake8 | 2 | ||||
-rwxr-xr-x | blocks/Xcos/MxGraphParser.py | 2 | ||||
-rw-r--r-- | blocks/authAPI/views.py | 2 | ||||
-rw-r--r-- | blocks/blocks/settings.py | 2 | ||||
-rw-r--r-- | blocks/create_gallery.py | 2 | ||||
-rw-r--r-- | blocks/saveAPI/views.py | 33 | ||||
-rw-r--r-- | blocks/simulationAPI/helpers/parse.py | 79 |
7 files changed, 23 insertions, 99 deletions
diff --git a/blocks/.flake8 b/blocks/.flake8 index 5b7ab23c..7f9fb299 100644 --- a/blocks/.flake8 +++ b/blocks/.flake8 @@ -5,5 +5,5 @@ #ignore = E121,E123,E126,E226,E24,E704,W503,W504 ignore = F401,F403,W504 extend-exclude = docs,env*,migrations,node_modules,Xcos/common,Xcos/blocks,Xcos/ports,Xcos/links -max-complexity = 13 +max-complexity = 12 max-line-length = 260 diff --git a/blocks/Xcos/MxGraphParser.py b/blocks/Xcos/MxGraphParser.py index 32acaab2..521bd2d2 100755 --- a/blocks/Xcos/MxGraphParser.py +++ b/blocks/Xcos/MxGraphParser.py @@ -294,7 +294,7 @@ for root in model: float(componentGeometry['height']) * float(geometryY)) geometry['x'] = geometryX geometry['y'] = geometryY - + globals()[stylename](outroot, attribid, ParentComponent, ordering, geometry, style=style) IDLIST[attribid] = stylename diff --git a/blocks/authAPI/views.py b/blocks/authAPI/views.py index e46f940e..e1cc173b 100644 --- a/blocks/authAPI/views.py +++ b/blocks/authAPI/views.py @@ -27,7 +27,7 @@ def activate_user(request, uid, token): """ protocol = 'https://' if request.is_secure() else 'http://' - web_url = protocol + request.get_host() + '/api/auth/users/activation/' # noqa URL comes from Djoser library + web_url = protocol + request.get_host() + '/api/auth/users/activation/' # URL comes from Djoser library return render(request, 'activate_user.html', {'uid': uid, 'token': token, diff --git a/blocks/blocks/settings.py b/blocks/blocks/settings.py index bc8072a5..e979be6b 100644 --- a/blocks/blocks/settings.py +++ b/blocks/blocks/settings.py @@ -214,7 +214,7 @@ STATIC_URL = '/django_static/' FILE_STORAGE_ROOT = os.path.join(BASE_DIR, 'file_storage') FILE_STORAGE_URL = '/files' -# noqa For Netlist handling netlist uploads and other temp uploads +# For Netlist handling netlist uploads and other temp uploads MEDIA_URL = '/files/' MEDIA_ROOT = os.path.join(BASE_DIR, 'file_storage') diff --git a/blocks/create_gallery.py b/blocks/create_gallery.py index e44d0e68..4a918c68 100644 --- a/blocks/create_gallery.py +++ b/blocks/create_gallery.py @@ -9,7 +9,7 @@ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blocks.settings') # Initialize Django django.setup() -from saveAPI.views import GalleryView +from saveAPI.views import GalleryView # noqa: E402 def escape_quotes(value): diff --git a/blocks/saveAPI/views.py b/blocks/saveAPI/views.py index 9e9d07e9..a659665b 100644 --- a/blocks/saveAPI/views.py +++ b/blocks/saveAPI/views.py @@ -166,6 +166,23 @@ class FetchSaveDiagram(APIView): return Response({'error': 'Invalid sharing state'}, status=status.HTTP_400_BAD_REQUEST) + def update_state(self, state, data): + # if data dump, shared, name, or description needs to be updated + if 'data_dump' in data: + state.data_dump = data['data_dump'] + if 'shared' in data: + state.shared = bool(data['shared']) + if 'name' in data: + state.name = data['name'] + if 'description' in data: + state.description = data['description'] + # if thumbnail needs to be updated + if 'base64_image' in data: + img = Base64ImageField(max_length=None, use_url=True) + filename, content = img.update( + data['base64_image']) + state.base64_image.save(filename, content) + @swagger_auto_schema(responses={200: StateSaveSerializer}) def post(self, request, save_id): if isinstance(save_id, uuid.UUID): @@ -186,21 +203,7 @@ class FetchSaveDiagram(APIView): status=status.HTTP_406_NOT_ACCEPTABLE) try: - # if data dump, shared,name and description needs to be updated - if 'data_dump' in request.data: - saved_state.data_dump = request.data['data_dump'] - if 'shared' in request.data: - saved_state.shared = bool(request.data['shared']) - if 'name' in request.data: - saved_state.name = request.data['name'] - if 'description' in request.data: - saved_state.description = request.data['description'] - # if thumbnail needs to be updated - if 'base64_image' in request.data: - img = Base64ImageField(max_length=None, use_url=True) - filename, content = img.update( - request.data['base64_image']) - saved_state.base64_image.save(filename, content) + self.update_state(saved_state, request.data) saved_state.save() serialized = SaveListSerializer(saved_state) return Response(serialized.data) diff --git a/blocks/simulationAPI/helpers/parse.py b/blocks/simulationAPI/helpers/parse.py deleted file mode 100644 index 52c2aa41..00000000 --- a/blocks/simulationAPI/helpers/parse.py +++ /dev/null @@ -1,79 +0,0 @@ -import re -import sys - - -def extract_data_from_ngspice_output(pathToFile): - """ Parses the output file generated by ngspice and - returns a json containing points to plot graph. - """ - - try: - with open(pathToFile, 'r') as f: - f_contents = f.readlines() - graph = True - - curernt_headers = [] - total_number_of_tables = 0 - if '=' in f_contents[0]: - graph = False - - if not graph: - json_data = {"data": [], "graph": "false"} - for line in f_contents: - contents_of_line = line.split() - json_data["data"].append(contents_of_line) - - else: - json_data = {"data": [], "graph": "true"} - for line in f_contents: - contents_of_line = line.split() - - if 'Index' in contents_of_line: - # line_set = remove_duplicate_items_from_list( - # contents_of_line) - line_set = contents_of_line - - if line_set != curernt_headers: - curernt_headers = line_set - json_data["data"].append( - {"labels": [], "x": [], "y": []}) - index = len(json_data["data"]) - 1 - for x in range(2, len(curernt_headers)): - json_data["data"][index]["y"].append([]) - - for x in range(1, len(curernt_headers)): - json_data["data"][index]["labels"].append( - curernt_headers[x]) - total_number_of_tables += 1 - - else: - m = re.match('[0-9]+', line) - if m: - index = len(json_data["data"]) - 1 - data = json_data["data"][index] - data["x"].append(contents_of_line[1]) - - for x in range(len(data["y"])): - data["y"][x].append(contents_of_line[x + 2]) - json_data["total_number_of_tables"] = total_number_of_tables - \ - len(json_data["data"]) - return json_data - - except OSError as e: - print('Cannot Open File') - raise e - - -# def remove_duplicate_items_from_list(line_list): -# res = [] -# for i in line_list: -# if i not in res: -# res.append(i) -# return res - - -# for testing provide the filepath as command line argument -if __name__ == "__main__": - - filePath = sys.argv[1] - print(extract_data_from_ngspice_output(filePath)) |