def load_game_sheet(season): """Loads season-specific data into task_options table in database. """ # Change Python path location to server/game folder. server_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.chdir(os.path.join(server_path, "season")) file = open(s_config.season(season, "gametasks.csv")) sheet = csv.reader(file) server.model.upsert.upsert_cols("task_options", { "task_name": "na", "type": "capability", "option_name": "na" }) def _insert_into_db(actor, task, claim, auto, teleop, finish, optionString): select = text( "INSERT INTO games (actor, task, claim, auto, teleop, finish) " "VALUES (:actor,:task,:claim,:auto,:teleop,:finish) " "ON CONFLICT (task) " "DO UPDATE " "SET actor=:actor, task=:task, claim=:claim, auto=:auto, " "teleop=:teleop, finish=:finish;") conn = server.model.connection.engine.connect() conn.execute(select, actor=actor, task=task, claim=claim, auto=auto, teleop=teleop, finish=finish) conn.close() server.model.upsert.upsert("tasks", "name", task) if optionString.strip(): optionNames = optionString.split('|') for optionName in optionNames: upsert_cols( "task_options", { 'task_name': task, 'type': 'capability', 'option_name': optionName.strip() }) for row in sheet: if row[0] != "actor": _insert_into_db(row[0], row[1], row[2], row[3], row[4], row[5], row[8])
def csvtasks(): with open(s_config.season(s_config.current_season, "gametasks.csv"), "r") as text: out = '' for line in text: if 'actor,task' not in line: task = Task(line) data = json.dumps(task, default=lambda o: o.__dict__, separators=(', ', ':'), sort_keys=True) out += data + '\n' return out
def load(self): with open( s_config.season(s_config.current_season, "observertasks.csv"), "r") as text: out = '' for line in text: if 'actor,observer' not in line: category = Section(line) data = json.dumps(category, default=lambda o: o.__dict__, separators=(', ', ':'), sort_keys=True) out += data + '\n' return out