Learn Environment
Loading...
Searching...
No Matches
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
10using json = nlohmann::json;
11
23class NotebookConverter : public QObject {
24 Q_OBJECT
25public:
26 explicit NotebookConverter(QObject *parent = nullptr);
27
33 bool convertNotebook(const QString &notebookPath);
34
38 void processTaskPool();
39
45 void toggleSolution(const QString &filePath, const QString &solutionFilePath);
46
51 void resetNotebook(const QString &notebookPath, const QString &notebookSolutionPath);
52
58 static bool hasSolutionCells(const QString &notebookPath);
59
60private:
74 void removeSolutionFromNotebook(const QString &notebookPath);
75
76 QByteArray readFile(const QString &notebookPath);
77 json parseJson(const QByteArray &data, const QString &notebookPath);
78 void processCells(json &notebook, const QString &notebookPath);
79 void processCell(json &cell, const QString &notebookPath, int i);
80 void writeFile(const json &notebook, const QString &notebookPath);
81 void copyAndModifyNotebooks(const QDir &sourceDir, const QDir &destDir);
82
83 void removeSolutionCells(const QString &notebookPath);
84 void addSolutionCells(const QString &notebookPath, const QString &solutionPath);
85 void manipulateSolutionCellContent(json &solutionCell);
86};
87
88#endif // NOTEBOOK_CONVERTER_HPP
A class for converting Jupyter notebooks to Python scripts and processing task pools.
Definition notebook_converter.hpp:23
NotebookConverter(QObject *parent=nullptr)
Definition notebook_converter.cpp:26
void toggleSolution(const QString &filePath, const QString &solutionFilePath)
Toggles the solution code in a Jupyter notebook.
Definition notebook_converter.cpp:265
void processTaskPool()
Modifies and copies all notebooks from task_pool to users workspace.
Definition notebook_converter.cpp:94
bool convertNotebook(const QString &notebookPath)
Converts a Jupyter notebook to a Python script. Ignoring code cells with "solution" tag.
Definition notebook_converter.cpp:28
void resetNotebook(const QString &notebookPath, const QString &notebookSolutionPath)
Removes solution code from a Jupyter notebook.
Definition notebook_converter.cpp:103
static bool hasSolutionCells(const QString &notebookPath)
Checks if the notebook contains any solution cells.
Definition notebook_converter.cpp:427
nlohmann::json json
Definition notebook_converter.cpp:11