Files
controller-wisetopdataserver/python/biopro/ext/export.c
T
2021-12-20 14:52:55 +08:00

129 lines
4.2 KiB
C

#include "export.h"
#include <stdio.h>
#include "Python.h"
#include "export_csv.h"
#include "export_txt.h"
#include "recording.h"
#include "sample.h"
static PyObject *Export_export_txt(PyObject *self, PyObject *args, PyObject *kwargs) {
static char *keywords[] = {"meta", //
"export_path", //
"resample_rate", //
"resample_method",
"shift_channel",
NULL};
PyObject * meta_file_ref = NULL;
PyObject * export_path_ref = NULL;
unsigned int resample_rate = 0;
unsigned int resample_method = 0;
int shift_channel = 0;
if (!PyArg_ParseTupleAndKeywords(args, //
kwargs,
"OO|IIp",
keywords,
&meta_file_ref,
&export_path_ref,
&resample_rate,
&resample_method,
&shift_channel)) {
return NULL;
}
char *meta_file = PyBytes_AsString(meta_file_ref);
char *export_path = PyBytes_AsString(export_path_ref);
return export_txt(meta_file, //
export_path,
resample_rate,
resample_method,
shift_channel);
}
static PyObject *Export_export_csv(PyObject *self, PyObject *args, PyObject *kwargs) {
static char *keywords[] = {"meta", //
"export_path", //
"channel", //
"duration", //
"resample_rate", //
"resample_method",
"include_header",
"shift_channel",
NULL};
PyObject * meta_file_ref = NULL;
PyObject * export_path_ref = NULL;
unsigned int duration = 60;
PyObject * channel = NULL;
unsigned int resample_rate = 0;
unsigned int resample_method = 0;
int include_header = 0;
int shift_channel = 0;
if (!PyArg_ParseTupleAndKeywords(args, //
kwargs,
"OO|OIIIpp",
keywords,
&meta_file_ref,
&export_path_ref,
&channel,
&duration,
&resample_rate,
&resample_method,
&include_header,
&shift_channel)) {
return NULL;
}
char *meta_file = PyBytes_AsString(meta_file_ref);
char *export_path = PyBytes_AsString(export_path_ref);
IntSet channel_mask;
int_set_init(&channel_mask);
if (channel != NULL && channel != Py_None) {
int_set_add_list(&channel_mask, channel);
}
PyObject *ret = export_csv(meta_file, //
export_path,
resample_rate,
resample_method,
duration,
&channel_mask,
include_header,
shift_channel);
int_set_clear(&channel_mask);
return ret;
}
// module init
static PyMethodDef moduleMethods[] = { //
{"export_txt", (PyCFunction)Export_export_txt, METH_VARARGS | METH_KEYWORDS, ""},
{"export_csv", (PyCFunction)Export_export_csv, METH_VARARGS | METH_KEYWORDS, ""},
{NULL, NULL, 0, NULL}};
static struct PyModuleDef ExportModule = { //
PyModuleDef_HEAD_INIT,
// module name
"export",
// module doc
NULL,
-1,
moduleMethods};
// module export
PyMODINIT_FUNC PyInit_export(void) {
PyObject *module;
module = PyModule_Create(&ExportModule);
if (module == NULL) return NULL;
return module;
}