def calculate(self, verify): import bdocpythonutils tic = ticker.Counter('Hääli:', '\tKorras: %d\tVigaseid: %d') tic.start('Hääletuse \"%s\" olekuanalüüs' % self.__elid) conf = bdocpythonutils.BDocConfig() conf.load(Election().get_bdoc_conf()) for path in os.walk(self.__reg.path(['hts', 'votes'])): root = path[0] for vote_file in path[2]: code = root.split('/').pop() msg = None res = True if verify: res, msg = self.do_verify(root, vote_file, conf, code) if htscommon.VALID_VOTE_PATTERN.match(vote_file): self.__sti.valid_vote(msg, res) elif htscommon.USERREVOKED_VOTE_PATTERN.match(vote_file): self.__sti.userrevoked_vote(msg, res) elif htscommon.AUTOREVOKED_VOTE_PATTERN.match(vote_file): self.__sti.autorevoked_vote(msg, res) elif htscommon.REVOKE_REASON_PATTERN.match(vote_file): pass elif htscommon.VOTE_VERIFICATION_ID_FILENAME == vote_file: pass else: self.__sti.unknown_file('\t' + root + '/' + vote_file) tic.tick(1, self.__sti.ok_count(), self.__sti.bad_count()) tic.finish()
def status_verify(self): import bdocconfig tic = ticker.Counter('Hääli:', '\tKorras: %d\tVigaseid: %d') tic.start('Hääletuse \"%s\" olekuanalüüs' % self._elid) conf = bdocconfig.BDocConfig() conf.load(Election().get_bdoc_conf()) for path in os.walk(self._reg.path(['hts', 'votes'])): root = path[0] code = root.split('/').pop() if not formatutil.is_isikukood(code): continue user_revoked = False valid_files = [] for vote_file in path[2]: if htscommon.REVOKE_REASON_PATTERN.match(vote_file): user_revoked = True continue if htscommon.VOTE_VERIFICATION_ID_FILENAME == vote_file: continue if htscommon.PARTIAL_VOTE_PATTERN.match(vote_file): continue if not htscommon.VALID_VOTE_PATTERN.match(vote_file): self.__sti.unknown_file( 1, '\tTundmatu fail: ' + code + '/' + vote_file) continue valid_files.append(vote_file) if len(valid_files) > 0: valid_files.sort() latest = valid_files.pop() res, msg = self.do_verify(root, latest, conf, code) if not user_revoked: self.__sti.valid_vote(1, msg, res) else: self.__sti.userrevoked_vote(1, msg, res) self.__sti.autorevoked_vote(len(valid_files), None, True) else: self.__sti.unknown_file(1, '\tHäälteta kaust: ' + code) tic.tick(1, self.__sti.ok_count(), self.__sti.bad_count()) tic.finish()
def tyhistusperioodi(self): vc_valid = 0 vc_autor = 0 jaoskonnad = {} jaoskonnad_rev = {} self.__load_jaoskonnad(jaoskonnad, jaoskonnad_rev) tic = ticker.Counter('Hääli:', '\tArvesse minevaid: %d\tKorduvaid: %d') tic.start('Koostan e-hääletanute nimekirja:') for path in os.walk(self._reg.path(['hts', 'votes'])): root = path[0] code = root.split('/').pop() if not formatutil.is_isikukood(code): continue log_lines = self.get_log_lines(root, path[2]) if len(log_lines) > 0: log_lines.sort(key=itemgetter(0)) latest = log_lines.pop() vc_autor += len(log_lines) vc_valid += 1 voter = htscommon.get_logline_voter(latest[0]) jaoskonnad_rev['%s\t%s\t%s\t%s' % (voter['jaoskond_omavalitsus'], voter['jaoskond'], voter['ringkond_omavalitsus'], voter['ringkond'])].append(voter) tic.tick(1, vc_valid, vc_autor) tic.finish() valijaid1 = self.__write_masinloetav(jaoskonnad_rev) valijaid2 = self.__write_inimloetav(jaoskonnad) if not (valijaid1 == valijaid2): self._errmsg = 'Viga nimekirjade koostamisel' raise Exception(self._errmsg) return vc_valid + vc_autor, vc_autor, valijaid1
def tyhistusperioodi(self): pc_cache = {} vc = htscommon.VoteCounter() self._log1.cache(pc_cache, 'isikukood') jaoskonnad = {} jaoskonnad_rev = {} self.__load_jaoskonnad(jaoskonnad, jaoskonnad_rev) tic = ticker.Counter(\ 'Hääli:', '\tArvesse minevaid: %d\tKorduvaid: %d') tic.start('Koostan e-hääletanute nimekirja:') for path in os.walk(self._reg.path(['hts', 'votes'])): root = path[0] for vote_file in path[2]: if htscommon.VALID_VOTE_PATTERN.match(vote_file): code = root.split('/').pop() if not code in pc_cache: self._errmsg = \ "Serveri andmestruktuurid ei ole kooskõlalised" raise Exception(self._errmsg) voter = htscommon.get_votefile_voter(vote_file) voter['isikukood'] = code jaoskonnad_rev['%s\t%s\t%s\t%s' % (\ voter['jaoskond_omavalitsus'], \ voter['jaoskond'], voter['ringkond_omavalitsus'], \ voter['ringkond'])].append(voter) vc.inc_valid() elif htscommon.AUTOREVOKED_VOTE_PATTERN.match(vote_file): vc.inc_autorevoked() else: vc.inc_unknown() tic.tick(1, vc.valid(), vc.autorevoked()) tic.finish() valijaid1 = self.__write_masinloetav(jaoskonnad_rev) valijaid2 = self.__write_inimloetav(jaoskonnad) if not (valijaid1 == valijaid2): self._errmsg = 'Viga nimekirjade koostamisel' raise Exception(self._errmsg) return vc.valid() + vc.autorevoked(), vc.autorevoked(), valijaid1
def lugemisperioodi(self): r_votes = 0 v_votes = 0 self._reg.ensure_no_key(\ ['hts', 'output', evcommon.ELECTIONS_RESULT_FILE]) vf = htscommon.LoggedFile(\ self._reg.path(\ ['hts', 'output', evcommon.ELECTIONS_RESULT_FILE]), self) vf.open('a') vf.write(evcommon.VERSION + "\n") vf.write(self._elid + "\n") tic = ticker.Counter(\ 'Hääli:', '\tKehtivaid: %d\tAvalduse alusel tühistatuid: %d') tic.start('Koostan loendamisele minevate häälte nimekirja') for path in os.walk(self._reg.path(['hts', 'votes'])): root = path[0] for vote_file in path[2]: if htscommon.VALID_VOTE_PATTERN.match(vote_file): v_votes += 1 res = self.__handle_valid(root, vote_file) vf.write('\t'.join(res) + '\n') elif htscommon.USERREVOKED_VOTE_PATTERN.match(vote_file): r_votes += 1 self.__handle_userrevoked(root, vote_file) elif htscommon.AUTOREVOKED_VOTE_PATTERN.match(vote_file): pass elif htscommon.REVOKE_REASON_PATTERN.match(vote_file): pass else: pass tic.tick(1, v_votes, r_votes) tic.finish() vf.close() ksum.store(vf.name()) return v_votes, r_votes
def lugemisperioodi(self): r_votes = 0 v_votes = 0 a_votes = 0 b_votes = 0 self._reg.ensure_no_key( ['hts', 'output', evcommon.ELECTIONS_RESULT_FILE]) vf = htscommon.LoggedFile( self._reg.path(['hts', 'output', evcommon.ELECTIONS_RESULT_FILE])) vf.open('a') vf.write(evcommon.VERSION + "\n") vf.write(self._elid + "\n") l1_lines = [] l2_lines = [] l3_lines = [] tic = ticker.Counter( 'Hääli:', '\tKehtivaid: %d\tAvalduse alusel tühistatuid: %d') tic.start('Koostan loendamisele minevate häälte nimekirja') nowstr = time.strftime("%Y%m%d%H%M%S") for path in os.walk(self._reg.path(['hts', 'votes'])): root = path[0] code = root.split('/').pop() if not formatutil.is_isikukood(code): continue log_lines = self.get_log_lines(root, path[2]) if len(log_lines) > 0: log_lines.sort(key=itemgetter(0), reverse=True) new = None for lines in log_lines: old = lines[0].rsplit('\t', 2)[0] notime = old.split('\t', 1)[1] fn = lines[1] voteforres = self.get_vote_for_result(old, fn) if voteforres: l1_lines.append(old) if new is None: ur, reason, tim = self.is_user_revoked(code) if ur: l2_lines.append("%s\t%s\t%s" % (tim, notime, reason)) r_votes += 1 else: vf.write('\t'.join(voteforres) + '\n') v_votes += 1 l3_lines.append("%s\t%s" % (nowstr, notime)) else: autor = new.split('\t') l2_lines.append("%s\t%s\tkorduv e-hääl: %s" % (autor[0], notime, autor[1])) a_votes += 1 new = old else: b_votes += 1 tic.tick(1, v_votes, r_votes) vf.close() ksum.store(vf.name()) tic.finish() l1_lines.sort() self.save_log(l1_lines, '1') l2_lines.sort() self.save_log(l2_lines, '2') l3_lines.sort() self.save_log(l3_lines, '3') return v_votes, r_votes, a_votes, b_votes