@@ -29,66 +29,49 @@ 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" )
49+ private fun getDfSelected () =
50+ df.select { full_name and stargazers_count and topics }
51+
52+ private fun getDfFiltered () = getDfSelected()
53+ .filter { stargazers_count >= 1000 }
54+
55+ private fun getDfRenamed () = getDfFiltered()
56+ .rename { full_name }.into(" name" )
7757 // And "stargazers_count" into "starsCount"
7858 .rename { stargazers_count }.into(" starsCount" )
79- .cast< RenamedSelectedRepositories >()
80- private val dfUpdated = dfRenamed
59+
60+ private fun getDfUpdated () = getDfRenamed()
8161 // Update "name" values with only its second part (after '/')
8262 .update { name }.with { it.split(" /" )[1 ] }
8363 // Convert "topics" `String` values into `List<String>` by splitting:
8464 .convert { topics }.with { it.removePrefix(" [" ).removeSuffix(" ]" ).split(" , " ) }
85- .cast<UpdatedRepositories >()
8665
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
66+ private fun getDfWithIsIntellij () = getDfUpdated()
67+ .add(" isIntellij" ) {
68+ name.contains(" intellij" ) || " intellij" in topics
69+ }
70+
71+ private fun getGroupedByIsIntellij () = getDfWithIsIntellij()
72+ .groupBy { isIntellij }
73+
74+ private fun getDfTop10 () = getDfWithIsIntellij()
9275 // Sort by "starsCount" value descending
9376 .sortByDesc { starsCount }.take(10 )
9477
@@ -129,6 +112,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
129112
130113 @Test
131114 fun notebook_test_quickstart_6 () {
115+ val dfSelected = getDfSelected()
132116 // SampleStart
133117 // Keep only rows where "stargazers_count" value is more than 1000
134118 val dfFiltered = dfSelected.filter { stargazers_count >= 1000 }
@@ -139,6 +123,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
139123
140124 @Test
141125 fun notebook_test_quickstart_7 () {
126+ val dfFiltered = getDfFiltered()
142127 // SampleStart
143128 // Rename "full_name" column into "name"
144129 val dfRenamed = dfFiltered.rename { full_name }.into(" name" )
@@ -151,6 +136,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
151136
152137 @Test
153138 fun notebook_test_quickstart_8 () {
139+ val dfRenamed = getDfRenamed()
154140 // SampleStart
155141 val dfUpdated = dfRenamed
156142 // Update "name" values with only its second part (after '/')
@@ -164,13 +150,15 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
164150
165151 @Test
166152 fun notebook_test_quickstart_9 () {
153+ val dfUpdated = getDfUpdated()
167154 // SampleStart
168155 dfUpdated.topics.type()
169156 // SampleEnd
170157 }
171158
172159 @Test
173160 fun notebook_test_quickstart_10 () {
161+ val dfUpdated = getDfUpdated()
174162 // SampleStart
175163 // Add a `Boolean` column indicating whether the `name` contains the "intellij" substring
176164 // or the topics include "intellij".
@@ -184,14 +172,17 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
184172
185173 @Test
186174 fun notebook_test_quickstart_11 () {
175+ val dfWithIsIntellij = getDfWithIsIntellij()
187176 // SampleStart
177+ val groupedByIsIntellij = dfWithIsIntellij.groupBy { isIntellij }
188178 groupedByIsIntellij
189179 // SampleEnd
190180 .saveDfHtmlSample()
191181 }
192182
193183 @Test
194184 fun notebook_test_quickstart_12 () {
185+ val groupedByIsIntellij = getGroupedByIsIntellij()
195186 // SampleStart
196187 groupedByIsIntellij.count()
197188 // SampleEnd
@@ -200,8 +191,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
200191
201192 @Test
202193 fun notebook_test_quickstart_13 () {
203- // issue #1454
204- val groupedByIsIntellij = dfWithIsIntellij.groupBy { isIntellij }
194+ val groupedByIsIntellij = getGroupedByIsIntellij()
205195 // SampleStart
206196 groupedByIsIntellij.aggregate {
207197 // Compute sum and max of "starsCount" within each group into "sumStars" and "maxStars" columns
@@ -214,6 +204,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
214204
215205 @Test
216206 fun notebook_test_quickstart_14 () {
207+ val dfWithIsIntellij = getDfWithIsIntellij()
217208 // SampleStart
218209 val dfTop10 = dfWithIsIntellij
219210 // Sort by "starsCount" value descending
@@ -225,6 +216,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
225216
226217 @Test
227218 fun notebook_test_quickstart_16 () {
219+ val dfTop10 = getDfTop10()
228220 // SampleStart
229221 dfTop10.plot {
230222 bars {
@@ -241,6 +233,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
241233 @Ignore
242234 @Test
243235 fun notebook_test_quickstart_17 () {
236+ val dfWithIsIntellij = getDfWithIsIntellij()
244237 // SampleStart
245238 dfWithIsIntellij.writeExcel(" jb_repos.xlsx" )
246239 // SampleEnd
0 commit comments