Added functions for finals state/score

main
noah metz 2024-01-29 00:07:52 -07:00
parent b9da942482
commit e37708cac3
1 changed files with 19 additions and 0 deletions

@ -241,6 +241,25 @@ handle_call({match_state, Division, Round, Number, MatchState}, _, State) ->
[Division, atom_to_list(Round), Number, get_tick(State), MatchState])),
{reply, ok, State};
handle_call({finals_score, Number, Red, Blue, Score}, _, State) ->
[{columns, Columns}, {rows, Rows}] = sqlite3:sql_exec(State#state.database,
io_lib:format(
"SELECT instance FROM finals_scores WHERE number = ~p;",
[Number])),
Instances = get_column("instance", Columns, Rows),
NextInstance = if length(Instances) == 0 -> 1;
true -> lists:max(Instances) + 1
end,
ok = first_error(sqlite3:sql_exec_script(State#state.database, lists:append(
[io_lib:format("INSERT INTO finals_scores(number, instance, red, blue, score) VALUES(~p, ~p, ~p, ~p, '~s');", [Number, NextInstance, Red, Blue, Score]),
io_lib:format("INSERT INTO finals_states(number, tick, state) VALUES(~p, ~p, '~s');", [Number, get_tick(State), "scored"])]))),
{reply, ok, State};
handle_call({finals_state, Number, MatchState}, _, State) ->
{rowid, _} = sqlite3:sql_exec(State#state.database,
io_lib:format("INSERT INTO finals_states(number, tick, state) VALUES(~p, ~p, '~s');",
[Number, get_tick(State), MatchState])),
{reply, ok, State};
handle_call({add_division, PSize, QSize, ESize}, _, State) ->
[{columns, Columns}, {rows, Rows}] = sqlite3:sql_exec(State#state.database, "SELECT division FROM divisions;"),
Divisions = lists:sort(get_column("division", Columns, Rows)),