- JOIN Fotballserier serier on resultater.Serie=serier.Nr
-WHERE deltager1.Nr > deltager2.nr
-');
-$q->execute($last_season);
-
-while (my $ref = $q->fetchrow_hashref) {
- next if ($ref->{'maalfor'} == 150 && $ref->{'maalmot'} == 0);
- next if ($ref->{'maalfor'} == 0 && $ref->{'maalmot'} == 150);
- printf DATA "%d %d %d %d %f\n", $ref->{'p1'}, $ref->{'p2'}, $ref->{'maalfor'}, $ref->{'maalmot'}, $ref->{'vekt'};
+ JOIN Fotballserier serier ON resultater.Serie=serier.Nr
+ JOIN Fotballspraak spraak ON serier.Spraak=spraak.Id
+WHERE deltager1.Nr > deltager2.nr AND kultur=?
+ ');
+ $q->execute($last_season, $locale);
+
+ while (my $ref = $q->fetchrow_hashref) {
+ next if ($ref->{'maalfor'} == 150 && $ref->{'maalmot'} == 0);
+ next if ($ref->{'maalfor'} == 0 && $ref->{'maalmot'} == 150);
+ next if ($ref->{'maalfor'} == 150 && $ref->{'maalmot'} == 150);
+ next if ($ref->{'maalfor'} == 0 && $ref->{'maalmot'} == 0);
+ push @$games, { %$ref };
+ $ids->{$ref->{'p1'}} = 1;
+ $ids->{$ref->{'p2'}} = 1;
+ }
+}
+
+sub output_to_file {
+ my ($games, $ids) = @_;
+
+ my $tmpnam = POSIX::tmpnam();
+ open DATA, ">", $tmpnam
+ or die "$tmpnam: $!";
+
+ printf DATA "%d\n", scalar keys %$ids;
+ for my $id (keys %$ids) {
+ printf DATA "%d\n", $id;
+ }
+ for my $ref (@$games) {
+ printf DATA "%d %d %d %d %f\n", $ref->{'p1'}, $ref->{'p2'}, $ref->{'maalfor'}, $ref->{'maalmot'}, $ref->{'vekt'};
+ }
+ close DATA;
+
+ return $tmpnam;
+}
+
+sub train_model {
+ my ($filename, $locale, $ratings, $covariances, $aux_params) = @_;
+
+ open RATINGS, "$config::base_dir/bayeswf < $filename |"
+ or die "bayeswf: $!";
+ while (<RATINGS>) {
+ chomp;
+ my @x = split;
+ if ($x[0] eq 'covariance') {
+ push @$covariances, (join("\t", @x[1..3]));
+ } elsif ($x[0] eq 'aux_param') {
+ push @$aux_params, ($locale . "\t" . $x[1] . "\t" . $x[2]);
+ } else {
+ push @$ratings, ($x[2] . "\t" . $x[0] . "\t" . $x[1]);
+ }
+ }
+
+ close RATINGS;