-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bola Malek
committed
Apr 17, 2019
1 parent
0bf2011
commit 3f7451d
Showing
5 changed files
with
3,060 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import dataset\n", | ||
"import csv\n", | ||
"import os\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"['3_26_final_compare.db', 'in_lab_3_26.db', 'in_lab_3_26_step_5.db', 'in_lab_3_26_step_5_bias_3_locked.db', 'in_lab_3_26_step_5_locked.db']\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"path_to_dbs = './to_export'\n", | ||
"\n", | ||
"db_files = [f for f in os.listdir(path_to_dbs) if \".db\" in f]\n", | ||
"print(db_files)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 14, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"\n", | ||
"def csv_name_from_db(db_file_name, T, k):\n", | ||
" return \"./send_to_xuejian/\" + db_file_name[19:-3] + str(T) + \"_\" + str(k) +\".csv\"\n", | ||
"\n", | ||
"def export_from_db(db_file_name):\n", | ||
" Ts = range(10, 100, 5)\n", | ||
" ks = [0, 1]\n", | ||
" db = dataset.connect(db_file_name)\n", | ||
" table = db.load_table('recording')\n", | ||
" output_file_lookup = {(T, k): csv.DictWriter(open(csv_name_from_db(db_file_name, T, k), 'w'), fieldnames=table.columns) for T in Ts for k in ks}\n", | ||
" for f in output_file_lookup.values():\n", | ||
" f.writeheader()\n", | ||
" for row in table.all():\n", | ||
" try:\n", | ||
" output_file_lookup[(row['T'], row['direction'])].writerow(row)\n", | ||
" except KeyError:\n", | ||
" pass\n", | ||
" \n", | ||
"for db_file in db_files:\n", | ||
" \n", | ||
" export_from_db('sqlite:///' + \"to_export/\" + db_file)\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def csv_name_from_db(db_file_name, T):\n", | ||
" return \"./export_final/\" + db_file_name[10:-3] + str(T) + \".csv\"\n", | ||
"\n", | ||
"def export_from_db_no_ks(db_file_name):\n", | ||
" Ts = [10, 20, 30, 40, 50, 60, 70, 80]\n", | ||
" db = dataset.connect(db_file_name)\n", | ||
" table = db.load_table('recording')\n", | ||
" output_file_lookup = {(T): csv.DictWriter(open(csv_name_from_db(db_file_name, T), 'w'), fieldnames=table.columns) for T in Ts}\n", | ||
" for f in output_file_lookup.values():\n", | ||
" f.writeheader()\n", | ||
" for row in table.all():\n", | ||
" output_file_lookup[(row['T'])].writerow(row)\n", | ||
"\n", | ||
"export_from_db_no_ks('sqlite:///' +'before_leaving.db')\n", | ||
"export_from_db_no_ks('sqlite:///' +'before_leaving_after_adding_down.db')\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Binary file not shown.
Oops, something went wrong.