{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "Use_OpenLA_in_Colab.ipynb", "provenance": [], "collapsed_sections": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" }, "pycharm": { "stem_cell": { "cell_type": "raw", "source": [], "metadata": { "collapsed": false } } } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "a1OO-Fc7m0m_" }, "source": [ "# Use OpenLA in Google Colaboratory" ] }, { "cell_type": "markdown", "metadata": { "id": "MGktwESelwlh" }, "source": [ "### Install OpenLA" ] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "9p7vEXopKcGf", "outputId": "d97f04b0-94a0-45e2-a4da-e6b72e058ad4" }, "source": [ "!pip install OpenLA" ], "execution_count": 1, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Collecting OpenLA\n", " Downloading OpenLA-0.2.2-py3-none-any.whl (23 kB)\n", "Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from OpenLA) (3.2.2)\n", "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from OpenLA) (1.19.5)\n", "Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from OpenLA) (1.1.5)\n", "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->OpenLA) (3.0.6)\n", "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->OpenLA) (2.8.2)\n", "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->OpenLA) (0.11.0)\n", "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->OpenLA) (1.3.2)\n", "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.1->matplotlib->OpenLA) (1.15.0)\n", "Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.7/dist-packages (from pandas->OpenLA) (2018.9)\n", "Installing collected packages: OpenLA\n", "Successfully installed OpenLA-0.2.2\n" ] } ] }, { "cell_type": "markdown", "metadata": { "id": "um3rYC3el8Ta" }, "source": [ "### Import OpenLA" ] }, { "cell_type": "code", "metadata": { "id": "D8qgGowKKjI_" }, "source": [ "import OpenLA as la" ], "execution_count": 2, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "C5nheXMAmBsK" }, "source": [ "### Mount google drive" ] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "u1FHI1OvKwFP", "outputId": "f7473fb1-295a-4ecd-c1fa-667dc409a741" }, "source": [ "from google.colab import drive\n", "drive.mount('/content/drive')" ], "execution_count": 3, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Mounted at /content/drive\n" ] } ] }, { "cell_type": "markdown", "metadata": { "id": "hzSPVtL-mEK2" }, "source": [ "If you have uploaded the dataset of the course A to 'data' directory in GoogleDrive, the dataset files belong to '/content/drive/MyDrive/data' " ] }, { "cell_type": "code", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "QI352hQRiVIh", "outputId": "3b071ac8-0a83-4f9c-afb0-a57c71cfe406" }, "source": [ "ls /content/drive/MyDrive/data" ], "execution_count": 4, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Course_A_EventStream.csv Course_A_LectureMaterial.csv Course_A_QuizScore.csv\n", "Course_A_GradePoint.csv Course_A_LectureTime.csv\n" ] } ] }, { "cell_type": "markdown", "metadata": { "id": "vx7SupApm-46" }, "source": [ "### Load course data from google drive ('/content/drive/MyDrive/data')" ] }, { "cell_type": "code", "metadata": { "id": "AuHIIUFnL1xv" }, "source": [ "course_info, event_stream = la.start_analysis(files_dir=\"/content/drive/MyDrive/data\",\n", " course_id=\"A\")" ], "execution_count": 5, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "VtTLlyjWoapC" }, "source": [ "or" ] }, { "cell_type": "code", "metadata": { "id": "eVvAt5bGoaFI" }, "source": [ "course_info, event_stream = la.start_analysis(event_stream_file=\"/content/drive/MyDrive/data/Course_A_EventStream.csv\",\n", " lecture_material_file=\"/content/drive/MyDrive/data/Course_A_LectureMaterial.csv\", \n", " lecture_time_file=\"/content/drive/MyDrive/data/Course_A_LectureTime.csv\",\n", " # quiz_score_file=\"/content/drive/MyDrive/data/Course_A_QuizScore.csv\", # in this code, quiz score and grade point is not needed\n", " # grade_point_file=\"/content/drive/MyDrive/data/Course_A_GradePoint.csv\"\n", " )" ], "execution_count": 6, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "mUedOFPJnurE" }, "source": [ "### Get reading time for contents \"C1\" and \"C2\" outside of lecture 2" ] }, { "cell_type": "code", "metadata": { "id": "Kn6Z_AzuO1gY" }, "source": [ "# event stream before lecture 2 started\n", "events_before_lecture2 = la.select_by_lecture_time(course_info=course_info, \n", " event_stream=event_stream,\n", " lecture_week=2,\n", " timing=\"before\",\n", " extension_minutes_before_lecture=0,\n", " extension_minutes_after_lecture=0,\n", " include_other_lecture_time=False)\n", "\n", "# event stream after lecture 2 ended\n", "events_after_lecture2 = la.select_by_lecture_time(course_info=course_info, \n", " event_stream=event_stream,\n", " lecture_week=2,\n", " timing=\"after\",\n", " extension_minutes_before_lecture=0,\n", " extension_minutes_after_lecture=10,\n", " include_other_lecture_time=False)\n", "\n", "# concatenate the event stream before/after lecture 2\n", "events_out_lecture2 = la.concat_data([events_before_lecture2, events_after_lecture2])\n", "\n", "# calculate reading time outside of lecture 2\n", "reading_time, pagewise_aggregation = la.individual_reading_time(event_stream=events_out_lecture2,\n", " user_id=None,\n", " contents_id=[\"C1\", \"C2\"],\n", " invalid_seconds=5,\n", " timeout_seconds=20*60,\n", " return_aggregation_result=True,\n", " time_unit=\"minutes\",\n", " for_each_content=True \n", " )" ], "execution_count": 7, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "F_F38Sy9YkK3", "colab": { "base_uri": "https://localhost:8080/", "height": 455 }, "outputId": "3a193e21-c0da-4c57-9e59-cc29b463bc90" }, "source": [ "reading_time" ], "execution_count": 8, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
| \n", " | \n", " | reading_minutes | \n", "
|---|---|---|
| userid | \n", "contentsid | \n", "\n", " |
| A_U1 | \n", "C1 | \n", "2.750000 | \n", "
| C2 | \n", "3.350000 | \n", "|
| A_U10 | \n", "C1 | \n", "11.633333 | \n", "
| C2 | \n", "0.466667 | \n", "|
| A_U100 | \n", "C1 | \n", "43.966667 | \n", "
| ... | \n", "... | \n", "... | \n", "
| A_U97 | \n", "C2 | \n", "20.183333 | \n", "
| A_U98 | \n", "C1 | \n", "4.450000 | \n", "
| C2 | \n", "36.166667 | \n", "|
| A_U99 | \n", "C1 | \n", "8.800000 | \n", "
| C2 | \n", "4.200000 | \n", "
220 rows × 1 columns
\n", "