Skip to content

Commit

Permalink
feat: grouping sheets in directories
Browse files Browse the repository at this point in the history
  • Loading branch information
1grzyb1 committed Sep 18, 2024
1 parent 999446a commit f97f310
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ dependencies {
implementation("com.google.apis:google-api-services-drive:v3-rev20220815-2.0.0")
implementation("com.google.apis:google-api-services-sheets:v4-rev20220927-2.0.0")
implementation("com.google.auth:google-auth-library-oauth2-http:1.19.0")
implementation("org.postgresql:postgresql:42.2.23")

runtimeOnly("org.postgresql:postgresql:42.3.8")
runtimeOnly("com.h2database:h2:1.4.200")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/odyseja/odysejapka/drive/DriveAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ class DriveAdapter(
file.parents = listOf(destination)
return service.Files().copy(fileId, file).execute()
}

fun createFolder(folderName: String, parentDir: String): String {
val fileMetadata = File()
fileMetadata.name = folderName
fileMetadata.mimeType = "application/vnd.google-apps.folder"
fileMetadata.parents = listOf(parentDir)
return service.files().create(fileMetadata).execute().id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class ZspSheetsAdapter(
return cell.lowercase().contains("sobota") || cell.lowercase().contains("niedziela")
}

private fun isStage(cell: String): Boolean {
fun isStage(cell: String): Boolean {
return cell.lowercase().contains("scena")
}
}
12 changes: 12 additions & 0 deletions src/main/kotlin/odyseja/odysejapka/gad/GadGroup.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package odyseja.odysejapka.gad

data class GadGroup(val problem: Int, val age: Int, val part: String) {
fun getDirName(): String {
val suffix = if (part == "") {
""
} else {
"_$part"
}
return "P${problem}G${age}$suffix"
}
}
8 changes: 7 additions & 1 deletion src/main/kotlin/odyseja/odysejapka/gad/GadRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import com.google.api.services.sheets.v4.model.Sheet
import odyseja.odysejapka.async.Runner
import odyseja.odysejapka.drive.DriveAdapter
import odyseja.odysejapka.drive.ZspSheetsAdapter
import odyseja.odysejapka.gad.GadGroup
import java.util.concurrent.atomic.AtomicInteger

internal class GadRunner(
Expand All @@ -16,6 +17,7 @@ internal class GadRunner(
private val templates = getTemplates()
private var totalSheetCount = 1
private var processedSheetCount = AtomicInteger(0)
private val groupFolders = mutableMapOf<GadGroup, String>()

override fun run() {
val sheets = sheetsAdapter.getSheets()
Expand Down Expand Up @@ -47,9 +49,13 @@ internal class GadRunner(
continue
}

val groupFolderId = groupFolders.computeIfAbsent(team.getGroup()) {
driveAdapter.createFolder(it.getDirName(), destinationFolderId)
}

val template = getTemplate(team.getProblem()[0])

val file = driveAdapter.copyFile(template.id, team.getFileName(), destinationFolderId)
val file = driveAdapter.copyFile(template.id, team.getFileName(), groupFolderId)
templateCell(file.id, "A1", team.getAge())
templateCell(file.id, "A2", team.teamName)
templateCell(file.id, "A3", teams.judges)
Expand Down
11 changes: 10 additions & 1 deletion src/main/kotlin/odyseja/odysejapka/gad/Team.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import odyseja.odysejapka.gad.GadGroup
import odyseja.odysejapka.timetable.Performance

data class Team(
Expand Down Expand Up @@ -60,7 +61,7 @@ data class Team(
part.toInt(),
day.lowercase(),
getSpontanDay(),
if (league != "0") league else "",
getFormattedLeague(),
zspRow = zspRow,
zspSheet = zspSheet
)
Expand All @@ -76,4 +77,12 @@ data class Team(
fun isJunior(): Boolean {
return code[1] == 'J'
}

fun getGroup(): GadGroup {
return GadGroup(getProblem().toInt(), getAge().toInt(), getFormattedLeague())
}

private fun getFormattedLeague(): String {
return if (league == "0") "" else league
}
}

0 comments on commit f97f310

Please sign in to comment.