| 1 |
8 |
ahitrov@rambler.ru |
#!/usr/bin/perl |
| 2 |
|
|
|
| 3 |
|
|
use strict; |
| 4 |
|
|
BEGIN { require '../libs.pl' }; |
| 5 |
|
|
|
| 6 |
|
|
use vars qw($DEBUG); |
| 7 |
|
|
$DEBUG = 0; |
| 8 |
|
|
|
| 9 |
|
|
use Data::Dumper; |
| 10 |
|
|
|
| 11 |
|
|
use Contenido::Init; |
| 12 |
|
|
use Rate::Main; |
| 13 |
|
|
|
| 14 |
|
|
&check_pid(); |
| 15 |
|
|
|
| 16 |
|
|
Contenido::Init::init(); |
| 17 |
|
|
|
| 18 |
|
|
$Contenido::Keeper::DEBUG = $DEBUG; |
| 19 |
|
|
$Contenido::Project::DEBUG = $DEBUG; |
| 20 |
|
|
$Contenido::State::DEBUG = $DEBUG; |
| 21 |
|
|
$PhoenixDBI::DEBUG = $DEBUG; |
| 22 |
|
|
|
| 23 |
|
|
$Data::Dumper::Indent = 0 unless ($DEBUG); |
| 24 |
|
|
|
| 25 |
|
|
# Подключаемся к базе данных для тестирования и проверки... |
| 26 |
|
|
my $keeper = Contenido::Keeper->new($state); |
| 27 |
|
|
$keeper->{TSQLStable} = 1; |
| 28 |
|
|
|
| 29 |
|
|
warn Data::Dumper::Dumper($state->rate()) if ($DEBUG); |
| 30 |
|
|
|
| 31 |
|
|
my $set={}; |
| 32 |
|
|
foreach my $serial (($state->rate->days-2..0),undef) { |
| 33 |
|
|
Rate::Main->parse_single_file($set,$serial); |
| 34 |
|
|
} |
| 35 |
|
|
warn Data::Dumper::Dumper($set) if ($DEBUG); |
| 36 |
|
|
|
| 37 |
|
|
my $id_hash=(); |
| 38 |
|
|
while (my ($client,$votes)=each(%$set)) { |
| 39 |
|
|
while (my ($id,$vote)= each(%$votes)) { |
| 40 |
|
|
$id_hash->{$id}->{$vote}++; |
| 41 |
|
|
$id_hash->{$id}->{votes}++; |
| 42 |
|
|
$id_hash->{$id}->{total}+=$vote; |
| 43 |
|
|
} |
| 44 |
|
|
} |
| 45 |
|
|
|
| 46 |
|
|
warn Data::Dumper::Dumper($id_hash) if ($DEBUG); |
| 47 |
|
|
|
| 48 |
|
|
my $time=time(); |
| 49 |
|
|
|
| 50 |
|
|
while (my ($id,$votes)=each(%$id_hash)) { |
| 51 |
|
|
my $document=undef; |
| 52 |
|
|
|
| 53 |
|
|
foreach (@{$state->rate->allowed_classes}) { |
| 54 |
|
|
$document = $keeper->get_document_by_id($id,class=>$_); |
| 55 |
|
|
last if $document; |
| 56 |
|
|
} |
| 57 |
|
|
|
| 58 |
|
|
unless ($document) { |
| 59 |
|
|
warn "wrong document id: '$id'"; |
| 60 |
|
|
next; |
| 61 |
|
|
} |
| 62 |
|
|
|
| 63 |
|
|
my $document_votes=$document->get_image('rating'); |
| 64 |
|
|
$document_votes->{LAST}=$votes; |
| 65 |
|
|
$document_votes->{LAST}->{mtime}=$time; |
| 66 |
|
|
|
| 67 |
|
|
foreach (qw(1 2 3 4 5 votes total mtime)) { |
| 68 |
|
|
$document_votes->{OLD}->{$_}||=0; |
| 69 |
|
|
$document_votes->{LAST}->{$_}||=0; |
| 70 |
|
|
$document_votes->{TOTAL}->{$_}=$document_votes->{OLD}->{$_}+$document_votes->{LAST}->{$_}; |
| 71 |
|
|
} |
| 72 |
|
|
|
| 73 |
|
|
my $raw_rating = Data::Dumper::Dumper($document_votes); |
| 74 |
|
|
|
| 75 |
|
|
#rating changed!!! |
| 76 |
|
|
#comparing Data::Dumper results is cheap hack but no fast and easy way compare two data structure |
| 77 |
|
|
if ($raw_rating ne $document->rating) { |
| 78 |
|
|
$document->rating($raw_rating); |
| 79 |
|
|
$document->store(); |
| 80 |
|
|
} |
| 81 |
|
|
} |