@@ -29,66 +29,49 @@ 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://github.com/raw/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" )
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" )
77
57
// And "stargazers_count" into "starsCount"
78
58
.rename { stargazers_count }.into(" starsCount" )
79
- .cast< RenamedSelectedRepositories >()
80
- private val dfUpdated = dfRenamed
59
+
60
+ private fun getDfUpdated () = getDfRenamed()
81
61
// Update "name" values with only its second part (after '/')
82
62
.update { name }.with { it.split(" /" )[1 ] }
83
63
// Convert "topics" `String` values into `List<String>` by splitting:
84
64
.convert { topics }.with { it.removePrefix(" [" ).removeSuffix(" ]" ).split(" , " ) }
85
- .cast<UpdatedRepositories >()
86
65
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()
92
75
// Sort by "starsCount" value descending
93
76
.sortByDesc { starsCount }.take(10 )
94
77
@@ -129,6 +112,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
129
112
130
113
@Test
131
114
fun notebook_test_quickstart_6 () {
115
+ val dfSelected = getDfSelected()
132
116
// SampleStart
133
117
// Keep only rows where "stargazers_count" value is more than 1000
134
118
val dfFiltered = dfSelected.filter { stargazers_count >= 1000 }
@@ -139,6 +123,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
139
123
140
124
@Test
141
125
fun notebook_test_quickstart_7 () {
126
+ val dfFiltered = getDfFiltered()
142
127
// SampleStart
143
128
// Rename "full_name" column into "name"
144
129
val dfRenamed = dfFiltered.rename { full_name }.into(" name" )
@@ -151,6 +136,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
151
136
152
137
@Test
153
138
fun notebook_test_quickstart_8 () {
139
+ val dfRenamed = getDfRenamed()
154
140
// SampleStart
155
141
val dfUpdated = dfRenamed
156
142
// Update "name" values with only its second part (after '/')
@@ -164,13 +150,15 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
164
150
165
151
@Test
166
152
fun notebook_test_quickstart_9 () {
153
+ val dfUpdated = getDfUpdated()
167
154
// SampleStart
168
155
dfUpdated.topics.type()
169
156
// SampleEnd
170
157
}
171
158
172
159
@Test
173
160
fun notebook_test_quickstart_10 () {
161
+ val dfUpdated = getDfUpdated()
174
162
// SampleStart
175
163
// Add a `Boolean` column indicating whether the `name` contains the "intellij" substring
176
164
// or the topics include "intellij".
@@ -184,14 +172,17 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
184
172
185
173
@Test
186
174
fun notebook_test_quickstart_11 () {
175
+ val dfWithIsIntellij = getDfWithIsIntellij()
187
176
// SampleStart
177
+ val groupedByIsIntellij = dfWithIsIntellij.groupBy { isIntellij }
188
178
groupedByIsIntellij
189
179
// SampleEnd
190
180
.saveDfHtmlSample()
191
181
}
192
182
193
183
@Test
194
184
fun notebook_test_quickstart_12 () {
185
+ val groupedByIsIntellij = getGroupedByIsIntellij()
195
186
// SampleStart
196
187
groupedByIsIntellij.count()
197
188
// SampleEnd
@@ -200,8 +191,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
200
191
201
192
@Test
202
193
fun notebook_test_quickstart_13 () {
203
- // issue #1454
204
- val groupedByIsIntellij = dfWithIsIntellij.groupBy { isIntellij }
194
+ val groupedByIsIntellij = getGroupedByIsIntellij()
205
195
// SampleStart
206
196
groupedByIsIntellij.aggregate {
207
197
// Compute sum and max of "starsCount" within each group into "sumStars" and "maxStars" columns
@@ -214,6 +204,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
214
204
215
205
@Test
216
206
fun notebook_test_quickstart_14 () {
207
+ val dfWithIsIntellij = getDfWithIsIntellij()
217
208
// SampleStart
218
209
val dfTop10 = dfWithIsIntellij
219
210
// Sort by "starsCount" value descending
@@ -225,6 +216,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
225
216
226
217
@Test
227
218
fun notebook_test_quickstart_16 () {
219
+ val dfTop10 = getDfTop10()
228
220
// SampleStart
229
221
dfTop10.plot {
230
222
bars {
@@ -241,6 +233,7 @@ class QuickStartGuide : DataFrameSampleHelper("quickstart", "guides") {
241
233
@Ignore
242
234
@Test
243
235
fun notebook_test_quickstart_17 () {
236
+ val dfWithIsIntellij = getDfWithIsIntellij()
244
237
// SampleStart
245
238
dfWithIsIntellij.writeExcel(" jb_repos.xlsx" )
246
239
// SampleEnd
0 commit comments