Saves one dataset into database, timestamp will be added automatically. Parameters ---------- dataset : any type The dataset you want to store. dataset_name : str The name of dataset. kwargs : other events Other events, suc
(self, dataset=None, dataset_name=None, **kwargs)
| 256 | |
| 257 | # =========================== DATASET =============================== |
| 258 | def save_dataset(self, dataset=None, dataset_name=None, **kwargs): |
| 259 | """Saves one dataset into database, timestamp will be added automatically. |
| 260 | |
| 261 | Parameters |
| 262 | ---------- |
| 263 | dataset : any type |
| 264 | The dataset you want to store. |
| 265 | dataset_name : str |
| 266 | The name of dataset. |
| 267 | kwargs : other events |
| 268 | Other events, such as description, author and etc (optinal). |
| 269 | |
| 270 | Examples |
| 271 | ---------- |
| 272 | Save dataset |
| 273 | >>> db.save_dataset([X_train, y_train, X_test, y_test], 'mnist', description='this is a tutorial') |
| 274 | |
| 275 | Get dataset |
| 276 | >>> dataset = db.find_top_dataset('mnist') |
| 277 | |
| 278 | Returns |
| 279 | --------- |
| 280 | boolean : Return True if save success, otherwise, return False. |
| 281 | """ |
| 282 | self._fill_project_info(kwargs) |
| 283 | if dataset_name is None: |
| 284 | raise Exception("dataset_name is None, please give a dataset name") |
| 285 | kwargs.update({'dataset_name': dataset_name}) |
| 286 | |
| 287 | s = time.time() |
| 288 | try: |
| 289 | dataset_id = self.dataset_fs.put(self._serialization(dataset)) |
| 290 | kwargs.update({'dataset_id': dataset_id, 'time': datetime.utcnow()}) |
| 291 | self.db.Dataset.insert_one(kwargs) |
| 292 | # print("[Database] Save params: {} SUCCESS, took: {}s".format(file_name, round(time.time()-s, 2))) |
| 293 | print("[Database] Save dataset: SUCCESS, took: {}s".format(round(time.time() - s, 2))) |
| 294 | return True |
| 295 | except Exception as e: |
| 296 | exc_type, exc_obj, exc_tb = sys.exc_info() |
| 297 | fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] |
| 298 | logging.info("{} {} {} {} {}".format(exc_type, exc_obj, fname, exc_tb.tb_lineno, e)) |
| 299 | print("[Database] Save dataset: FAIL") |
| 300 | return False |
| 301 | |
| 302 | def find_top_dataset(self, dataset_name=None, sort=None, **kwargs): |
| 303 | """Finds and returns a dataset from the database which matches the requirement. |
no test coverage detected