• Willkommen im Geoclub - dem größten deutschsprachigen Geocaching-Forum. Registriere dich kostenlos, um alle Inhalte zu sehen und neue Beiträge zu erstellen.

AuxSort anhand eines Counter Coins

ChristianGK

Geonewbie
Hallo und erst mal Danke an HSCA und fogg für das tolle Tool.
Habe eine Idee zur weiterentwicklung.
Nachdem es ja doch recht aufwändig ist jede einzelne note.txt zu bearbeiten und dann das auch noch in der richtigen Reihenfolge, dachte ich mir, dass es doch ganz praktisch wäre wenn die Einträge anhand eine Counter Coins passieren würden.

Gruß
Christian
 

HSCA

Geomaster
Hi Christian,

über die Variante mit dem Coin habe ich auch schon nachgedacht, bin dabei aber auch wieder auf das Problem gestoßen, das hier wieder die Logreihenfolge entscheident sein müsste. (und die bekomme zumindestens ich nicht auf die Reihe :roll: )

Eine Lösung, die bei mir den Einsatz gefunden hat, ist eine Kennung in jedem Log, das geschrieben wird. Meine Kennung sieht so aus

[#(wer war mit), (wer hat gefunden), (wann haben wir gefunden), (wie sind wir hin), (der wievielte am Tag war das)]
also in der Praxis sieht das in etwa so aus.
[#HSCA, C, 12:23, car, 01]

Diese Information lasse ich mir per Skript aus den logs extrahieren und dann in die entsprechenden Zeilen der note.txt eintragen. Dabei habe ich auch keine Probleme mehr, wenn ich meine Logs in ungeordneter Reihenfolge schreibe.

Vielleicht hift dir das ja schon weiter. Das Skript kann ich dir gerne zukommen lassen.

Ein Wandertagebuch meiner Coins schwebt mir seit längerer Zeit auch schon immer mal wieder durch den Kopf. Bisher fehlte nur die Zeit für die Umsetzung.

Gruß, C
 

huzzel

Geowizard
Kannst Du das Script evtl hier einstellen?
Hätte da auch Interesse dran.
Kann man es auch individuell anpassen?
 

HSCA

Geomaster
huzzel schrieb:
Kann man es auch individuell anpassen?
Natürlich, ist ja perl ;)

huzzel schrieb:
Kannst Du das Script evtl hier einstellen?
Code:
#!/usr/bin/perl

use strict;
use warnings;

use FindBin;
my(%legalfield) =  ( Name => 1, 
		     GCid => 1, 
		     Coordinates => 1,
		     Status => 1,
		     Type => 1, 
		     Container => 1, 
		     Difficulty => 1, 
		     Terrain => 1, 
		     Hidden => 1, 
		     Country => 1, 
		     State => 1,
		     Attributes => 1,
		     Found => 1, 
		     AuxSort => 1,
		     NotFound => 1, 
		     LaterFound => 1, 
		     Elevation => 1, 
		     Up => 1, 
		     Category => 1, 
		     AltCategory1 => 1, 
		     AltCategory2 => 1, 
		     Access => 1, 
		     Search => 1, 
		     OverallTime => 1, 
		     Judgement => 1, 
		     NCId => 1,
		     OCId => 1,
		     OCCacheId => 1,
		     Owner => 1,
		     Ownerguid => 1,
		     Reason => 1,
		     Optional1 => 1,
		     Optional2 => 1,
		     Optional3 => 1,
		     Finds => 1,
		     DNFs => 1,
		     FTF => 1,
		     LastFound => 1,
		     FindRate => 1,
		     LastArchived => 1,
		     Maintenance => 1);

#global profile vars
my($profile, $profiledir);

#global vars
my($oldh);
my($oldfh);
my($rem_cm)=1;
my($directory);

my(@founddir) = ();
my(@notfounddir) = ();
my(@foundwpt) = ();
my(@notfoundwpt) = ();

my(%data);
my(%seen);

sub profile_used {
    my($path) = @_;
    return ((-e $path . "/profile.txt"));
}

sub find_profiledir {
  $profiledir = File::Spec->rel2abs($FindBin::Bin . "/../.geolog");
  return if (profile_used($profiledir));
}

sub read_profile {
#read geolog profile for directory, editor
    if(!open(RC, "< $profile")){
	die("\nKann das Profil $profile nicht lesen");
    }
    while (<RC>) {
	chomp;
	if (/^directory: (.*)$/){
	    $directory = $1;
	}
    }
    close(RC);
}

sub collect_present_cachedata {
#read directories
    opendir(DIR, $directory . "/found");
    @founddir = readdir(DIR);
    close(DIR);
    opendir(DIR, $directory . "/not-found");
    @notfounddir = readdir(DIR);
    close(DIR);
    @foundwpt = setWpt("found",@founddir);
    @notfoundwpt = setWpt("notfound",@notfounddir);
}

sub setWpt {
    my($type,@dirlist) = @_;
    my(@gclist, $ent, $wpt);
    foreach $ent (@dirlist) {
	if ($ent =~ /^.*_(GC[A-Z0-9]+)$/mi) {
	    $wpt = $1;
	    $seen{$type}->{$wpt} = 1;
	    push(@gclist,$wpt);
	}
    }
    return(@gclist);
}

sub extract_fields {
    my($path, $id, $file) = @_;
    my($line);

    if(-f $path . "/" . $file) {
	open(FLDS, "<" . $path . "/" . $file) or
	    print "\nKann " . $path . "/" . $file . " nicht öffnen";
	while(<FLDS>) {
	    chomp();
	    s/\r//g if ($rem_cm);
	    $line = $_;
	    if($line =~ /^(.*?): (.+)$/) {
		print "\nFalsches oder fehlerhaftes Feld $1 ind $id/$file\n" unless $legalfield{$1};
		$data{$id}->{$1} = $2;
	    }
	}
	close(FLDS);
    }
}

sub process_notes {
    my($ent);
    my($team,$finder,$time,$access,$auxsort,$reason);
    my($oldteam,$oldfinder,$oldtime,$oldaccess,$oldauxsort);
    my($line);
    my($path) = $directory . "/found";
    my($zeichen);
    my(@param);
    my(@newnote);
    my($refresh);
    my($entry,$old,$new);
    foreach $ent (@founddir) {
      if (($ent =~ /^.*_(GC[A-Z0-9]+)$/mi) || ($ent =~ /^.*_(OC[A-Z0-9]+)$/mi)) {
        $team = " ";
        $finder = " ";
        $time = " ";
        $access = " ";
        $auxsort = " ";
        if(-f $path . "/" . $ent . "/log.txt")
        {        
          open(FILE, "<" . $path . "/" . $ent . "/log.txt") or
          die( "\nKann " . $ent . "/log.txt nicht öffnen");
          while(<FILE>) {
            $line = ();
            $line = $_;
            #print "\n" . $line;
            if($line =~ m/\[#([A-Za-z0-9:, ]+)/) {
              @param = split(/,/,$1);
              $team = $param[0];
              $team =~ s/^\s+//;
              $finder = $param[1];
              $finder =~ s/^\s+//;
              $time = $param[2];
              $time =~ s/^\s+//;
              $access = $param[3];
              $access =~ s/^\s+//;
              $access = $access . ".gif";
              $auxsort = $param[4];
              $auxsort =~ s/^\s+//;
              #print "\n" . $team . $finder . $time . $access . $auxsort;
            } 
            else {
              print "\nno string found for " . $ent;
            }
          }
          close(FILE);
        }
        @newnote = ();
        $refresh = 0;
        #Eintrag überprüfen
        if(-f $path . "/" . $ent . "/note.txt") {
          if(!open(FILE, "<" . $path . "/" . $ent . "/note.txt")) {
              die( "\nKann " . $ent . "\/note.txt nicht oeffnen"); 
          }
          while(<FILE>){
            $entry = ();
            $entry = $_;
            my($found) = 1;
            $old = " ";
            #print "\n" . $entry;
            if ($entry =~ /^AuxSort: (.*)$/){
              $old = $auxsort;
            } elsif ($entry =~ /^Access: (.*)$/) {
              $old = $access;
            } elsif ($entry =~ /^Optional1: (.*)$/) {
              $old = $team;
            } elsif ($entry =~ /^Optional2: (.*)$/) {
              $old = $finder;
            } elsif ($entry =~ /^Optional3: (.*)$/) {
              $old = $time;
            } else {
              $found = 0;
            }
            if($found eq 1)
            {
              if($1 ne $old) {
                $new = $old;
                if($entry =~  m/^([A-Za-z0-9]+).*$/) {
                  push(@newnote, $1 . ": " . $new . "\n");
                  $refresh = 1;
                }
              } else {
                push(@newnote, $entry);
              }
            } else {
              push(@newnote, $entry);
            }
          }
          close(FILE);
        }
        #Datei neu schreiben wenn Änderung aufgetreten
        if($refresh eq 1) {
          write_to_file ( $path . "/" . $ent ."/note.txt", \@newnote );
        }
      }
    }
    $path = $directory . "/not-found";
    foreach $ent (@notfounddir) {
      if (($ent =~ /^.*_(GC[A-Z0-9]+)$/mi) || ($ent =~ /^.*_(OC[A-Z0-9]+)$/mi)) {
        $team = " ";
        $reason = " ";
        $time = " ";
        $access = " ";
        $auxsort = " ";
        if(-f $path . "/" . $ent . "/log.txt") {
        open(FILE, "<" . $path . "/" . $ent . "/log.txt") or
          die( "\nKann " . $ent . "/log.txt nicht öffnen");
        while(<FILE>) {
          $line = ();
          $line = $_;
          #print "\n" . $line;
          if($line =~ m/\[#([A-Za-z0-9:, ]+)/) {
            @param = split(/,/,$1);
            $team = $param[0];
            $team =~ s/^\s+//;
            $reason = $param[1];
            $reason =~ s/^\s+//;
            $reason = $reason . ".gif";
            $time = $param[2];
            $time =~ s/^\s+//;
            $access = $param[3];
            $access =~ s/^\s+//;
            $access = $access . ".gif";
            $auxsort = $param[4];
            $auxsort =~ s/^\s+//;
            print "\n" . $ent . $team . $reason . $time . $access . $auxsort;
          }
          else {
            print "\nno string found for " . $ent;
          }
        }
        close(FILE);
        }
        @newnote = ();
        $refresh = 0;
        #Eintrag überprüfen
        if(-f $path . "/" . $ent . "/note.txt") {
        if(!open(FILE, "<" . $path . "/" . $ent . "/note.txt")) {
            #die( "\nKann " . $ent . "\/note.txt nicht oeffnen"); 
            next;
        }
        while(<FILE>){
          $entry = ();
          $entry = $_;
          my($found) = 1;
          $old = " ";
          #print "\n" . $entry;
          if ($entry =~ /^AuxSort: (.*)$/){
            $old = $auxsort;
          } elsif ($entry =~ /^Access: (.*)$/) {
            $old = $access;
          } elsif ($entry =~ /^Optional1: (.*)$/) {
            $old = $team;
          } elsif ($entry =~ /^Reason: (.*)$/) {
            $old = $reason;
          } elsif ($entry =~ /^Optional3: (.*)$/) {
            $old = $time;
          } else {
            $found = 0;
          }
          if($found eq 1)
          {
            if($1 ne $old) {
              $new = $old;
              if($entry =~  m/^([A-Za-z0-9]+).*$/) {
                push(@newnote, $1 . ": " . $new . "\n");
                $refresh = 1;
              }
            } else {
              push(@newnote, $entry);
            }
          } else {
            push(@newnote, $entry);
          }
        }
        close(FILE);
        }
        #Datei neu schreiben wenn Änderung aufgetreten
        if($refresh eq 1) {
          write_to_file ( $path . "/" . $ent ."/note.txt", \@newnote );
        }
      }
    }
    print "alle Eintraege ausgewaertet";
}


sub write_to_file {

    my ( $filename, $txt2write) = @_;
    my($line);
    open(FILE, ">" . $filename);
    foreach $line(@$txt2write) {
	print FILE $line;
    }
    close(FILE);
}

sub mainprog {
    $rem_cm = 1;

    $oldh = select(STDOUT);
    $| = 1;
    select($oldh);

    $oldfh = select(STDERR);
    $| = 1;
    select($oldfh);

    find_profiledir();
    $profile = $profiledir . "/profile.txt";

    read_profile();
    #print $directory . "\n";
    collect_present_cachedata();
    process_notes();
}

eval 'mainprog()';
exit(0);

Benutzung natürlich auf eigene Gefahr ;)

C
 

HSCA

Geomaster
ChristianGK schrieb:
Ich verstehe nich wo dein Problem ist.

Ich habe kein Problem damit. In dem Fall habe ich nur die Sache aus meinem Cacheverhalten beurteilt und festgestellt, dass die Informationen aus meinem Countercoin dafür nicht passen würden, da ich die Caches nicht in meiner Fundreihenfolge logge. Das war auch schon alles.

Das ermitteln der TB-Daten würde ich aber ähnlich wie ocprop in einem extra Programm sehen, welches seine Informationen dann in geolog einbindet.

C
 
OP
C

ChristianGK

Geonewbie
OK, ich war mir nur nicht sicher ob du verstanden hast was ich sagen wollte ;-)
Plant ihr da etwas in der Hinsicht zu machen?

Gruß
Christian
 
Oben