<commit_before>module ClearElection
  module Factory
    def self.seq(key)
      val = (@seq ||= Hash.new(-1))[key] += 1
      "#{key}-#{val}"
    end

    def self.election_uri
      "http://test.example.com/elections/#{seq(:id)}"
    end

    def self.agent_uri(what="agent", host:"agents.example.com")
      "http://#{host}/#{seq(what)}"
    end

    def self.election(
      signin: "http://dummy-signin.example.com",
      booth: nil,
      pollsOpen: nil,
      pollsClose: nil
    )
      Election.new(
        signin: Election::Agent.new(uri: signin || self.agent_uri("signin")),
        booth: Election::Agent.new(uri: booth || self.agent_uri("booth")),
        pollsOpen: pollsOpen || (DateTime.now - 1.day),
        pollsClose: pollsClose || (DateTime.now + 1.day),
        contests: [
          Election::Contest.new(contestId: seq(:contestId),
                      ranked: true,
                      multiplicity: 3,
                      writeIn: true,
                      candidates: [
                        Election::Candidate.new(candidateId: seq(:candidateId)),
                        Election::Candidate.new(candidateId: seq(:candidateId)),
                        Election::Candidate.new(candidateId: seq(:candidateId)),
                      ]),
          Election::Contest.new(contestId: seq(:contestId),
                      candidates: [
                        Election::Candidate.new(candidateId: seq(:candidateId)),
                        Election::Candidate.new(candidateId: seq(:candidateId)),
                      ]),
        ]
      )
    end

    def self.ballot(election=nil, ballotId: nil, uniquifier: nil, invalid: nil)
      election ||= self.election
      Ballot.new(
        ballotId: ballotId || seq(:ballotId),
        uniquifier: uniquifier || seq(:uniquifier),
        contests: election.contests.map { |contest|
          options = contest.candidates.map(&:candidateId)
          options << "ABSTAIN"
          options << "WRITEIN: TestWritein" if contest.writeIn
          options.shuffle!
          options.push "Test-Invalid-CandidateId" if invalid == :candidateId
          Ballot::Contest.new(
            contestId: contest.contestId,
            choices: contest.multiplicity.times.map {|rank|
              Ballot::Choice.new(candidateId: options.pop, rank: rank)
            }
          )
        }
      )
    end
  end
end

<commit_msg>use .day.ago helpers<commit_after>module ClearElection
  module Factory
    def self.seq(key)
      val = (@seq ||= Hash.new(-1))[key] += 1
      "#{key}-#{val}"
    end

    def self.election_uri
      "http://test.example.com/elections/#{seq(:id)}"
    end

    def self.agent_uri(what="agent", host:"agents.example.com")
      "http://#{host}/#{seq(what)}"
    end

    def self.election(
      signin: "http://dummy-signin.example.com",
      booth: nil,
      pollsOpen: nil,
      pollsClose: nil
    )
      Election.new(
        signin: Election::Agent.new(uri: signin || self.agent_uri("signin")),
        booth: Election::Agent.new(uri: booth || self.agent_uri("booth")),
        pollsOpen: (pollsOpen || 1.month.ago).to_datetime(),
        pollsClose: (pollsClose || 1.month.from_now).to_datetime(),
        contests: [
          Election::Contest.new(contestId: seq(:contestId),
                      ranked: true,
                      multiplicity: 3,
                      writeIn: true,
                      candidates: [
                        Election::Candidate.new(candidateId: seq(:candidateId)),
                        Election::Candidate.new(candidateId: seq(:candidateId)),
                        Election::Candidate.new(candidateId: seq(:candidateId)),
                      ]),
          Election::Contest.new(contestId: seq(:contestId),
                      candidates: [
                        Election::Candidate.new(candidateId: seq(:candidateId)),
                        Election::Candidate.new(candidateId: seq(:candidateId)),
                      ]),
        ]
      )
    end

    def self.ballot(election=nil, ballotId: nil, uniquifier: nil, invalid: nil)
      election ||= self.election
      Ballot.new(
        ballotId: ballotId || seq(:ballotId),
        uniquifier: uniquifier || seq(:uniquifier),
        contests: election.contests.map { |contest|
          options = contest.candidates.map(&:candidateId)
          options << "ABSTAIN"
          options << "WRITEIN: TestWritein" if contest.writeIn
          options.shuffle!
          options.push "Test-Invalid-CandidateId" if invalid == :candidateId
          Ballot::Contest.new(
            contestId: contest.contestId,
            choices: contest.multiplicity.times.map {|rank|
              Ballot::Choice.new(candidateId: options.pop, rank: rank)
            }
          )
        }
      )
    end
  end
end


{'fraction_non_alphanumeric': 0.13308457711442787, 'fraction_numerical': 0.0020729684908789387, 'mean_word_length': 1.8926858513189448, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, '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': '3490806', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1423, 'n_words': 240}