@@ -29,68 +29,56 @@ import org.jetbrains.kotlinx.kandy.letsplot.feature.layout
2929import org.jetbrains.kotlinx.kandy.letsplot.layers.bars
3030import org.junit.Ignore
3131import org.junit.Test
32+ import java.net.URL
3233
3334class QuickStartGuide : DataFrameSampleHelper (" quickstart" , " guides" ) {
3435
3536 @DataSchema
36- interface Repositories : SelectedRepositories {
37- val html_url: java.net. URL
37+ interface Repositories {
38+ val html_url: URL
3839 val watchers: Int
39- }
40-
41- @DataSchema
42- interface SelectedRepositories {
4340 val full_name: String
4441 val stargazers_count: Int
4542 val topics: String
4643 }
4744
48- @DataSchema
49- interface RenamedSelectedRepositories {
50- val name: String
51- val starsCount: Int
52- val topics: String
53- }
54-
55- @DataSchema
56- interface UpdatedRepositories {
57- val name: String
58- val starsCount: Int
59- val topics: List <String >
60- }
61-
62- @DataSchema
63- interface IsIntellijRepositories {
64- val name: String
65- val starsCount: Int
66- val topics: List <String >
67- val isIntellij: Boolean
68- }
69-
7045 private val df = DataFrame .readCsv(
7146 " https://raw.githubusercontent.com/Kotlin/dataframe/master/data/jetbrains_repositories.csv" ,
7247 ).cast<Repositories >()
7348
74- private val dfSelected = df.select { full_name and stargazers_count and topics }.cast<SelectedRepositories >()
75- private val dfFiltered = dfSelected.filter { stargazers_count >= 1000 }
76- private val dfRenamed = dfFiltered.rename { full_name }.into(" name" )
77- // And "stargazers_count" into "starsCount"
78- .rename { stargazers_count }.into(" starsCount" )
79- .cast<RenamedSelectedRepositories >()
80- private val dfUpdated = dfRenamed
81- // Update "name" values with only its second part (after '/')
82- .update { name }.with { it.split(" /" )[1 ] }
83- // Convert "topics" `String` values into `List<String>` by splitting:
84- .convert { topics }.with { it.removePrefix(" [" ).removeSuffix(" ]" ).split(" , " ) }
85- .cast<UpdatedRepositories >()
86-
87- private val dfWithIsIntellij = dfUpdated.add(" isIntellij" ) {
88- name.contains(" intellij" ) || " intellij" in topics
89- }.cast<IsIntellijRepositories >()
90- private val groupedByIsIntellij = dfWithIsIntellij.groupBy { isIntellij }
91- private val dfTop10 = dfWithIsIntellij
92- // Sort by "starsCount" value descending
93- .sortByDesc { starsCount }.take(10 )
49+ private fun getDfSelected () = df.select { full_name and stargazers_count and topics }
50+
51+ private fun getDfFiltered () =
52+ getDfSelected()
53+ .filter { stargazers_count >= 1000 }
54+
55+ private fun getDfRenamed () =
56+ getDfFiltered()
57+ .rename { full_name }.into(" name" )
58+ // And "stargazers_count" into "starsCount"
59+ .rename { stargazers_count }.into(" starsCount" )
60+
61+ private fun getDfUpdated () =
62+ getDfRenamed()
63+ // Update "name" values with only its second part (after '/')
64+ .update { name }.with { it.split(" /" )[1 ] }
65+ // Convert "topics" `String` values into `List<String>` by splitting:
66+ .convert { topics }.with { it.removePrefix(" [" ).removeSuffix(" ]" ).split(" , " ) }
67+
68+ private fun getDfWithIsIntellij () =
69+ getDfUpdated()
70+ .add(" isIntellij" ) {
71+ name.contains(" intellij" ) || " intellij" in topics
72+ }
73+
74+ private fun getGroupedByIsIntellij () =
75+ getDfWithIsIntellij()
76+ .groupBy { isIntellij }
77+
78+ private fun getDfTop10 () =
79+ getDfWithIsIntellij()
80+ // Sort by "starsCount" value descending
81+ .sortByDesc { starsCount }.take(10 )
9482
9583 @Test
9684 fun notebook_test_quickstart_2 () {
@@ -129,6 +117,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
129117
130118 @Test
131119 fun notebook_test_quickstart_6 () {
120+ val dfSelected = getDfSelected()
132121 // SampleStart
133122 // Keep only rows where "stargazers_count" value is more than 1000
134123 val dfFiltered = dfSelected.filter { stargazers_count >= 1000 }
@@ -139,6 +128,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
139128
140129 @Test
141130 fun notebook_test_quickstart_7 () {
131+ val dfFiltered = getDfFiltered()
142132 // SampleStart
143133 // Rename "full_name" column into "name"
144134 val dfRenamed = dfFiltered.rename { full_name }.into(" name" )
@@ -151,6 +141,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
151141
152142 @Test
153143 fun notebook_test_quickstart_8 () {
144+ val dfRenamed = getDfRenamed()
154145 // SampleStart
155146 val dfUpdated = dfRenamed
156147 // Update "name" values with only its second part (after '/')
@@ -164,13 +155,15 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
164155
165156 @Test
166157 fun notebook_test_quickstart_9 () {
158+ val dfUpdated = getDfUpdated()
167159 // SampleStart
168160 dfUpdated.topics.type()
169161 // SampleEnd
170162 }
171163
172164 @Test
173165 fun notebook_test_quickstart_10 () {
166+ val dfUpdated = getDfUpdated()
174167 // SampleStart
175168 // Add a `Boolean` column indicating whether the `name` contains the "intellij" substring
176169 // or the topics include "intellij".
@@ -184,14 +177,17 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
184177
185178 @Test
186179 fun notebook_test_quickstart_11 () {
180+ val dfWithIsIntellij = getDfWithIsIntellij()
187181 // SampleStart
182+ val groupedByIsIntellij = dfWithIsIntellij.groupBy { isIntellij }
188183 groupedByIsIntellij
189184 // SampleEnd
190185 .saveDfHtmlSample()
191186 }
192187
193188 @Test
194189 fun notebook_test_quickstart_12 () {
190+ val groupedByIsIntellij = getGroupedByIsIntellij()
195191 // SampleStart
196192 groupedByIsIntellij.count()
197193 // SampleEnd
@@ -200,8 +196,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
200196
201197 @Test
202198 fun notebook_test_quickstart_13 () {
203- // issue #1454
204- val groupedByIsIntellij = dfWithIsIntellij.groupBy { isIntellij }
199+ val groupedByIsIntellij = getGroupedByIsIntellij()
205200 // SampleStart
206201 groupedByIsIntellij.aggregate {
207202 // Compute sum and max of "starsCount" within each group into "sumStars" and "maxStars" columns
@@ -214,6 +209,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
214209
215210 @Test
216211 fun notebook_test_quickstart_14 () {
212+ val dfWithIsIntellij = getDfWithIsIntellij()
217213 // SampleStart
218214 val dfTop10 = dfWithIsIntellij
219215 // Sort by "starsCount" value descending
@@ -225,6 +221,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
225221
226222 @Test
227223 fun notebook_test_quickstart_16 () {
224+ val dfTop10 = getDfTop10()
228225 // SampleStart
229226 dfTop10.plot {
230227 bars {
@@ -241,6 +238,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
241238 @Ignore
242239 @Test
243240 fun notebook_test_quickstart_17 () {
241+ val dfWithIsIntellij = getDfWithIsIntellij()
244242 // SampleStart
245243 dfWithIsIntellij.writeExcel(" jb_repos.xlsx" )
246244 // SampleEnd
0 commit comments