{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Kotlin/JVM package dependencies + imports\n", "Note: this notebook was updated July 2021 to point to newer versions of its dependencies, which had become deprecated and were not allowing the notebook to complete successfully. No code has been changed.\n", "\n", "We pull in lets-plot with `%use`, which automatically sets up rich output\n", "\n", "Fuel is 'officially supported' but was causing some problems. Anyway we need to manually import jsoup and moshi, they aren't supported by Kotlin-Jupyter." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "@file:Repository(\"https://repo1.maven.org/maven2/\")\n", "@file:DependsOn(\"com.github.kittinunf.fuel:fuel:2.2.3\")\n", "@file:DependsOn(\"com.github.kittinunf.fuel:fuel-coroutines:2.2.3\")\n", "@file:DependsOn(\"org.jsoup:jsoup:1.13.1\")\n", "@file:DependsOn(\"com.squareup.moshi:moshi-kotlin:1.9.3\")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "import java.io.File\n", "import kotlinx.coroutines.*\n", "import com.github.kittinunf.result.Result\n", "import com.github.kittinunf.fuel.Fuel\n", "import com.github.kittinunf.fuel.core.FuelManager\n", "import com.github.kittinunf.fuel.coroutines.*\n", "import org.jsoup.Jsoup\n", "import org.jsoup.nodes.Document\n", "import com.squareup.moshi.*" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%use lets-plot, krangl" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### define our classes\n", "Note that normally we could simply annotate each class with `@JsonClass` to tell Moshi to auto-build Json adapters.\n", " I don't believe that's possible with Kotlin-Jupyter (happy to be wrong about this) so we will create adapters by hand" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "// @JsonClass(generateAdapter = true)\n", "data class ScoringPlay(\n", " val quarter : Int,\n", " val timeString : String,\n", " val secondsElapsed : Int,\n", " val team : String,\n", " val detail : String,\n", " val awayscore : Int,\n", " val homescore : Int\n", ")\n", "\n", "// @JsonClass(generateAdapter = true)\n", "data class PFRWeek(val season : Int, val weeknumber : Int, val pfrURLs : List