diff options
author | emkael <emkael@tlen.pl> | 2020-10-08 22:33:25 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2020-10-08 22:33:25 +0200 |
commit | bdff54b0ccbee5753e3756bb2a592813aeab7671 (patch) | |
tree | cad20e2267aa9ef9faa497c5999f1a30ca403717 /butler | |
parent | d0f4f64a6f946d56a5a7304eb07edda66e725b4b (diff) |
Butler merge script
Diffstat (limited to 'butler')
-rw-r--r-- | butler/butler.py | 91 | ||||
-rw-r--r-- | butler/config.json | 46 |
2 files changed, 137 insertions, 0 deletions
diff --git a/butler/butler.py b/butler/butler.py new file mode 100644 index 0000000..36022e0 --- /dev/null +++ b/butler/butler.py @@ -0,0 +1,91 @@ +from __future__ import print_function +import json, os, sys + +config = json.load(open(os.path.join( + os.path.dirname(__file__), + 'config.json'))) + +butler_set = sys.argv[1] + +if butler_set not in config: + sys.exit() + +groups = config.get('__groups', {}) +queries = config.get('__queries', {}) + +config = config[butler_set] + +TABL_STEP = 8 +TEAM_STEP = 16 +PLAYER_STEP = 400 + +tabl_offset = 0 +team_offset = 0 +player_offset = 0 + +for s_db in config['source']: + print('USE %s;' % (s_db)) + for table in ['matches', 'players', 'scores', 'teams', 'segments']: + print('DROP TABLE IF EXISTS _%s;' % (table)) + print('CREATE TABLE _%s AS SELECT * FROM %s;' % (table, table)) + if s_db in queries: + for q in queries[s_db]: + print(q) + print( + 'UPDATE _matches SET tabl=tabl+%d, homet=homet+%d, visit=visit+%d;' % ( + tabl_offset, team_offset, team_offset) + ) + print( + 'UPDATE _players SET id=id+%d, team=team+%d;' % ( + player_offset, team_offset) + ) + print ( + 'UPDATE _scores SET tabl=tabl+%d;' % ( + tabl_offset) + ) + print ( + 'UPDATE _teams SET id=id+%d;' % ( + team_offset) + ) + print( + '''UPDATE _segments SET tabl=tabl+%d, homet=homet+%d, visit=visit+%d, + openN=openN+%d, openE=openE+%d, openS=openS+%d, openW=openW+%d, + closeN=closeN+%d, closeE=closeE+%d, closeS=closeS+%d, closeW=closeW+%d;''' % ( + tabl_offset, team_offset, team_offset, + player_offset, player_offset, player_offset, player_offset, + player_offset, player_offset, player_offset, player_offset) + ) + tabl_offset += TABL_STEP + team_offset += TEAM_STEP + player_offset += PLAYER_STEP + +print('USE %s;' % (config['output'])) + +print('UPDATE admin SET teamcnt=%d, butler=%d;' % ( + 16*len(config['source']), 4*len(config['source']) +)) + +print('UPDATE teams SET bye=2;') + +print('DELETE FROM butler;') + +for table in ['boards', 'rounds']: + print('DELETE FROM %s;' % (table)) + print('INSERT INTO %s SELECT * FROM %s.%s;' % ( + table, config['source'][0], table)) + +for table in ['matches', 'players', 'scores', 'segments']: + print('DELETE FROM %s;' % (table)) + for s_db in config['source']: + print('INSERT INTO %s SELECT * FROM %s._%s;' % ( + table, s_db, table)) + +print('DELETE FROM teams;') +for idx, s_db in enumerate(config['source']): + print("INSERT INTO teams (id,fullname,shortname,grupa,bye) SELECT id,fullname,CONCAT('%s: ',shortname),%d,bye FROM %s._teams;" % ( + groups[s_db], idx+1, s_db)) + +print('UPDATE admin SET rnd=%d, segm=%d;' % ( + int(os.environ.get('LIGA_BUTLER_FINISHED_ROUND', 0)), + int(os.environ.get('LIGA_BUTLER_FINISHED_SEGMENT', 0)) +)) diff --git a/butler/config.json b/butler/config.json new file mode 100644 index 0000000..eea10ba --- /dev/null +++ b/butler/config.json @@ -0,0 +1,46 @@ +{ + "1+2": { + "source": [ + "dmp202021_1s", + "dmp202021_2se", + "dmp202021_2sw", + "dmp202021_2ne", + "dmp202021_2nw" + ], + "output": "dmp202021_b_0" + }, + "1": { + "source": [ + "dmp202021_1s" + ], + "output": "dmp202021_b_1" + }, + "2": { + "source": [ + "dmp202021_2sw", + "dmp202021_2ne", + "dmp202021_2nw", + "dmp202021_2se" + ], + "output": "dmp202021_b_2" + }, + "__groups": { + "dmp202021_e": "E", + "dmp202021_1s": "S", + "dmp202021_1n": "N", + "dmp202021_2se": "SE", + "dmp202021_2sw": "SW", + "dmp202021_2ne": "NE", + "dmp202021_2nw": "NW" + }, + "__queries": { + "dmp202021_2se": [ + "INSERT INTO _teams(id, bye) VALUES(15, 2),(16, 2);", + "INSERT INTO _matches(rnd, tabl, homet, visit, mtitle) SELECT rnd, 8, 15, 16, '--' FROM rounds WHERE rnd < 14;", + "INSERT INTO _matches(rnd, tabl, homet, visit, mtitle) SELECT 14, id, id, id+8, '--' FROM teams WHERE id < 9;", + "INSERT INTO _matches(rnd, tabl, homet, visit, mtitle) SELECT 15, id, id, id+8, '--' FROM teams WHERE id < 9;", + "INSERT INTO _segments(rnd, segment, tabl, homet, visit, towel) SELECT rnd, 1, 8, 15, 16, 1 FROM rounds;", + "INSERT INTO _segments(rnd, segment, tabl, homet, visit, towel) SELECT rnd, 2, 8, 15, 16, 1 FROM rounds;" + ] + } +} |