@@ -29,68 +29,56 @@ import org.jetbrains.kotlinx.kandy.letsplot.feature.layout
29
29
import org.jetbrains.kotlinx.kandy.letsplot.layers.bars
30
30
import org.junit.Ignore
31
31
import org.junit.Test
32
+ import java.net.URL
32
33
33
34
class QuickStartGuide : DataFrameSampleHelper (" quickstart" , " guides" ) {
34
35
35
36
@DataSchema
36
- interface Repositories : SelectedRepositories {
37
- val html_url: java.net. URL
37
+ interface Repositories {
38
+ val html_url: URL
38
39
val watchers: Int
39
- }
40
-
41
- @DataSchema
42
- interface SelectedRepositories {
43
40
val full_name: String
44
41
val stargazers_count: Int
45
42
val topics: String
46
43
}
47
44
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
-
70
45
private val df = DataFrame .readCsv(
71
46
" https://raw.githubusercontent.com/Kotlin/dataframe/master/data/jetbrains_repositories.csv" ,
72
47
).cast<Repositories >()
73
48
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 )
94
82
95
83
@Test
96
84
fun notebook_test_quickstart_2 () {
@@ -129,6 +117,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
129
117
130
118
@Test
131
119
fun notebook_test_quickstart_6 () {
120
+ val dfSelected = getDfSelected()
132
121
// SampleStart
133
122
// Keep only rows where "stargazers_count" value is more than 1000
134
123
val dfFiltered = dfSelected.filter { stargazers_count >= 1000 }
@@ -139,6 +128,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
139
128
140
129
@Test
141
130
fun notebook_test_quickstart_7 () {
131
+ val dfFiltered = getDfFiltered()
142
132
// SampleStart
143
133
// Rename "full_name" column into "name"
144
134
val dfRenamed = dfFiltered.rename { full_name }.into(" name" )
@@ -151,6 +141,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
151
141
152
142
@Test
153
143
fun notebook_test_quickstart_8 () {
144
+ val dfRenamed = getDfRenamed()
154
145
// SampleStart
155
146
val dfUpdated = dfRenamed
156
147
// Update "name" values with only its second part (after '/')
@@ -164,13 +155,15 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
164
155
165
156
@Test
166
157
fun notebook_test_quickstart_9 () {
158
+ val dfUpdated = getDfUpdated()
167
159
// SampleStart
168
160
dfUpdated.topics.type()
169
161
// SampleEnd
170
162
}
171
163
172
164
@Test
173
165
fun notebook_test_quickstart_10 () {
166
+ val dfUpdated = getDfUpdated()
174
167
// SampleStart
175
168
// Add a `Boolean` column indicating whether the `name` contains the "intellij" substring
176
169
// or the topics include "intellij".
@@ -184,14 +177,17 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
184
177
185
178
@Test
186
179
fun notebook_test_quickstart_11 () {
180
+ val dfWithIsIntellij = getDfWithIsIntellij()
187
181
// SampleStart
182
+ val groupedByIsIntellij = dfWithIsIntellij.groupBy { isIntellij }
188
183
groupedByIsIntellij
189
184
// SampleEnd
190
185
.saveDfHtmlSample()
191
186
}
192
187
193
188
@Test
194
189
fun notebook_test_quickstart_12 () {
190
+ val groupedByIsIntellij = getGroupedByIsIntellij()
195
191
// SampleStart
196
192
groupedByIsIntellij.count()
197
193
// SampleEnd
@@ -200,8 +196,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
200
196
201
197
@Test
202
198
fun notebook_test_quickstart_13 () {
203
- // issue #1454
204
- val groupedByIsIntellij = dfWithIsIntellij.groupBy { isIntellij }
199
+ val groupedByIsIntellij = getGroupedByIsIntellij()
205
200
// SampleStart
206
201
groupedByIsIntellij.aggregate {
207
202
// Compute sum and max of "starsCount" within each group into "sumStars" and "maxStars" columns
@@ -214,6 +209,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
214
209
215
210
@Test
216
211
fun notebook_test_quickstart_14 () {
212
+ val dfWithIsIntellij = getDfWithIsIntellij()
217
213
// SampleStart
218
214
val dfTop10 = dfWithIsIntellij
219
215
// Sort by "starsCount" value descending
@@ -225,6 +221,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
225
221
226
222
@Test
227
223
fun notebook_test_quickstart_16 () {
224
+ val dfTop10 = getDfTop10()
228
225
// SampleStart
229
226
dfTop10.plot {
230
227
bars {
@@ -241,6 +238,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
241
238
@Ignore
242
239
@Test
243
240
fun notebook_test_quickstart_17 () {
241
+ val dfWithIsIntellij = getDfWithIsIntellij()
244
242
// SampleStart
245
243
dfWithIsIntellij.writeExcel(" jb_repos.xlsx" )
246
244
// SampleEnd
0 commit comments