Skip to content

Commit

Permalink
fix error in downloading mapping files from jupyter notebook #133
Browse files Browse the repository at this point in the history
  • Loading branch information
bl-young committed Jun 26, 2024
1 parent 963c035 commit d68664d
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions Jupyter/run_mappings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,24 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"## Step 1\n",
"import pandas as pd\n",
"import fedelemflowlist\n",
"from fedelemflowlist.globals import flowmappingpath, flowmapping_fields\n",
"import os\n",
"from pathlib import Path\n",
"import ipywidgets as widgets\n",
"from IPython.display import display, FileLink\n",
"\n",
"if not os.path.exists('./scratch'):\n",
" os.mkdir('./scratch')\n",
"\n",
"uploader = widgets.FileUpload(\n",
" accept = '.csv'\n",
" ,multiple = False\n",
" accept = '.csv',\n",
" multiple = False\n",
")\n",
"\n",
"display(uploader)"
Expand All @@ -59,14 +58,14 @@
"if not uploader.value:\n",
" raise ValueError('Input Excel file is required to continue. Make sure to select the Upload button above before continuing.')\n",
"\n",
"input_file = next(iter(uploader.value))\n",
"input_full = r\"./scratch/\" + input_file\n",
"input_file = uploader.value[0]\n",
"input_full = r\"./scratch/\" + input_file['name']\n",
"\n",
"if os.path.exists(input_full):\n",
" os.remove(input_full)\n",
" \n",
"with open(input_full,\"wb\") as fp:\n",
" fp.write(uploader.value[input_file]['content'])\n",
" fp.write(input_file['content'])\n",
"\n",
"mapping = pd.read_csv(input_full)\n",
"mapping_length = len(mapping)\n",
Expand Down Expand Up @@ -126,17 +125,27 @@
"#Subset all flows to get just those used in selected mapping\n",
"flows_used_in_mapping = pd.merge(all_flows,mapping_flow_uuids)\n",
"\n",
"fedelemflowlist.write_jsonld(flows_used_in_mapping,output_full,mapping_w_conversion)\n",
"print(\"mapping file created as json\")\n",
"download = FileLink(output_full,result_html_prefix=\"Click here to download: \")\n",
"display(download)\n"
"fedelemflowlist.write_jsonld(flows = flows_used_in_mapping,\n",
" path = Path(output_full),\n",
" mappings = mapping_w_conversion)\n",
"print(\"mapping file created as json\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%html\n",
"<a href=\"scratch/flows_w_mappings.zip\" download=\"flows_w_mappings.zip\">Download Mapping File</a>"
]
}
],
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -150,7 +159,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.5"
"version": "3.12.3"
}
},
"nbformat": 4,
Expand Down

0 comments on commit d68664d

Please sign in to comment.