<commit_before>require 'json'
require './lib/controllers/round'
require './lib/controllers/flag'
require './lib/controllers/score'
require './lib/utils/queue'
require 'themis/checker/result'
require './lib/controllers/contest-state'
require './lib/utils/event-emitter'
require './lib/controllers/attack'
require './lib/controllers/scoreboard-state'


module Themis
    module Controllers
        module Contest
            @logger = Themis::Utils::Logger::get

            def self.start
                Themis::Controllers::ContestState::start
            end

            def self.push_flag(team, service, round)
                flag = Themis::Controllers::Flag::issue team, service, round

                @logger.info "Pushing flag '#{flag.flag}' to service #{service.name} of '#{team.name}' ..."
                job_data = {
                    operation: 'push',
                    endpoint: team.host,
                    flag_id: flag.seed,
                    flag: flag.flag
                }.to_json
                Themis::Utils::Queue::enqueue "themis.service.#{service.alias}.listen", job_data
            end

            def self.push_flags
                round = Themis::Controllers::Round::start_new
                round_num = Themis::Models::Round.all.count
                @logger.info "Round #{round_num} started!"

                all_services = Themis::Models::Service.all

                Themis::Models::Team.all.each do |team|
                    all_services.each do |service|
                        begin
                            push_flag team, service, round
                        rescue => e
                            @logger.error "#{e}"
                        end
                    end
                end
            end

            def self.handle_push(flag, status, seed)
                if status == Themis::Checker::Result::UP
                    flag.pushed_at = DateTime.now
                    expires = Time.now + Themis::Configuration.get_contest_flow.flag_lifetime
                    flag.expired_at = expires.to_datetime
                    flag.seed = seed
                    flag.save
                    @logger.info "Successfully pushed flag #{flag.flag}!"

                    poll_flag flag
                else
                    @logger.info "Failed to push flag #{flag.flag} (status code #{status})!"
                end
            end

            def self.poll_flag(flag)
                team = flag.team
                service = flag.service<commit_msg>Update service state on push<commit_after>require 'json'
require './lib/controllers/round'
require './lib/controllers/flag'
require './lib/controllers/score'
require './lib/utils/queue'
require 'themis/checker/result'
require './lib/controllers/contest-state'
require './lib/utils/event-emitter'
require './lib/controllers/attack'
require './lib/controllers/scoreboard-state'


module Themis
    module Controllers
        module Contest
            @logger = Themis::Utils::Logger::get

            def self.start
                Themis::Controllers::ContestState::start
            end

            def self.push_flag(team, service, round)
                flag = Themis::Controllers::Flag::issue team, service, round

                @logger.info "Pushing flag '#{flag.flag}' to service #{service.name} of '#{team.name}' ..."
                job_data = {
                    operation: 'push',
                    endpoint: team.host,
                    flag_id: flag.seed,
                    flag: flag.flag
                }.to_json
                Themis::Utils::Queue::enqueue "themis.service.#{service.alias}.listen", job_data
            end

            def self.push_flags
                round = Themis::Controllers::Round::start_new
                round_num = Themis::Models::Round.all.count
                @logger.info "Round #{round_num} started!"

                all_services = Themis::Models::Service.all

                Themis::Models::Team.all.each do |team|
                    all_services.each do |service|
                        begin
                            push_flag team, service, round
                        rescue => e
                            @logger.error "#{e}"
                        end
                    end
                end
            end

            def self.handle_push(flag, status, seed)
                if status == Themis::Checker::Result::UP
                    flag.pushed_at = DateTime.now
                    expires = Time.now + Themis::Configuration.get_contest_flow.flag_lifetime
                    flag.expired_at = expires.to_datetime
                    flag.seed = seed
                    flag.save
                    @logger.info "Successfully pushed flag #{flag.flag}!"

                    poll_flag flag
                else
                    @logger.info "Failed to push flag #{flag.flag} (status code #{status})!"
                end

                update_team_service_state flag.team, flag.service, status
            end

            def self.poll_flag(flag)
                team = flag.team
                service = flag.service
{'fraction_non_alphanumeric': 0.09941747572815535, 'fraction_numerical': 0.0, 'mean_word_length': 1.4070093457943926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4409445', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1246, 'n_words': 281}