Skip to content

Commit

Permalink
2012 election add
Browse files Browse the repository at this point in the history
  • Loading branch information
oshlykov committed Feb 18, 2012
1 parent 14a67cf commit dfc04c2
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 39 deletions.
2 changes: 1 addition & 1 deletion app/controllers/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create
def destroy
redirect_to :back unless @p = Protocol.find_by_id(params[:id])
respond_to do |format|
unless can?(:destroy, @p) and @p.priority != 1 and @p.destroy
unless can?(:destroy, @p) and @p.destroy
flash[:error] = 'Протокол не удалён, обратитесь в тех поддержку ([email protected])'
end
format.js
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def suckerfish(node)
fuc.call(node.descendants.arrange)
end

def vds(i=0)
VOTING_DICTIONARY_SHORT[1][i]
def vds(i=0, election_id=1)
VOTING_DICTIONARY_SHORT[election_id][i]
end
end
2 changes: 1 addition & 1 deletion app/models/election.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Election < ActiveRecord::Base
has_many :commissions, :dependent => :destroy
has_many :voting_dictionaries, :dependent => :destroy
# has_many :voting_dictionaries, :dependent => :destroy
end
2 changes: 1 addition & 1 deletion app/views/commissions/_commissions_region.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
= child.name
%sup
%small
= child.descendants.where('votes_taken=true').size
= child.descendants.where(:votes_taken => true).size
- else
= child.name
%sup
Expand Down
12 changes: 6 additions & 6 deletions app/views/commissions/_commissions_uik.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
.span12
%table.voting-table
%tr
%td{:width => "100px"}
%td{:colspan => 18}
- 7.times do |i|
%td
%small{"title"=>Protocol.voting_name(i+19, 1)}= vds(i+19)
%th{:width => "100px"}
-#%th{:colspan => 18}
- VOTING_DICTIONARY_SHORT[@commission.election_id].each_with_index do |s,i|
%th
%small{"title"=>Protocol.voting_name(i, @commission.election_id)}= vds(i, @commission.election_id)
- @checked.each do |p|
- if p == @checked.first
%tr
Expand Down Expand Up @@ -45,7 +45,7 @@
%a{:href => pic.image_url}
= image_tag pic.image_url(:thumb) if pic.image?

- if @unchecked
- unless @unchecked.blank?
%h2 Непроверенные протоколы
%table.voting-table
- @unchecked.each do |p|
Expand Down
11 changes: 6 additions & 5 deletions app/views/commissions/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
- else
%table.voting-table
%tr
%td{:width => "100px"}
%td{:colspan => 18}
- 7.times do |i|
%td
%small{"title"=>Protocol.voting_name(i+19, 1)}= vds(i+19)
%th{:width => "100px"}
-#%th{:colspan => 18}
- VOTING_DICTIONARY_SHORT[@commission.election_id].each_with_index do |s,i|
%th
%small{"title"=>Protocol.voting_name(i, @commission.election_id)}= vds(i, @commission.election_id)
- @commission.children.each do |c|
%tr
%td
Expand All @@ -26,6 +26,7 @@
= vote



-# = vote.voting_dictionary.name
-#%div.voting-table
-# %div.controllers
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
= f.input :role, :label => 'Роль', :collection => User::ROLES, :include_blank => false if can? :update_role, current_user
= f.input :name, :label => "ФИО полностью:"
-unless current_user.commission
= f.input :commission, :label => "Регион:", :collection => Commission.where(:ancestry => nil).collect{|c| [ c.name, c.id ]}, :selected => current_user.commission_id
= f.input :commission, :label => "Регион:", :collection => Commission.where(:ancestry => nil, :election_id => 2).all(:order => 'name ASC').collect{|c| [ c.name, c.id ]}, :selected => current_user.commission_id
-#= f.input :name, :label => "Номер участка:"
-#= f.input :name, :label => "Номер телефона:"
-#= f.input :name, :label => "Доверяющий:"
Expand Down
2 changes: 1 addition & 1 deletion config/deploy/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# git and Auth
set :scm, :git
set :repository, "https://github.com/jesteracer/nk12.git"
set :repository, "https://github.com/oshlykov/nk12.git"
#set :branch, "production"
set :deploy_via, :remote_cache

Expand Down
2 changes: 1 addition & 1 deletion config/deploy/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# SVN and Auth
set :scm, :git
set :repository, "https://github.com/jesteracer/nk12.git"
set :repository, "https://github.com/oshlykov/nk12.git"
set :branch, "master"
set :deploy_via, :remote_cache

Expand Down
50 changes: 50 additions & 0 deletions config/initializers/voting_dictionary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@
24: Всероссийская политическая партия ЕДИНАЯ РОССИЯ
25: Всероссийская политическая партия ПРАВОЕ ДЕЛО
26: Число зафиксированных заявлениями нарушений
2:
1: Число избирателей, внесенных в список избирателей
2: Число избирательных бюллетеней, полученных участковой избирательной комиссией
3: Число избирательных бюллетеней, выданных избирателям, проголосовавшим досрочно
4: Число избирательных бюллетеней, выданных избирателям в помещении для голосования
5: Число избирательных бюллетеней, выданных избирателям вне помещения для голосования
6: Число погашенных избирательных бюллетеней
7: Число избирательных бюллетеней в переносных ящиках для голосования
8: Число избирательных бюллетеней в стационарных ящиках для голосования
9: Число недействительных избирательных бюллетеней
10: Число действительных избирательных бюллетеней
11: Число открепительных удостоверений, полученных участковой избирательной комиссией
12: Число открепительных удостоверений, выданных избирателям на избирательном участке
13: Число избирателей, проголосовавших по открепительным удостоверениям на избирательном участке
14: Число погашенных неиспользованных открепительных удостоверений
15: Число открепительных удостоверений, выданных избирателям территориальной избирательной комиссией
16: Число утраченных открепительных удостоверений
17: Число утраченных избирательных бюллетеней
18: Число избирательных бюллетеней, не учтенных при получении
19: Первый
20: Второй
21: Третитй
22: Четвертый
23: Пятый
24: Число зафиксированных заявлениями нарушений
YAML_TEXT

VOTING_DICTIONARY_SHORT = YAML::load <<YAML_TEXT2
Expand Down Expand Up @@ -57,4 +82,29 @@
24: ЕР
25: ПД
26: ЧН
2:
1: изб
2: пол
3: дос
4: выд
5: вне
6: пгш
7: ящк
8: стц
9: ндтв
10: дтв
11: опл
12: овд
13: опр
14: пго
15: овт
16: уту
17: утб
18: бне
19: к1
20: к2
21: к3
22: к4
23: к5
24: ЧН
YAML_TEXT2
42 changes: 22 additions & 20 deletions lib/tasks/grabber.rake
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace :grab do
# Fetches and stores all the needed data from the commission
# Recursively calls itself to handle sub-commissions
def fetch_commissions(dir, url)
return if /Regional\/Regional/ =~ dir
if(!File.exists?(dir))
mkdir(dir)
end
Expand Down Expand Up @@ -204,34 +205,35 @@ YAML_TEXT2

#{
# "poll" => "Число избирательных бюллетеней, полученных участковой избирательной комиссией","received_by_commission" => "Число избирательных бюллетеней, выданных избирателям, проголосовавшим досрочно","voted_early" => "Число избирательных бюллетеней, выданных избирателям в помещении для голосования","voted_in" => "Число избирательных бюллетеней, выданных избирателям вне помещения для голосования","voted_out" => "Число погашенных избирательных бюллетеней","canceled_ballots" => "Число избирательных бюллетеней в переносных ящиках для голосования","mobile_ballots" => "Число избирательных бюллетеней в стационарных ящиках для голосования","stationary_ballots" => "Число недействительных избирательных бюллетеней","invalid_ballots" => "Число действительных избирательных бюллетеней","valid_ballots" => "Число открепительных удостоверений, полученных участковой избирательной комиссией","absentee_ballots_all" => "Число открепительных удостоверений, выданных избирателям на избирательном участке","absentee_ballots_given" => "Число избирателей, проголосовавших по открепительным удостоверениям на избирательном участке","absentee_ballots_voted" => "Число погашенных неиспользованных открепительных удостоверений","unused_absentee_ballots" => "Число открепительных удостоверений, выданных избирателям территориальной избирательной комиссией","absentee_territorial" => "Число утраченных открепительных удостоверений","lost_absentee_ballots" => "Число утраченных избирательных бюллетеней","ballots_not_taken" => "Число избирательных бюллетеней, не учтенных при получении","sr" => "Политическая партия СПРАВЕДЛИВАЯ РОССИЯ","ldpr" => "Политическая партия Либерально-демократическая партия России","pr" => "Политическая партия ПАТРИОТЫ РОССИИ","kprf" => "Политическая партия Коммунистическая партия Российской Федерации","yabloko" => "Политическая партия Российская объединенная демократическая партия ЯБЛОКО","er" => "Всероссийская политическая партия ЕДИНАЯ РОССИЯ","pd" => "Всероссийская политическая партия ПРАВОЕ ДЕЛО"}

=begin
@voting_dictionaries = Hash.new
voting_labels.each do |key,value|
voting_dictionary = @election.voting_dictionaries.create(:en_name => key, :name => value, :source_identifier => voting_names[key])
@voting_dictionaries[voting_names[key]] = voting_dictionary.id
end

=end
# Getting commission's page from the file system. No fetching/saving happens. As all the data is already in filesystem's cache
raw_html = fetch_and_save(inp_data_dir + '/about.html', "http://www.vybory.izbirkom.ru/region/izbirkom?action=show&root_a=null&vrn=100100031793505&region=0&global=true&type=0&sub_region=0&prver=0&pronetvd=null")
raw_html = fetch_and_save(inp_data_dir + '/about.html', "http://www.vybory.izbirkom.ru/region/izbirkom?action=show&root_a=null&vrn=100100031793505&region=0&global=true&type=0&sub_region=0&prver=0&pronetvd=null")
#2011 raw_html = fetch_and_save(inp_data_dir + '/about.html', "http://www.vybory.izbirkom.ru/region/izbirkom?action=show&root_a=null&vrn=100100028713299&region=0&global=true&type=0&sub_region=0&prver=0&pronetvd=null")
#2012 raw_html = fetch_and_save(inp_data_dir + '/about.html', "http://www.vybory.izbirkom.ru/region/izbirkom?action=show&root_a=null&vrn=100100031793505&region=0&global=true&type=0&sub_region=0&prver=0&pronetvd=null")
agent = Nokogiri::HTML(raw_html, nil, 'Windows-1251')
agent = Nokogiri::HTML(raw_html, nil, 'Windows-1251')

agent.search("select option").each_with_index do |option,index|
if (option['value'])
name = option.content.gsub(/^\d+ /,'')
commission = Commission.create!(:name => name.strip, :url => option['value'], :election_id => @election.id)
print "Taken: #{option.content}\n"
end
agent.search("select option").each_with_index do |option,index|
if (option['value'])
name = option.content.gsub(/^\d+ /,'')
commission = Commission.create!(:name => name.strip, :url => option['value'], :election_id => @election.id)
print "Taken: #{option.content}\n"
end
end

Parallel.each(Commission.all, :in_threads => 15){|commission| get_children_from_raw_html(inp_data_dir + '/' + commission.name, commission, commission.url)}
}
Parallel.each(Commission.all, :in_threads => 15){|commission| get_children_from_raw_html(inp_data_dir + '/' + commission.name, commission, commission.url)}
}
end

# The function below is almost copy of get_children_from_raw_html. Temporary solution. Not very effective in terms of execution time
def get_children_from_raw_html(dir, parent_commission, url)
return if /Regional\/Regional/ =~ dir
begin
# Getting commission's page from the file system. No fetching/saving happens. As all the data is already in filesystem's cache
agent = Nokogiri::HTML(fetch_and_save(dir + '/about.html', url), nil, 'Windows-1251')
Expand Down Expand Up @@ -261,12 +263,12 @@ YAML_TEXT2
get_children_from_raw_html(dir + '/Regional', parent_commission, href['href'])
end
end
voting_table_from_raw_html(dir, parent_commission)
#2012 voting_table_from_raw_html(dir, parent_commission)
rescue Exception => ex
print "Error: #{ex}\n"
end
end

=begin
def voting_table_from_raw_html(dir, commission)
if commission.voting_table_url
begin
Expand All @@ -290,7 +292,6 @@ YAML_TEXT2
end
end
end

desc "Get ungetted"
task :get_lost => :environment do
Expand All @@ -312,6 +313,7 @@ YAML_TEXT2
end
end
end
=end

desc "Grab all the commissions out there from 4-dec elections"
task :get => :environment do
Expand Down Expand Up @@ -390,14 +392,14 @@ yabloko: "Политическая партия Российская объед
er: "Всероссийская политическая партия ЕДИНАЯ РОССИЯ"
pd: "Всероссийская политическая партия ПРАВОЕ ДЕЛО"
YAML_TEXT2

=begin
@voting_dictionaries = Hash.new
voting_labels.each do |key,value|
voting_dictionary = @election.voting_dictionaries.create(:en_name => key, :name => value, :source_identifier => voting_names[key])
@voting_dictionaries[voting_names[key]] = voting_dictionary.id
end

=end

agent = Nokogiri::HTML(open("http://www.vybory.izbirkom.ru/region/izbirkom?action=show&root_a=null&vrn=100100031793505&region=0&global=true&type=0&sub_region=0&prver=0&pronetvd=null"), nil, 'Windows-1251')
#2011 agent = Nokogiri::HTML(open("http://www.vybory.izbirkom.ru/region/izbirkom?action=show&root_a=null&vrn=100100028713299&region=0&global=true&type=0&sub_region=0&prver=0&pronetvd=null"), nil, 'Windows-1251')
Expand Down Expand Up @@ -466,13 +468,13 @@ YAML_TEXT2
get_children(parent_commission,href['href'])
end
end
voting_table(parent_commission)
#2012 voting_table(parent_commission)
rescue Exception => ex
print "Error: #{ex}\n"
end

end

=begin
def voting_table(commission)
if commission.voting_table_url
begin
Expand All @@ -498,5 +500,5 @@ YAML_TEXT2
end
end
end

=end
end

0 comments on commit dfc04c2

Please sign in to comment.