Kyu and dan levels on the sgf files

Post Reply
jwz
Posts: 4
Joined: Mon Dec 21, 2009 4:36 am

Kyu and dan levels on the sgf files

Post by jwz »

If this is done one can study by degrees of difficulty.

Regards,

Justin
tails
Posts: 90
Joined: Thu Oct 23, 2008 12:10 pm

Re: Kyu and dan levels on the sgf files

Post by tails »

Hi, are you talking about the offline version?
jwz
Posts: 4
Joined: Mon Dec 21, 2009 4:36 am

Re: Kyu and dan levels on the sgf files

Post by jwz »

Yes
tails
Posts: 90
Joined: Thu Oct 23, 2008 12:10 pm

Re: Kyu and dan levels on the sgf files

Post by tails »

Ok, I'll add the kyu and dan levels ... oh, it's already there! :o

The offline SGF files contain some extended tags:
  • GE : genre
  • DI : difficulty as kyu/dan value
  • DP : difficulty as percentage
  • SO : author (submitter)
  • CO : old coolness value
Check out the value of DI tag; that's what you want.
jwz
Posts: 4
Joined: Mon Dec 21, 2009 4:36 am

Re: Kyu and dan levels on the sgf files

Post by jwz »

How do you suggest I allocate the right file, because they are individual files and the degrees of difficulty are pretty random.
Thanks
tails
Posts: 90
Joined: Thu Oct 23, 2008 12:10 pm

Re: Kyu and dan levels on the sgf files

Post by tails »

Hmm... So, you are using some software (such as CGoban) to open SGF files, and not using the offline site archive, right? And, to open a file of a certain level, you wish to know the level by its filename, right?

If you have Perl installed in your system, then this script will rename the files for you. The names will have kyu/dan levels, and be lexicographically sortable by the order of difficulty.

Code: Select all

use strict;
use integer;
chdir("goproblemsSGF");  # <-- modify this for your env.
foreach my $fn (<*.sgf>) {
    my $f;
    open($f,$fn);
    my $t=<$f>;
    close($f);
    my $di=$t=~/DI\[(.*?)\]/?$1:'x';
    my $dp=$t=~/DP\[(.*?)\]/?sprintf("%03d",$1):'x';
    rename($fn,"$dp-$di-$fn");
}
I don't think we can just change the naming rules on the site because that would cause troubles to other users who are using the files.
jwz
Posts: 4
Joined: Mon Dec 21, 2009 4:36 am

Re: Kyu and dan levels on the sgf files

Post by jwz »

Thank you!

I can program, has been a whole I must say, but that will not be a problem.

Regards!
usagi
Posts: 3
Joined: Sat Jul 31, 2010 6:52 am

Re: Kyu and dan levels on the sgf files

Post by usagi »

tails wrote: If you have Perl installed in your system, then this script will rename the files for you. (...)
Great idea tails!

I noticed that the script doesn't handle some SGF files which include line breaks before the tags. This is a bit of a problem, in the current goproblemsSGF collection there are nearly 400 files it won't handle. So I changed your script a bit. This one works on all files. Thanks and good luck everyone.

Code: Select all

# by tails on 2008-10-23
# v1.1 by usagi on 2010-08-01
use strict;
use integer;

foreach my $fn (<*.sgf>) {
    my $f;
    open my $FILE, '<' , $fn or die "can't open $fn $!";

    my $di = 'x';
    my $dp = 'x';

    while (<$FILE>)
    {
      if ( /DI\[(.*?)\]/ )
      {
        $di = $1;
      }
      
      if ( /DP\[(.*?)\]/ )
      {
        $dp = sprintf("%03d",$1);
      }
    }

    rename($fn,"$dp-$di-$fn");
}
tails
Posts: 90
Joined: Thu Oct 23, 2008 12:10 pm

Re: Kyu and dan levels on the sgf files

Post by tails »

Thank you very much for the nice improvement, Usagi!
Post Reply