11 # Find last completely done season
12 sub find_last_season {
13 my ($dbh, $locale) = @_;
14 my $ref = $dbh->selectrow_hashref('SELECT sesong FROM fotballserier se JOIN fotballspraak sp ON se.spraak=sp.id GROUP BY kultur,sesong HAVING COUNT(*)=COUNT(avgjort=1 OR NULL) AND kultur=? ORDER BY kultur,sesong DESC LIMIT 1', undef, $locale);
15 return $ref->{'sesong'};
19 my ($dbh, $locale, $last_season, $games, $ids) = @_;
20 my $q = $dbh->prepare('
22 deltager1.id as p1, deltager2.id as p2, maalfor, maalmot, least(pow(2.0, (sesong - ? + 3) / 3.0), 1.0) AS vekt
24 ( SELECT * FROM fotballresultater UNION ALL SELECT * FROM fotballresultater_2123 ) resultater
25 JOIN Fotballdeltagere deltager1 ON resultater.Lagrecno=deltager1.Nr AND resultater.Serie=deltager1.Serie
26 JOIN Fotballdeltagere deltager2 ON resultater.Motstander=deltager2.Nr AND resultater.Serie=deltager2.Serie
27 JOIN Fotballserier serier ON resultater.Serie=serier.Nr
28 JOIN Fotballspraak spraak ON serier.Spraak=spraak.Id
29 WHERE deltager1.Nr > deltager2.nr AND kultur=?
31 $q->execute($last_season, $locale);
33 while (my $ref = $q->fetchrow_hashref) {
34 next if ($ref->{'maalfor'} == 150 && $ref->{'maalmot'} == 0);
35 next if ($ref->{'maalfor'} == 0 && $ref->{'maalmot'} == 150);
36 next if ($ref->{'maalfor'} == 150 && $ref->{'maalmot'} == 150);
37 next if ($ref->{'maalfor'} == 0 && $ref->{'maalmot'} == 0);
38 push @$games, { %$ref };
39 $ids->{$ref->{'p1'}} = 1;
40 $ids->{$ref->{'p2'}} = 1;
45 my ($locale, $games, $ids) = @_;
47 my $tmpnam = POSIX::tmpnam();
48 open DATA, ">", $tmpnam
51 printf DATA "%s\n", $locale;
52 printf DATA "%d\n", scalar keys %$ids;
53 for my $id (keys %$ids) {
54 printf DATA "%d\n", $id;
56 for my $ref (@$games) {
57 printf DATA "%d %d %d %d %f\n", $ref->{'p1'}, $ref->{'p2'}, $ref->{'maalfor'}, $ref->{'maalmot'}, $ref->{'vekt'};
64 my $dbh = DBI->connect($config::local_connstr, $config::local_username, $config::local_password)
65 or die "connect: " . $DBI::errstr;
66 $dbh->{AutoCommit} = 1;
68 my @locales = wloh_common::find_all_locales($dbh);
71 for my $locale (@locales) {
72 my $last_season = find_last_season($dbh, $locale);
75 fetch_games($dbh, $locale, $last_season, \@games, \%ids);
76 my $tmpnam = output_to_file($locale, \@games, \%ids);
77 push @filenames, $tmpnam;
82 system("$config::base_dir/bayeswf", @filenames);