|
5 | 5 | "id": "63c4b10f",
|
6 | 6 | "metadata": {},
|
7 | 7 | "source": [
|
8 |
| - "# Portal Inventory" |
| 8 | + "# Inventory Organizational Content" |
9 | 9 | ]
|
10 | 10 | },
|
11 | 11 | {
|
12 | 12 | "cell_type": "markdown",
|
13 | 13 | "id": "42a813b1",
|
14 | 14 | "metadata": {},
|
15 | 15 | "source": [
|
16 |
| - "Being able to retrieve, display, analyze, and export the content within an organization portal are important tasks for any admin. Here we will leverage the [ContentManager](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#contentmanager) and [UserManager](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#usermanager) classes of the GIS module, as well as some functionality from the [Pandas](https://pandas.pydata.org/docs/index.html) library, to accomplish those tasks.\n", |
| 16 | + "Being able to retrieve, display, analyze, and export the content within an organization Portal are important tasks for any admin. Here we will leverage the [ContentManager](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#contentmanager) and [UserManager](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#usermanager) classes of the GIS module, as well as some functionality from the [Pandas](https://pandas.pydata.org/docs/index.html) library, to accomplish those tasks.\n", |
17 | 17 | "\n",
|
18 | 18 | "In this page we are going to observe how the following can be accomplished:\n",
|
19 | 19 | "- [Import Libraries](#Import-Libraries)\n",
|
|
54 | 54 | "from arcgis.gis import GIS"
|
55 | 55 | ]
|
56 | 56 | },
|
57 |
| - { |
58 |
| - "cell_type": "code", |
59 |
| - "execution_count": 2, |
60 |
| - "id": "d8ce68a4", |
61 |
| - "metadata": {}, |
62 |
| - "outputs": [ |
63 |
| - { |
64 |
| - "data": { |
65 |
| - "text/plain": [ |
66 |
| - "'1.9.1'" |
67 |
| - ] |
68 |
| - }, |
69 |
| - "execution_count": 2, |
70 |
| - "metadata": {}, |
71 |
| - "output_type": "execute_result" |
72 |
| - } |
73 |
| - ], |
74 |
| - "source": [ |
75 |
| - "arcgis.__version__" |
76 |
| - ] |
77 |
| - }, |
78 | 57 | {
|
79 | 58 | "cell_type": "markdown",
|
80 | 59 | "id": "abca04ba",
|
|
141 | 120 | "id": "4ae14d15",
|
142 | 121 | "metadata": {},
|
143 | 122 | "source": [
|
144 |
| - "To search for content within our organization, we can access the [ContentManager](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager) class via gis.content. \n", |
| 123 | + "To search for content within our organization, we can access the [ContentManager](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager) class via `gis.content()`. \n", |
145 | 124 | "\n",
|
146 |
| - "Using the [advanced_search()](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager.advanced_search) method, we can query content belonging to a user by providing the string \"owner: < username >\". By setting the return_count parameter of advanced_search to True, we can simply return a single integer representing the number of items which that user owns.\n", |
| 125 | + "Using the [`advanced_search()`](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager.advanced_search) method, we can query content belonging to a user by providing the string `\"owner: < username >\"`. By setting the `return_count` parameter of `advanced_search()` to `True`, we can simply return a single integer representing the number of items which that user owns.\n", |
147 | 126 | "\n",
|
148 | 127 | "Let's return the number of items that belong to the user currently logged in:"
|
149 | 128 | ]
|
|
181 | 160 | "id": "55de05fb",
|
182 | 161 | "metadata": {},
|
183 | 162 | "source": [
|
184 |
| - "If we leave the return_count parameter as its default value False, then we will receive a response dictionary containing metadata about the query as well as a list of returned items in the 'results' field.\n", |
| 163 | + "If we leave the `return_count` parameter as its default value `False`, then we will receive a response dictionary containing metadata about the query as well as a list of returned items in the `results` field.\n", |
185 | 164 | "\n",
|
186 |
| - "By setting the max_items parameter, we can limit the number of items that are returned in the results field." |
| 165 | + "By setting the `max_items` parameter, we can limit the number of items that are returned in the `results` field." |
187 | 166 | ]
|
188 | 167 | },
|
189 | 168 | {
|
|
324 | 303 | "id": "d5435bc3",
|
325 | 304 | "metadata": {},
|
326 | 305 | "source": [
|
327 |
| - "It is also possible to have these items returned as dictionary objects by setting the as_dict parameter:" |
| 306 | + "It is also possible to have these items returned as dictionary objects by setting the `as_dict` parameter:" |
328 | 307 | ]
|
329 | 308 | },
|
330 | 309 | {
|
|
535 | 514 | "id": "339448aa",
|
536 | 515 | "metadata": {},
|
537 | 516 | "source": [
|
538 |
| - "The sort_field and sort_order parameters of the [advanced_search()](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager.advanced_search) method can be used to sort the returned content server side.\n", |
| 517 | + "The `sort_field` and `sort_order` parameters of the [`advanced_search()`](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.ContentManager.advanced_search) method can be used to sort the returned content server side.\n", |
539 | 518 | "\n",
|
540 |
| - "Possible values for sort_order are \"asc\" for ascending or increasing order and \"desc\" for descending or decreasing order. Default values for the sort_field and sort_order parameters are \"title\" and \"asc\", respectively.\n", |
| 519 | + "Possible values for `sort_order` are `\"asc\"` for ascending or increasing order and `\"desc\"` for descending or decreasing order. Default values for the `sort_field` and `sort_order` parameters are `\"title\"` and `\"asc\"`, respectively.\n", |
541 | 520 | "\n",
|
542 |
| - "In this next example we'll search for the last 3 items that the current user modified by setting sort_field=\"modified\" and sort_order=\"desc\":" |
| 521 | + "In this next example we'll search for the last 3 items that the current user modified by setting `sort_field=\"modified\"` and `sort_order=\"desc\"`:" |
543 | 522 | ]
|
544 | 523 | },
|
545 | 524 | {
|
|
643 | 622 | "id": "7ea4079f",
|
644 | 623 | "metadata": {},
|
645 | 624 | "source": [
|
646 |
| - "Here we return the first 3 items that the user created by setting sort_field=\"created\" and sort_order=\"asc\":" |
| 625 | + "Here we return the first 3 items that the user created by setting `sort_field=\"created\"` and `sort_order=\"asc\"`:" |
647 | 626 | ]
|
648 | 627 | },
|
649 | 628 | {
|
|
762 | 741 | "id": "0dd43cbc",
|
763 | 742 | "metadata": {},
|
764 | 743 | "source": [
|
765 |
| - "We can search for a list of the members within the organization by using the [UserManager](https://developers.arcgis.com/python/api-reference/arcgis.gis.server.html#arcgis.gis.server.UserManager) class within the GIS module. Here we access the UserManager by calling gis.users, and use the [search()](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.UserManager.search) method to return a list of organization members. The search() method will return all users in the organization if no parameters are provided:" |
| 744 | + "We can search for a list of the members within the organization by using the [UserManager](https://developers.arcgis.com/python/api-reference/arcgis.gis.server.html#arcgis.gis.server.UserManager) class within the GIS module. Here we access the UserManager by calling `gis.users`, and use the [`search()`](https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.UserManager.search) method to return a list of organization members. The `search()` method will return all users in the organization if no parameters are provided:" |
766 | 745 | ]
|
767 | 746 | },
|
768 | 747 | {
|
|
876 | 855 | "id": "ebb244c2",
|
877 | 856 | "metadata": {},
|
878 | 857 | "source": [
|
879 |
| - "Similarly to above, we can set return_count=True and see how many items this user has:" |
| 858 | + "Similarly to above, we can set `return_count=True` and see how many items this user has:" |
880 | 859 | ]
|
881 | 860 | },
|
882 | 861 | {
|
|
943 | 922 | "source": [
|
944 | 923 | "If we return all items for each user in the organization, we can compile those items into a single list representing all of the organizations content.\n",
|
945 | 924 | "\n",
|
946 |
| - "We can remove the item limit for each query by setting max_items=-1 in the advanced_search() function:" |
| 925 | + "We can remove the item limit for each query by setting `max_items=-1` in the `advanced_search()` function:" |
947 | 926 | ]
|
948 | 927 | },
|
949 | 928 | {
|
|
1228 | 1207 | "id": "3e3cb9ac",
|
1229 | 1208 | "metadata": {},
|
1230 | 1209 | "source": [
|
1231 |
| - "We can use the pandas function [value_counts()](https://pandas.pydata.org/docs/reference/api/pandas.Series.value_counts.html#pandas.Series.value_counts) to see how many occurrences there are of each value for a particular column. Here we return the top 10 most frequently occurring item types and the number of instances they have:" |
| 1210 | + "We can use the pandas function [`value_counts()`](https://pandas.pydata.org/docs/reference/api/pandas.Series.value_counts.html#pandas.Series.value_counts) to see how many occurrences there are of each value for a particular column. Here we return the top 10 most frequently occurring item types and the number of instances they have:" |
1232 | 1211 | ]
|
1233 | 1212 | },
|
1234 | 1213 | {
|
|
1268 | 1247 | "id": "25f3946f",
|
1269 | 1248 | "metadata": {},
|
1270 | 1249 | "source": [
|
1271 |
| - "Another [value_counts()](https://pandas.pydata.org/docs/reference/api/pandas.Series.value_counts.html#pandas.Series.value_counts) example where we see the distribution of access levels for each of the items in the organization:" |
| 1250 | + "Another [`value_counts()`](https://pandas.pydata.org/docs/reference/api/pandas.Series.value_counts.html#pandas.Series.value_counts) example where we see the distribution of access levels for each of the items in the organization:" |
1272 | 1251 | ]
|
1273 | 1252 | },
|
1274 | 1253 | {
|
|
1301 | 1280 | "id": "afb7847c",
|
1302 | 1281 | "metadata": {},
|
1303 | 1282 | "source": [
|
1304 |
| - "Using the [value_counts()](https://pandas.pydata.org/docs/reference/api/pandas.Series.value_counts.html#pandas.Series.value_counts) function in conjunction with the [groupby()](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.groupby.html) operation allows for an additional level of analysis. Here we see the breakdown of item types that each user has created:" |
| 1283 | + "Using the [`value_counts()`](https://pandas.pydata.org/docs/reference/api/pandas.Series.value_counts.html#pandas.Series.value_counts) function in conjunction with the [`groupby()`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.groupby.html) operation allows for an additional level of analysis. Here we see the breakdown of item types that each user has created:" |
1305 | 1284 | ]
|
1306 | 1285 | },
|
1307 | 1286 | {
|
|
1495 | 1474 | "id": "2d2c814c",
|
1496 | 1475 | "metadata": {},
|
1497 | 1476 | "source": [
|
1498 |
| - "Creating and applying Boolean masks is a very efficient way to the filter the rows of a DataFrame. By using standard operators such as <, >, == and != on pandas Series objects (e.g. the columns of our DataFrame), we can create a new Series of True and False values, called a mask. When this mask is applied to the original DataFrame, a new DataFrame will be returned with only the rows corresponding to where the mask had a True value.\n", |
| 1477 | + "Creating and applying Boolean masks is a very efficient way to the filter the rows of a DataFrame. By using standard operators such as `<`, `>`, `==` and `!=` on pandas Series objects (e.g. the columns of our DataFrame), we can create a new Series of `True` and `False` values, called a mask. When this mask is applied to the original DataFrame, a new DataFrame will be returned with only the rows corresponding to where the mask had a `True` value.\n", |
1499 | 1478 | "\n",
|
1500 | 1479 | "Let's create a mask to represent all items with public level access:"
|
1501 | 1480 | ]
|
|
1534 | 1513 | "id": "2fb3bef4",
|
1535 | 1514 | "metadata": {},
|
1536 | 1515 | "source": [
|
1537 |
| - "Applying this mask to our DataFrame, we return all fields for objects which have access=='public':" |
| 1516 | + "Applying this mask to our DataFrame, we return all fields for objects which have `access=='public'`:" |
1538 | 1517 | ]
|
1539 | 1518 | },
|
1540 | 1519 | {
|
|
1893 | 1872 | "id": "5a0345c2",
|
1894 | 1873 | "metadata": {},
|
1895 | 1874 | "source": [
|
1896 |
| - "Another example where we create a Boolean mask for all objects of type 'Web Map':" |
| 1875 | + "Another example where we create a Boolean mask for all objects of type `\"Web Map\"`:" |
1897 | 1876 | ]
|
1898 | 1877 | },
|
1899 | 1878 | {
|
|
2612 | 2591 | "id": "a893b341",
|
2613 | 2592 | "metadata": {},
|
2614 | 2593 | "source": [
|
2615 |
| - "The [.apply()](https://pandas.pydata.org/docs/reference/api/pandas.Series.apply.html) method can also be used to generate masks that can't be created using the standard comparison operators. As long as the function called within the apply method has a Boolean output, then the result can be used as a mask to filter rows. Here we use a [lambda](https://www.w3schools.com/python/python_lambda.asp) function to return all items which have a type that ends with the word \"Service\"." |
| 2594 | + "The [`apply()`](https://pandas.pydata.org/docs/reference/api/pandas.Series.apply.html) method can also be used to generate masks that can't be created using the standard comparison operators. As long as the function called within the apply method has a Boolean output, then the result can be used as a mask to filter rows. Here we use a [lambda](https://www.w3schools.com/python/python_lambda.asp) function to return all items which have a type that ends with the word \"Service\"." |
2616 | 2595 | ]
|
2617 | 2596 | },
|
2618 | 2597 | {
|
|
2798 | 2777 | "id": "736fa4d4",
|
2799 | 2778 | "metadata": {},
|
2800 | 2779 | "source": [
|
2801 |
| - "Once we've identified an item of interest in our DataFrame, we can return the content of that item by providing its ID to the [ContentManager](https://pandas.pydata.org/docs/reference/api/pandas.Series.apply.html) .get() method. If we know the index of the object in the DataFrame (i.e. the leftmost value), then we can access that row's information using the .loc() method. From there we can get the id of the item and provide it to the get method." |
| 2780 | + "Once we've identified an item of interest in our DataFrame, we can return the content of that item by providing its ID to the [ContentManager](https://pandas.pydata.org/docs/reference/api/pandas.Series.apply.html) `get()` method. If we know the index of the object in the DataFrame (i.e. the leftmost value), then we can access that row's information using the `loc()` method. From there we can get the id of the item and provide it to the get method." |
2802 | 2781 | ]
|
2803 | 2782 | },
|
2804 | 2783 | {
|
|
2894 | 2873 | "id": "548344fd",
|
2895 | 2874 | "metadata": {},
|
2896 | 2875 | "source": [
|
2897 |
| - "Pandas provides a convenient [to_csv()](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_csv.html) method which can be used to generate zipped and unzipped csv outputs. Simply provide your target path with the appropriate file extension and call the method on the DataFrame object you would like to export." |
| 2876 | + "Pandas provides a convenient [`to_csv()`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_csv.html) method which can be used to generate zipped and unzipped csv outputs. Simply provide your target path with the appropriate file extension and call the method on the DataFrame object you would like to export." |
2898 | 2877 | ]
|
2899 | 2878 | },
|
2900 | 2879 | {
|
|
2938 | 2917 | "id": "47157c31",
|
2939 | 2918 | "metadata": {},
|
2940 | 2919 | "source": [
|
2941 |
| - "Pandas also provides additional methods for exporting the data as different file formats (e.g. [to_json()](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_json.html), [to_pickle()](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_pickle.html), [to_excel()](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_excel.html)) which behave similarly." |
| 2920 | + "Pandas also provides additional methods for exporting the data as different file formats (e.g. [`to_json()`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_json.html), [`to_pickle()`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_pickle.html), [`to_excel()`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_excel.html)) which behave similarly." |
2942 | 2921 | ]
|
2943 | 2922 | }
|
2944 | 2923 | ],
|
2945 | 2924 | "metadata": {
|
2946 | 2925 | "kernelspec": {
|
2947 |
| - "display_name": "Python 3", |
| 2926 | + "display_name": "Python 3 (ipykernel)", |
2948 | 2927 | "language": "python",
|
2949 | 2928 | "name": "python3"
|
2950 | 2929 | },
|
|
2958 | 2937 | "name": "python",
|
2959 | 2938 | "nbconvert_exporter": "python",
|
2960 | 2939 | "pygments_lexer": "ipython3",
|
2961 |
| - "version": "3.7.11" |
| 2940 | + "version": "3.9.7" |
2962 | 2941 | }
|
2963 | 2942 | },
|
2964 | 2943 | "nbformat": 4,
|
|
0 commit comments