forked from oshlykov/nk12
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.rb
87 lines (79 loc) · 3.18 KB
/
console.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#пользователи
us = User.all
option = {:col_sep => ";", :encoding => "windows-1251"}
FasterCSV.open( 'users-commissions.csv', "w", option) do |csv|
csv << ["номер", "имя", "почта", "код уика", "название уика", "регион"]
us.each do |u|
csv << [u.id, u.name, u.email, u.commission_id, u.commission_id ? u.commission.name : "", u.commission_id ? u.commission.root.name : "" ].flatten.compact
end
end
#уики
cs = Commission.find_all_by_election_id(1)
x = Array.new
cs.each_with_index do |c,i|
x[i] = Hash.new
x[i][:id] = c.id
x[i][:parent] = c.parent_id
x[i][:name] = c.name
option = {:col_sep => ";", :encoding => "WINDOWS_1251"}
FasterCSV.open('exp-katya.csv', "w", option) do |csv|
csv << ['id', 'parent', 'name']
x.each do |ccc|
csv << [ccc[:id], ccc[:parent], ccc[:name]].flatten.compact
end
end
end
# обновление хешей и приоритетов
state = Hash.new
Commission.find_all_by_votes_taken(1).each do |c|
if c.protocols.size < 2
c.votes_taken = 0
c.conflict = 0
c.save
else
state[:uik] = c.protocols[0].votings
karik = c.protocols[1]
if karik.priority <100 and karik.priority >=50
karik.priority = 1
karik.save
end
conflict = false
if karik.priority == 1
state[:checked] = Array.new
karik.votings.each_with_index do |v,i|
state[:checked][i] = karik.send("v#{i+1}")
conflict = true if state[:checked][i] != state[:uik][i] and i != 25
end
end
c.state = state
c.save
end
end
# загрузка структуры уиков
Commission.roots.each do |c|
Commission.get_children(c)
end
#стягивание всех данных по голосованиям с сайта ЦИК
cs = Commission.where("voting_table_url IS NOT NULL and election_id=2").includes(:protocols)
Parallel.each(Commission.where("voting_table_url IS NOT NULL and election_id=2").includes(:protocols), :in_threads => 4){ |c| Commission.voting_table(c) }
#или
Commission.where("voting_table_url IS NOT NULL and election_id=2").includes(:protocols).each do |c| Commission.voting_table(c) end
#особое обновление, кеширования - разовый случай
Commission.where("election_id=2 and voting_table_url IS NOT NULL and state = '--- \n'").each do |commission|
if commission.voting_table_url and uik = commission.protocols.find_by_priority(0)
commission.state ||= Hash.new
commission.state[:uik] = uik.votings
if karik = commission.protocols.find_by_priority(1)
commission.state[:checked] = karik.votings unless commission.state.include? :checked
#Обновление кэша
conflict = false
karik.votings.each_with_index do |v,i|
# karik.size-1 так как неучитываем последгний столбец с кол заявлений
conflict = true if commission.state[:checked][i] != commission.state[:uik][i] and i != karik.votings.size-1
end
commission.conflict = conflict
commission.votes_taken = true
end
commission.save
end
end