{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "cereja_example.ipynb", "provenance": [], "collapsed_sections": [], "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": { "id": "8OIpCsdKwlet" }, "source": [ "#Install cereja" ] }, { "cell_type": "code", "metadata": { "id": "B1qNEuxZwVs_", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "799a0afe-6404-4615-a2b3-3a747f9878f0" }, "source": [ "!pip install cereja --upgrade" ], "execution_count": 1, "outputs": [ { "output_type": "stream", "text": [ "Collecting cereja\n", " Downloading cereja-1.4.9-py3-none-any.whl (103 kB)\n", "\u001B[K |████████████████████████████████| 103 kB 5.2 MB/s \n", "\u001B[?25hInstalling collected packages: cereja\n", "Successfully installed cereja-1.4.9\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "B-6AKLqiwuGR" }, "source": [ "#Import cereja" ] }, { "cell_type": "code", "metadata": { "id": "KhRIV54DxZ6Z", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "ce20312a-937d-4e2e-d0bd-f1314731c8da" }, "source": [ "import cereja as cj" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "\u001B[31m🍒\u001B[30m Using Cereja v.1.2.4\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "_FvoFjndxKIk" }, "source": [ "##Commons" ] }, { "cell_type": "markdown", "metadata": { "id": "2lxP-3C2tIZB" }, "source": [ "###is_iterable\n", "return whether an object is iterable or not." ] }, { "cell_type": "code", "metadata": { "id": "w_6TLC0DxI1f", "cellView": "both", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "124971da-dcee-4fd9-ac2b-e4aed35335be" }, "source": [ "my_var = [1,2,3] # change value and execute the cell\n", "cj.is_iterable(my_var)" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "True" ] }, "metadata": { "tags": [] }, "execution_count": 3 } ] }, { "cell_type": "code", "metadata": { "id": "bSJ69PuWiYGx", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "19e9e1f8-cd03-4f82-a2c5-84b77acb8cef" }, "source": [ "cj.is_iterable('hi')" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "True" ] }, "metadata": { "tags": [] }, "execution_count": 4 } ] }, { "cell_type": "markdown", "metadata": { "id": "rCjh0owqhhUb" }, "source": [ "###is_sequence\n", "\n", "Return whether an object a Sequence or not, exclude strings." ] }, { "cell_type": "code", "metadata": { "id": "tAPeDiyRhzWS", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "3a255b20-ec10-4f6e-e7a9-6cef52fb9b7d" }, "source": [ "cj.is_sequence([1,2,3])" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "True" ] }, "metadata": { "tags": [] }, "execution_count": 5 } ] }, { "cell_type": "code", "metadata": { "id": "QrFmt6iOicEL", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "0fbd306c-db30-4092-87be-a84fbbd43fcb" }, "source": [ "cj.is_sequence('hi')" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "False" ] }, "metadata": { "tags": [] }, "execution_count": 6 } ] }, { "cell_type": "markdown", "metadata": { "id": "q88o7iwCinDY" }, "source": [ "###theta_angle\n", "\n", "Calculates and returns theta angle between two vectors" ] }, { "cell_type": "code", "metadata": { "id": "f547KjDWisWw", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "cc9e87db-78f8-4c77-f3b4-f69faa3f9053" }, "source": [ "u = (2,2)\n", "v = (0, -2)\n", "cj.theta_angle(u, v)" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "135.0" ] }, "metadata": { "tags": [] }, "execution_count": 7 } ] }, { "cell_type": "markdown", "metadata": { "id": "Ho09h5KStktn" }, "source": [ "###group_items_in_batches\n", "responsible for grouping items in batch taking into account the quantity of items per batch" ] }, { "cell_type": "code", "metadata": { "id": "TXgvv3b2y1A9", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "903c77ac-6b69-45d9-f7ba-fa2d5ff58ba1" }, "source": [ "my_var = [1,2,3,4]\n", "num_items_per_batch = 4\n", "result = cj.group_items_in_batches(items=my_var, items_per_batch=num_items_per_batch)\n", "print(f\"items per batch with leftovers: {result}\")" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "items per batch with leftovers: [[1, 2, 3, 4]]\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "YWvTGuECtwHj", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "8088d51a-b232-48c0-f5ba-8aa57edc4e65" }, "source": [ "\"\"\"\n", "Note that the last batch does not contain the same number as the previous batch,\n", "this is due to the split split. You can choose to fill this void as in the example below.\n", "\"\"\"\n", "my_var = [1,2,3,4]\n", "num_items_per_batch = 3\n", "\n", "result = cj.group_items_in_batches(items=my_var, items_per_batch=num_items_per_batch, fill=\"cereja\")\n", "print(f\"fill values: {result}\")" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "fill values: [[1, 2, 3], [4, 'cereja', 'cereja']]\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "PPVLm9VNt3wj", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "e9aa25b9-cd9b-40d4-be07-41a0b14fd741" }, "source": [ "# Other examples\n", "result = cj.group_items_in_batches(items=['a','b','c','d'], items_per_batch=2)\n", "print(f\"Other examples: {result}\")" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "Other examples: [['a', 'b'], ['c', 'd']]\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "y7fcQ6WPuGkn" }, "source": [ "###remove_duplicate_items\n", "remove duplicates items in an item list or duplicate items list of list" ] }, { "cell_type": "code", "metadata": { "id": "M9lJN5t8AMvs", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "fd42c574-b60b-450e-fa3b-a7450bed4462" }, "source": [ "#simple list\n", "my_var = [1,2,3,4,4]\n", "result = cj.remove_duplicate_items(my_var)\n", "print(f\"simple list: {my_var} --> {result}\")" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "simple list: [1, 2, 3, 4, 4] --> [1, 2, 3, 4]\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "KUVj-_W0uXxa", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "d139e3de-8f78-40bd-9957-2adefe2b118a" }, "source": [ "#list of list\n", "my_var = [[1,2,3,4,4], [1,2,3,4,4]]\n", "result = cj.remove_duplicate_items(my_var)\n", "print(f\"list of list: {my_var} --> {result}\")" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "list of list: [[1, 2, 3, 4, 4], [1, 2, 3, 4, 4]] --> [[1, 2, 3, 4, 4]]\n" ], "name": "stdout" } ] }, { "cell_type": "code", "metadata": { "id": "vBPxDdzfujKO", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "2695517b-3316-4f11-8e67-19e14e625547" }, "source": [ "# other example\n", "my_var = [['hi'], ['hi'], ['ih']]\n", "result = cj.remove_duplicate_items(my_var)\n", "print(f\"other example: {my_var} --> {result}\")" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "other example: [['hi'], ['hi'], ['ih']] --> [['hi'], ['ih']]\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "KbsUISmOkRDD" }, "source": [ "###flatten\n", "\n", "Receives values, whether arrays of values, regardless of their shape and flatness" ] }, { "cell_type": "code", "metadata": { "id": "mxUDUIaGkV_o", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "7ae66909-70c9-41cd-c7d6-e83df6bcbb7c" }, "source": [ "sequence = [[1, 2, 3], [], [[2, [3], 4], 6]]\n", "cj.flatten(sequence)" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "[1, 2, 3, 2, 3, 4, 6]" ] }, "metadata": { "tags": [] }, "execution_count": 14 } ] }, { "cell_type": "code", "metadata": { "id": "5uK1e-rQxcTf", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "5f544938-cf88-4b5f-fcce-bd403b1c88cf" }, "source": [ "sequence = [[1, 2, 3], [], [[2, [3], 4], 6]]\n", "cj.flatten(sequence, max_recursion=2)" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "[1, 2, 3, 2, [3], 4, 6]" ] }, "metadata": { "tags": [] }, "execution_count": 15 } ] }, { "cell_type": "markdown", "metadata": { "id": "pzo5oUytvnsG" }, "source": [ "###Freq Class\n", "Enumerates the amount of identical intens generating a dictionary of frequencies. Where KEY is item - the original list's item - and VALUE is the total amount." ] }, { "cell_type": "markdown", "metadata": { "id": "qOn877TQxhKW" }, "source": [ "####instance of Freq" ] }, { "cell_type": "code", "metadata": { "id": "cNO-l7MKvlRG", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "0ae76256-b86f-47a7-a169-c3313854a3a4" }, "source": [ "# Instance\n", "freq = cj.Freq([1,2,3,3,4,5,6,7,6,7,12,31,123,5,3])\n", "print(freq)" ], "execution_count": null, "outputs": [ { "output_type": "stream", "text": [ "Freq({1: 1, 2: 1, 3: 3, 4: 1, 5: 2, 6: 2, 7: 2, 12: 1, 31: 1, 123: 1})\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "ddCDXmX0xmzD" }, "source": [ "####most_freq" ] }, { "cell_type": "markdown", "metadata": { "id": "MasIEXjPyD7P" }, "source": [ "returns the most frequent items from the list, the maximum number of items must be entered." ] }, { "cell_type": "code", "metadata": { "id": "Sp3jZx3KxYXO", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "944004b5-121b-4d65-f67e-15910c87ae3c" }, "source": [ "freq = cj.Freq([1,2,3,3,4,5,6,7,6,7,12,31,123,5,3])\n", "freq.most_common(4)" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "{3: 3, 5: 2, 6: 2, 7: 2}" ] }, "metadata": { "tags": [] }, "execution_count": 18 } ] }, { "cell_type": "markdown", "metadata": { "id": "aErkzjfoyUgj" }, "source": [ "####least_freq\n", "When returning the least frequent items from the list, the maximum number of items must be entered." ] }, { "cell_type": "code", "metadata": { "id": "aVkXduKezIYs", "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "outputId": "eb463062-8a06-4d60-d495-24924f3d21e8" }, "source": [ "freq = cj.Freq([1,2,3,3,4,5,6,7,6,7,12,31,123,5,3])\n", "freq.least_freq(4)" ], "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "{4: 1, 12: 1, 31: 1, 123: 1}" ] }, "metadata": { "tags": [] }, "execution_count": 19 } ] }, { "cell_type": "markdown", "metadata": { "id": "yxnOWQG8XUOA" }, "source": [ "###Progress\n", "A simple way to display progress to the user" ] }, { "cell_type": "markdown", "metadata": { "id": "0V7mg0nqi5Ot" }, "source": [ "####Example-1" ] }, { "cell_type": "code", "metadata": { "id": "YMWVgjjbXqYO", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "687f7df0-0b9a-4941-a0ab-3d41e9fb3309" }, "source": [ "import cereja as cj\n", "import time\n", "\n", "def process_data(i: int):\n", " # simulates some processing \n", " time.sleep(cj.rand_n()/max(abs(i), 1))\n", "\n", "my_iterable = range(1, 500)\n", "my_progress = cj.Progress(\"My Progress\")\n", "\n", "for i in my_progress(my_iterable):\n", " process_data(i)" ], "execution_count": 2, "outputs": [ { "output_type": "stream", "text": [ "\u001B[31m🍒\u001B[0;0m Using Cereja v.1.4.9\n", "\u001B[31m🍒\u001B[34m My Progress \u001B[36m»\u001B[0;0m \u001B[0;0m499/499 - [\u001B[38;5;2m▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰\u001B[0;0m] - 100.00% - 🕜 00:00:03 total - \u001B[38;5;2mDone! ✅\u001B[38;5;2m\u001B[0;0m \u001B[0;0m\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "a-QUB5_xi-Cc" }, "source": [ "####Custom Display" ] }, { "cell_type": "markdown", "metadata": { "id": "HqiI2fOHjeQB" }, "source": [ "Update the percentage by the end of the task" ] }, { "cell_type": "code", "metadata": { "id": "zizXGDXIZr2l", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "1e17857f-5a43-4507-a72f-ee6f3239a570" }, "source": [ "import cereja as cj\n", "import time\n", "\n", "progress = cj.Progress(\"My Progress\")\n", "print(progress)\n", "\n", "print(progress[0])\n", "print(progress[1])\n", "print(progress[2])\n", "\n", "class MyCustomState(cj.State):\n", " def display(self, current_value, max_value, *args, **kwargs):\n", " return f'{current_value} -> {max_value}'\n", " def done(self, *args, **kwargs):\n", " return f'FINISHED'\n", "\n", "progress[0] = MyCustomState\n", "\n", "for i in progress(range(1, 500)):\n", " time.sleep(1/i)" ], "execution_count": 4, "outputs": [ { "output_type": "stream", "text": [ "Progress('_StateValue', '_StateBar', '_StatePercent', '_StateTime')\n", "\u001B[31m🍒\u001B[34m Example States View \u001B[36m»\u001B[0;0m \u001B[0;0m100/100 - [\u001B[38;5;2m▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰\u001B[0;0m] - 100.00% - 🕜 -00:00:00 total - \u001B[38;5;2mDone! ✅\u001B[38;5;2m\u001B[0;0m \u001B[0;0m\n", "_StateValue field 100/100\n", "_StateBar field [\u001B[38;5;2m▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰\u001B[0;0m]\n", "_StatePercent field 100.00%\n", "\u001B[31m🍒\u001B[34m My Progress \u001B[36m»\u001B[0;0m \u001B[0;0mFINISHED - [\u001B[38;5;2m▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰\u001B[0;0m] - 100.00% - 🕜 00:00:06 total - \u001B[38;5;2mDone! ✅\u001B[38;5;2m\u001B[0;0m \u001B[0;0m\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "u-1kd_xH2Qw9" }, "source": [ "####Many tasks" ] }, { "cell_type": "code", "metadata": { "id": "gIHoEUgX2QCg", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "bdf9b891-9df3-4d45-fdff-f2e0105c9126" }, "source": [ "import time\n", "\n", "with cj.Progress(\"Progress Test\") as bar:\n", " time.sleep(5) # Awaiting data!\n", " for i in bar(range(1, 500), 'task-1'):\n", " time.sleep(1 / i)\n", " \n", " # in an abstract way we identified that the previous task ended.\n", " for i in bar(range(1, 400), 'task-2'):\n", " time.sleep(1 / i)" ], "execution_count": 5, "outputs": [ { "output_type": "stream", "text": [ "\u001B[31m🍒\u001B[34m Progress Test(task-2) \u001B[36m»\u001B[0;0m \u001B[0;0m399/399 - [\u001B[38;5;2m▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰\u001B[0;0m] - 100.00% - 🕜 00:00:06 total - \u001B[38;5;2mDone! ✅\u001B[38;5;2m\u001B[0;0m \u001B[0;0m\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "QcMtkhsCG32R" }, "source": [ "###FileTools\n", "Baseline of this" ] }, { "cell_type": "markdown", "metadata": { "id": "0ccuC2t6HE2l" }, "source": [ "####Basics Usage" ] }, { "cell_type": "code", "metadata": { "id": "2MN_3EiHHHsh", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "e08aea9d-d945-4ef4-ba7a-cabc1837507b" }, "source": [ "import cereja as cj\n", "\n", "data = ['how', 'are', 'you!']\n", "# Create new file\n", "file_ = cj.FileIO.create(\"/content/new_file.txt\", data)\n", "\n", "doc = f\"\"\"\n", ">>> file_ = cj.FileIO(\"/content/new_file.txt\", data)\n", "\n", ">>> file_\n", "{file_}\n", "\n", ">>> file_.size(unit='KB')\n", "{repr(file_.size(unit='KB'))}\n", "\n", ">>> file_.add(2, ['CerejaFile'])\n", "{file_.add(['CerejaFile'], 2)}\n", "\n", ">>> file_.data\n", "{repr(file_.data)}\n", "\n", ">>> file_.size(unit='KB')\n", "{repr(file_.size(unit='KB'))}\n", "\n", ">>> file_.dir_name\n", "{repr(file_.dir_name)}\n", "\n", ">>> file_.dir_path\n", "{repr(file_.dir_path)}\n", "\n", ">>> file_.ext\n", "{repr(file_.ext)}\n", "\n", ">>> file_.name\n", "{repr(file_.name)}\n", "\n", ">>> file_.name_without_ext\n", "{repr(file_.name_without_ext)}\n", "\n", ">>> file_.is_empty\n", "{repr(file_.is_empty)}\n", "\n", ">>> file_.line_sep\n", "{repr(file_.line_sep)}\n", "\n", ">>> file_.length\n", "{repr(file_.length)}\n", "\n", ">>> file_.path_\n", "{repr(file_.path)}\n", "\"\"\"\n", "print(doc)\n", "with cj.Progress('Saving File') as prog:\n", " file_.save()" ], "execution_count": 17, "outputs": [ { "output_type": "stream", "text": [ "\n", ">>> file_ = cj.FileIO(\"/content/new_file.txt\", data)\n", "\n", ">>> file_\n", "TXT\n", "\n", ">>> file_.size(unit='KB')\n", "0.056\n", "\n", ">>> file_.add(2, ['CerejaFile'])\n", "None\n", "\n", ">>> file_.data\n", "['how', 'are', 'CerejaFile', 'you!']\n", "\n", ">>> file_.size(unit='KB')\n", "0.088\n", "\n", ">>> file_.dir_name\n", "'content'\n", "\n", ">>> file_.dir_path\n", "/content\n", "\n", ">>> file_.ext\n", "'.txt'\n", "\n", ">>> file_.name\n", "'new_file.txt'\n", "\n", ">>> file_.name_without_ext\n", "'new_file'\n", "\n", ">>> file_.is_empty\n", "False\n", "\n", ">>> file_.line_sep\n", "'\\n'\n", "\n", ">>> file_.length\n", "4\n", "\n", ">>> file_.path_\n", "/content/new_file.txt\n", "\n", "\u001B[31m🍒\u001B[34m Saving File \u001B[36m»\u001B[0;0m \u001B[0;0m100/100 - [\u001B[38;5;2m▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰▰\u001B[0;0m] - 100.00% - 🕜 00:00:00 total - \u001B[38;5;2mDone! ✅\u001B[38;5;2m\u001B[0;0m \u001B[0;0m\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "SCpqGct6BCmn" }, "source": [ "##Decorators" ] }, { "cell_type": "markdown", "metadata": { "id": "5_RAxSJru0ZV" }, "source": [ "###time_exec\n", "used to signal or perform a particular function." ] }, { "cell_type": "code", "metadata": { "id": "8faV1ZV9BN1w", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "257f47bd-2c7a-4b13-9b98-6f0dfb0cc7c5" }, "source": [ "cj.set_log_level('INFO') # needed to see message \n", "@cj.decorators.time_exec\n", "def my_function(my_param): # Change-me\n", " print(my_param)\n", "\n", "my_function(\"Hi Cereja\")" ], "execution_count": 19, "outputs": [ { "output_type": "stream", "text": [ "INFO:cereja.utils._utils:Update log level to INFO\n", "Hi Cereja\n", "INFO:cereja.utils.decorators:[my_function] performed 0.00013065338134765625\n" ], "name": "stdout" } ] }, { "cell_type": "markdown", "metadata": { "id": "BJh-p9HmF0Q-" }, "source": [ "###deprecation\n", "used info deprecated func" ] }, { "cell_type": "code", "metadata": { "id": "TJZ4tEAuF9F-", "colab": { "base_uri": "https://localhost:8080/", "height": 89 }, "outputId": "6aaf9493-a05c-4f4a-a515-9531ad2ea779" }, "source": [ "@cj.decorators.depreciation(\"path.dotted.to.alternative\")\n", "def foo(bar: str):\n", " return f'Result of Foo -> {bar}'\n", "\n", "# simule user use func\n", "foo(\"Test\")" ], "execution_count": 21, "outputs": [ { "output_type": "stream", "text": [ "/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:6: DeprecationWarning: This function will be deprecated in future versions. You can use path.dotted.to.alternative\n", " \n" ], "name": "stderr" }, { "output_type": "execute_result", "data": { "application/vnd.google.colaboratory.intrinsic+json": { "type": "string" }, "text/plain": [ "'Result of Foo -> Test'" ] }, "metadata": { "tags": [] }, "execution_count": 21 } ] }, { "cell_type": "markdown", "metadata": { "id": "XTqMg2BqCutt" }, "source": [ "##Path" ] }, { "cell_type": "markdown", "metadata": { "id": "UtBVEmZAvFA8" }, "source": [ "###group_path_from_dir \n", "returns data tuples based on the number of items entered for each tuple,\n", "follows the default order if no sort function is sent" ] }, { "cell_type": "code", "metadata": { "id": "qxpaAczOCxCn", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "b3e1d16f-2274-41b5-e917-4429fc0d0fa8" }, "source": [ "\"\"\"\n", "group_path_from_dir function ...\n", "\n", "\"\"\"\n", "my_dir = '/content/sample_data'\n", "my_ext_file = '.csv'\n", "\n", "cj.group_path_from_dir(dir_path=my_dir, num_items_on_tuple=2, ext_file=my_ext_file)" ], "execution_count": 22, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "[['/content/sample_data/california_housing_test.csv',\n", " '/content/sample_data/california_housing_train.csv'],\n", " ['/content/sample_data/mnist_test.csv',\n", " '/content/sample_data/mnist_train_small.csv']]" ] }, "metadata": { "tags": [] }, "execution_count": 22 } ] }, { "cell_type": "markdown", "metadata": { "id": "ckTiv8_kvQAA" }, "source": [ "###file_name" ] }, { "cell_type": "code", "metadata": { "id": "qgiqJp8vEU-r", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "a2294393-c857-4005-d3e6-34d8a7020607" }, "source": [ "my_file_path = '/content/sample_data/california_housing_test.csv'\n", "result = cj.file_name(file_path=my_file_path)\n", "print(f\"file_path: {my_file_path} --> {result}\")\n", "\n", "# or with ext\n", "result = cj.file_name(file_path=my_file_path, with_ext=True)\n", "print(f\"file_path: {my_file_path} --> {result}\")" ], "execution_count": 23, "outputs": [ { "output_type": "stream", "text": [ "file_path: /content/sample_data/california_housing_test.csv --> california_housing_test\n", "file_path: /content/sample_data/california_housing_test.csv --> california_housing_test.csv\n" ], "name": "stdout" } ] } ] }