|
1 | 1 | import sys |
2 | 2 | import funscript_editor.utils.logging as logging |
3 | 3 | import os |
| 4 | +import json |
4 | 5 | import time |
5 | 6 | import platform |
6 | 7 | import cv2 |
|
15 | 16 |
|
16 | 17 | from PyQt5 import QtCore, QtGui, QtWidgets |
17 | 18 |
|
18 | | -USE_OPTICALFLOW = False |
| 19 | +USE_OPTICALFLOW = False # Enable some hardcoded optical flow testcode |
19 | 20 | if USE_OPTICALFLOW: |
20 | 21 | from funscript_editor.algorithms.opticalflow import OpticalFlowFunscriptGeneratorThread, OpticalFlowFunscriptGeneratorParameter |
21 | 22 |
|
@@ -44,6 +45,9 @@ def __init__(self, |
44 | 45 | if os.path.exists(definitions.ICON_PATH): |
45 | 46 | self.setWindowIcon(QtGui.QIcon(definitions.ICON_PATH)) |
46 | 47 |
|
| 48 | + if include_multiaxis: |
| 49 | + self.__logger.info("Enable multiaxis output") |
| 50 | + |
47 | 51 | if not isinstance(output_file, Funscript): |
48 | 52 | output_file = os.path.abspath(output_file) |
49 | 53 | if os.path.isdir(output_file): |
@@ -108,15 +112,34 @@ def __funscript_generated(self, funscripts, msg, success) -> None: |
108 | 112 | first_metric = [x for x in funscripts.keys()][0] |
109 | 113 |
|
110 | 114 | if isinstance(self.output_file, Funscript): |
| 115 | + if len(funscripts) > 1: |
| 116 | + self.__logger.warning("Multiaxis output for build-in UI is not implemented") |
111 | 117 | for item in funscripts[first_metric].get_actions(): |
112 | 118 | self.output_file.add_action(item['pos'], item['at'], SETTINGS['raw_output']) |
113 | 119 | self.funscriptCompleted.emit(self.output_file, msg, success) |
114 | 120 | else: |
115 | 121 | os.makedirs(os.path.dirname(self.output_file), exist_ok=True) |
116 | | - with open(self.output_file, 'w') as f: |
117 | | - f.write('at;pos\n') |
118 | | - for item in funscripts[first_metric].get_actions(): |
119 | | - f.write('{at};{pos}\n'.format(at=item['at'], pos=item['pos'])) |
| 122 | + if self.output_file.lower().endswith('.json'): |
| 123 | + funscript_json_output = { |
| 124 | + 'version': 1, |
| 125 | + 'actions': {} |
| 126 | + } |
| 127 | + |
| 128 | + for key in funscripts.keys(): |
| 129 | + funscript_json_output['actions'][key] = [] |
| 130 | + for item in funscripts[key].get_actions(): |
| 131 | + funscript_json_output['actions'][key].append(item) |
| 132 | + |
| 133 | + with open(self.output_file, 'w') as f: |
| 134 | + json.dump(funscript_json_output, f) |
| 135 | + else: |
| 136 | + # dump to CSV |
| 137 | + if len(funscripts) > 1: |
| 138 | + self.__logger.warning("Multiaxis output for csv is not implemented") |
| 139 | + with open(self.output_file, 'w') as f: |
| 140 | + f.write('at;pos\n') |
| 141 | + for item in funscripts[first_metric].get_actions(): |
| 142 | + f.write('{at};{pos}\n'.format(at=item['at'], pos=item['pos'])) |
120 | 143 |
|
121 | 144 | self.__logger.info("Save result to %s", self.output_file) |
122 | 145 | if not success: self.__show_message(msg, error=True) |
|
0 commit comments