Learn Environment
notebook_converter.hpp
Go to the documentation of this file.
1 #ifndef NOTEBOOK_CONVERTER_HPP
2 #define NOTEBOOK_CONVERTER_HPP
3 
4 #include <QObject>
5 #include <QString>
6 #include <QDir>
7 #include <QByteArray>
8 #include <nlohmann/json.hpp>
9 
11 
24 public:
25  explicit NotebookConverter();
26 
32  bool convertNotebook(const QString &notebookPath);
33 
37  void processTaskPool();
38 
44  void toggleSolution(const QString &filePath, const QString &solutionFilePath);
45 
50  void resetNotebook(const QString &notebookPath, const QString &notebookSolutionPath);
51 
57  static bool hasSolutionCells(const QString &notebookPath);
58 
59 private:
73  void removeSolutionFromNotebook(const QString &notebookPath);
74 
75  QByteArray readFile(const QString &notebookPath);
76  json parseJson(const QByteArray &data, const QString &notebookPath);
77  void processCells(json &notebook, const QString &notebookPath);
78  void processCell(json &cell, const QString &notebookPath, int i);
79  void writeFile(const json &notebook, const QString &notebookPath);
80  void copyAndModifyNotebooks(const QDir &sourceDir, const QDir &destDir);
81 
82  void removeSolutionCells(const QString &notebookPath);
83  void addSolutionCells(const QString &notebookPath, const QString &solutionPath);
84  void manipulateSolutionCellContent(json &solutionCell);
85 };
86 
87 #endif // NOTEBOOK_CONVERTER_HPP
FolderStructureConstants::USER_WORKSPACE
const QString USER_WORKSPACE
Path to the user workspace directory. Adjust it in devconatiner.json if changed.
Definition: folder_structure_constants.hpp:63
NotebookConverter
A class for converting Jupyter notebooks to Python scripts and processing task pools.
Definition: notebook_converter.hpp:23
SOLUTION_CELL_TAG
const QString SOLUTION_CELL_TAG
Definition: notebook_converter.cpp:16
json
nlohmann::json json
Definition: notebook_converter.cpp:12
NotebookConverter::hasSolutionCells
static bool hasSolutionCells(const QString &notebookPath)
Checks if the notebook contains any solution cells.
Definition: notebook_converter.cpp:428
folder_structure_constants.hpp
json
nlohmann::json json
Definition: notebook_converter.hpp:10
SOLUTION_CODE_PLACEHOLDER_END
const QString SOLUTION_CODE_PLACEHOLDER_END
Definition: notebook_converter.cpp:25
notebook_converter.hpp
FolderStructureConstants::getPackagePath
QString getPackagePath()
Retrieves the path of the package.
Definition: folder_structure_constants.hpp:80
TASK_CELL_TAG
const QString TASK_CELL_TAG
Definition: notebook_converter.cpp:14
NotebookConverter::processTaskPool
void processTaskPool()
Modifies and copies all notebooks from task_pool to users workspace.
Definition: notebook_converter.cpp:95
FolderStructureConstants::SOLUTION_SCRIPTS_SOURCE_PATH
const QString SOLUTION_SCRIPTS_SOURCE_PATH
Path to the solution scripts source directory.
Definition: folder_structure_constants.hpp:51
NotebookConverter::convertNotebook
bool convertNotebook(const QString &notebookPath)
Converts a Jupyter notebook to a Python script. Ignoring code cells with "solution" tag.
Definition: notebook_converter.cpp:29
NOT_IMPLEMENTED_ERROR
const QString NOT_IMPLEMENTED_ERROR
Definition: notebook_converter.cpp:18
FolderStructureConstants::CONVERTED_SCRIPT_PATH
const QString CONVERTED_SCRIPT_PATH
Path to the converted script.
Definition: folder_structure_constants.hpp:21
SOLUTION_CODE_PLACEHOLDER_START
const QString SOLUTION_CODE_PLACEHOLDER_START
Definition: notebook_converter.cpp:24
SOLUTION_REMOVED_CELL_TAG
const QString SOLUTION_REMOVED_CELL_TAG
Definition: notebook_converter.cpp:15
WRITE_CODE_MARKER
const QString WRITE_CODE_MARKER
Definition: notebook_converter.cpp:17
NotebookConverter::NotebookConverter
NotebookConverter()
Definition: notebook_converter.cpp:27
NotebookConverter::toggleSolution
void toggleSolution(const QString &filePath, const QString &solutionFilePath)
Toggles the solution code in a Jupyter notebook.
Definition: notebook_converter.cpp:266
NotebookConverter::resetNotebook
void resetNotebook(const QString &notebookPath, const QString &notebookSolutionPath)
Removes solution code from a Jupyter notebook.
Definition: notebook_converter.cpp:104
SOLUTION_CELL_HEADER
const QString SOLUTION_CELL_HEADER
Definition: notebook_converter.cpp:19