Skip to content

Commit

Permalink
review example notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaume committed Aug 5, 2021
1 parent f4db465 commit b205a16
Show file tree
Hide file tree
Showing 12 changed files with 803 additions and 458 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@
"metadata": {},
"outputs": [],
"source": [
"cid = client.contributions.get_entries(\n",
" project=name, _fields=[\"id\", \"identifier\"]\n",
").result()[\"data\"][0][\"id\"]"
"all_ids = client.get_all_ids(\n",
" {\"project\": name}, include=[\"tables\"]\n",
").get(name, {})\n",
"cids = list(all_ids[\"ids\"])\n",
"tids = list(all_ids[\"tables\"][\"ids\"])\n",
"cids, tids"
]
},
{
Expand All @@ -149,7 +152,7 @@
"metadata": {},
"outputs": [],
"source": [
"contrib = client.get_contribution(cid)"
"client.get_contribution(cids[0])"
]
},
{
Expand All @@ -159,8 +162,7 @@
"metadata": {},
"outputs": [],
"source": [
"tid = contrib[\"tables\"][0][\"id\"]\n",
"table = client.get_table(tid) # pandas DataFrame"
"table = client.get_table(tids[0]) # pandas DataFrame"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "stopped-herald",
"metadata": {},
"outputs": [],
"source": [
"from mpcontribs.client import Client, Attachment\n",
"from pathlib import Path"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "electoral-usage",
"metadata": {},
"outputs": [],
"source": [
"name = \"sandbox\"\n",
"client = Client()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "banner-choice",
"metadata": {},
"outputs": [],
"source": [
"downloads = Path(\"/Users/patrick/Downloads\")\n",
"path_gz = downloads / \"2021-02-19_scan_mpids_changed.json.gz\"\n",
"path_img = downloads / \"IMG-20210224-WA0010.jpg\"\n",
"\n",
"attachment = Attachment.from_data(\"other\", {\"hello\": \"world\", \"test\": [1,2,4]})\n",
"\n",
"contributions = [{\n",
" \"project\": name,\n",
" \"identifier\": \"mp-2\",\n",
" \"attachments\": [path_gz, path_img, attachment]\n",
"}]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "utility-contest",
"metadata": {},
"outputs": [],
"source": [
"attachment.write(outdir=\"/Users/patrick/Downloads/\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "flush-speech",
"metadata": {},
"outputs": [],
"source": [
"client.delete_contributions(name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "forward-package",
"metadata": {},
"outputs": [],
"source": [
"client.submit_contributions(contributions)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bronze-client",
"metadata": {},
"outputs": [],
"source": [
"query = {\"project\": name}\n",
"client.get_totals(query=query)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "killing-veteran",
"metadata": {},
"outputs": [],
"source": [
"all_ids = client.get_all_ids(query=query, include=[\"attachments\"]).get(name)\n",
"md5s = list(all_ids[\"attachments\"][\"md5s\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "imposed-application",
"metadata": {},
"outputs": [],
"source": [
"attms = client.attachments.get_entries(md5__in=md5s, mime__contains=\"jpeg\", _fields=[\"id\"]).result()\n",
"aid = attms[\"data\"][0][\"id\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "rental-dublin",
"metadata": {},
"outputs": [],
"source": [
"a = client.get_attachment(aid)\n",
"a.display()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "invisible-criminal",
"metadata": {},
"outputs": [],
"source": [
"client.contributions.get_entries(project=name, _fields=[\"attachments\"]).result()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "instructional-north",
"metadata": {},
"outputs": [],
"source": [
"client.attachments.get_entries(_fields=[\"_all\"]).result()"
]
}
],
"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.9.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "lesbian-vegetarian",
"metadata": {},
"outputs": [],
"source": [
"from mpcontribs.client import Client"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "collaborative-physiology",
"metadata": {},
"outputs": [],
"source": [
"name = \"barin_tables\"\n",
"client = Client()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dominant-details",
"metadata": {},
"outputs": [],
"source": [
"client.get_project(name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "laughing-presence",
"metadata": {},
"outputs": [],
"source": [
"client.get_totals({\"project\": name})"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "accurate-singapore",
"metadata": {},
"outputs": [],
"source": [
"# col = \"SOLM21\"\n",
"# query = {f\"data__{col}__Ti__value__gte\": 0}\n",
"# client.contributions.get_entries(\n",
"# project=name, _fields=[\"identifier\", f\"data.{col}.Ti.value\"],\n",
"# **query\n",
"# ).result()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "nuclear-purpose",
"metadata": {},
"outputs": [],
"source": [
"all_ids = list(client.get_all_ids({\"project\": name}).get(name, {}).get(\"ids\", set()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "completed-tsunami",
"metadata": {},
"outputs": [],
"source": [
"tables = client.get_contribution(cid=all_ids[0]).get(\"tables\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "changing-plant",
"metadata": {},
"outputs": [],
"source": [
"t = client.get_table(tables[0][\"id\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "minus-beach",
"metadata": {},
"outputs": [],
"source": [
"t.display()"
]
}
],
"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.9.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit b205a16

Please sign in to comment.