Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
django
python-environ
django-environ
django-cors-headers
gunicorn
31 changes: 27 additions & 4 deletions backend/synthesis/synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,23 @@
BLOCK_DIRECTORY = 'modules'

OPTIONAL_FILES = {
'FaceDetector' : 'utils/models/haar_cascade/*',
'ObjectDetector': 'utils/models/yolov3/*'
'FaceDetector' : 'utils/models/haar_cascade/**/*',
'ObjectDetector': 'utils/models/yolov3/**/*'
}

BLOCK_DEPENDENCIES = {
'FaceDetector': ['opencv-python', 'numpy'],
'ObjectDetector': ['opencv-python', 'numpy'],
'ContourDetector': ['opencv-python', 'numpy'],
'Cropper': ['opencv-python', 'numpy'],
'ColorFilter': ['opencv-python', 'numpy'],
'Blur': ['opencv-python', 'numpy'],
'Dilation': ['opencv-python', 'numpy'],
'EdgeDetector': ['opencv-python', 'numpy'],
'Erosion': ['opencv-python', 'numpy'],
'Threshold': ['opencv-python', 'numpy'],
'VideoStreamer': ['opencv-python', 'numpy'],
'ImageRead': ['opencv-python', 'numpy']
}

PROJECT_FILE_EXTENSION = '.vc3'
Expand All @@ -34,6 +49,7 @@ def syntheize_modules(data: dict, zipfile: InMemoryZip) -> Tuple[InMemoryZip, Di
parameters = {}
synhronize_frequency = {}
optional_files = {}
project_dependencies = set()
wire_comp = data['design']['graph']['wires'] # Retrieve all wire connections from the design graph
dep_no = {} # Dictionary to store the number of blocks of each type

Expand Down Expand Up @@ -61,6 +77,9 @@ def process_dependency(dep, zipfile, synhronize_frequency, optional_files, dep_n
if script_name in optional_files:
optional_files[script_name] = True # Mark the script as required in optional files

if script_name in BLOCK_DEPENDENCIES:
project_dependencies.update(BLOCK_DEPENDENCIES[script_name])

script_name += dependency['package']['version'].replace('.', '') # Append version number to the script name, removing dots

# Increment the count for this script type or initialize it
Expand Down Expand Up @@ -303,7 +322,7 @@ def process_wires(valid_wires):
zipfile.append('data.json', json.dumps(data)) # Append the JSON data to the zipfile


return zipfile, optional_files
return zipfile, optional_files, project_dependencies

def synthesize_executioner(zipfile: InMemoryZip, optional_files: Dict[str, bool]) -> InMemoryZip:
'''Synthesize python code necessary to run the blocks.
Expand Down Expand Up @@ -338,9 +357,13 @@ def synthesize(data: dict) -> Tuple[str, BytesIO]:
'''
zipfile = InMemoryZip()
# Optional files required based on blocks present.
zipfile, optional_files = syntheize_modules(data, zipfile)
zipfile, optional_files, project_dependencies = syntheize_modules(data, zipfile)
zipfile = synthesize_executioner(zipfile, optional_files)
zipfile = syntesize_extras(zipfile)

if project_dependencies:
requirements_content = "\n".join(project_dependencies) + "\n"
zipfile.append('requirements.txt', requirements_content)

# Project name (zipfile name)
project_name = f"{data['package']['name']}" if data['package']['name'] != '' else 'Project'
Expand Down
Loading