Skip to content

Commit

Permalink
fix(openchallenges): update static plot numbers (Sage-Bionetworks#2504)
Browse files Browse the repository at this point in the history
  • Loading branch information
vpchung authored Feb 16, 2024
1 parent 89e285e commit ff72e18
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public ChallengesPerYearDto getChallengesPerYear() {
Arrays.asList(
"2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017",
"2018", "2019", "2020", "2021", "2022", "2023", "2024");

// The following line will be auto-updated by a script and should NOT be modified manually.
List<Integer> challengeCounts =
/* AUTO-UPDATE MARKER */
Arrays.asList(6, 9, 13, 17, 23, 29, 34, 41, 49, 59, 86, 97, 116, 135, 184, 243, 306, 317);
Integer undatedChallengeCount = 171;

Expand Down
18 changes: 18 additions & 0 deletions apps/openchallenges/db-update/update_db_csv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import csv
import gspread
import numpy as np
Expand All @@ -7,6 +8,11 @@
GOOGLE_SHEET_TITLE = "OpenChallenges Data"
CHALLENGE_FOLDER = "apps/openchallenges/challenge-service/src/main/resources/db"
ORGANIZATION_FOLDER = "apps/openchallenges/organization-service/src/main/resources/db"
PLOT_FILE = (
"apps/openchallenges/challenge-service/src/main/java/org/sagebionetworks/"
"openchallenges/challenge/service/service/ChallengeAnalyticsService.java"
)
UPDATE_MARKER = r"(\/\* AUTO-UPDATE MARKER \*\/\s+)" # capture as a group to preserve


def output_csv(df, output_filename, output_folder="", print_row=False):
Expand Down Expand Up @@ -216,6 +222,18 @@ def main(gc):
output_csv(sub_types, "submission_types.csv",
output_folder=CHALLENGE_FOLDER, print_row=True)

# Update static plot numbers (displayed on homepage).
updated_plot_numbers = wks.worksheet("(plot) challenges_by_year").acell("D3").value
with open(PLOT_FILE, "r", encoding="utf-8") as file:
curr_content = file.read()
updated_content = re.sub(
UPDATE_MARKER + r"Arrays.asList\([\d, ]+\);",
r"\1" + updated_plot_numbers, # replace but keep reserved group (\1)
curr_content,
)
with open(PLOT_FILE, "w", encoding="utf-8") as file:
file.write(updated_content)


if __name__ == "__main__":
google_client = gspread.service_account(filename="service_account.json")
Expand Down

0 comments on commit ff72e18

Please sign in to comment.