Skip to content
Browse files

Merge branch 'ttlogmerge'

Conflicts:
	beeminder.pl
  • Loading branch information...
2 parents f83107e + 0892eec commit 34b75fcea48ddb2bc12e322d921953cd93b3cc81 @pmyteh committed Feb 26, 2014
Showing with 34 additions and 14 deletions.
  1. +9 −4 beeminder.pl
  2. +25 −10 script/ttlogmerge.pl
View
13 beeminder.pl
@@ -41,9 +41,9 @@
my $start = time; # start and end are the earliest and latest times we will
my $end = 0; # need to care about when updating beeminder.
# bflag is true if we need to regenerate the beeminder cache file. reasons we'd
-# need to: 1. it doesn't exist; 2. any beeminder IDs are missing from the
-# cache file; 3. there are multiple datapoints for the same day.
-$bflag = (!-e $beef);
+# need to: 1. it doesn't exist or is empty; 2. any beeminder IDs are missing
+# from the cache file; 3. there are multiple datapoints for the same day.
+$bflag = (!-s $beef);
my $bf1 = 0; my $bf2 = 0; my $bf3 = 0; my $bf4 = 0; # why bflag?
$bf1 = 1 if $bflag;
undef %remember; # remember which dates we've already seen in the cache file
@@ -93,7 +93,7 @@
my $tmp = $beef; $tmp =~ s/(?:[^\/]*\/)*//; # strip path from filename
if($bf1) {
- print "Cache file missing ($tmp); recreating... ";
+ print "Cache file missing or empty ($tmp); recreating... ";
} elsif($bf2) {
print "Cache file doesn't have all the Bmndr IDs; recreating... ";
} elsif($bf3) {
@@ -192,10 +192,12 @@
$nadd++;
$plus += $p1;
$bh{$ts} = beemcreate($usr,$slug,$t, $p1*$ping, splur($p1,"ping").": ".$s1);
+ #print "Created: $y $m $d ",$p1*$ping," \"$p1 pings: $s1\"\n";
} elsif($p0 > 0 && $p1 <= 0) { # on beeminder but not in tagtime log: DELETE
$ndel++;
$minus += $p0;
beemdelete($usr, $slug, $b);
+ #print "Deleted: $y $m $d ",$p0*$ping," \"$p0 pings: $s0 [bID:$b]\"\n";
} elsif($p0 != $p1 || $s0 ne $s1) { # bmndr & tagtime log differ: UPDATE
$nchg++;
if ($p1 > $p0) { $plus += ($p1-$p0); }
@@ -210,6 +212,9 @@
# though simply deleting the cache file and waiting for next time is less
# Intrusive. Deleting the cache files when merging two TT logs would reduce
# the scope for this somewhat.
+ #print "Updated:\n";
+ #print "$y $m $d ",$p0*$ping," \"$p0 pings: $s0 [bID:$b]\" to:\n";
+ #print "$y $m $d ",$p1*$ping," \"$p1 pings: $s1\"\n";
} else {
print "ERROR: can't tell what to do with this datapoint (old/new):\n";
print "$y $m $d ",$p0*$ping," \"$p0 pings: $s0 [bID:$b]\"\n";
View
35 script/ttlogmerge.pl
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-# Syntax: ttlogmerge.pl logfile1 logfile2 outputlogfile
+# Syntax: ttlogmerge.pl logfile1 logfile2 [outputlogfile]
#
# A helper script for the Unison file synchroniser. One option for Unison is to
# use an external program to merge two files which have been change in both
@@ -27,7 +27,16 @@
sub longer
{
- (length($_[0]) >= length($_[1])) ? $_[0] : $_[1];
+ my $a = shift;
+ my $b = shift;
+ length(&removeautotags($a)) >= length(&removeautotags($b)) ? $a : $b;
+}
+
+sub removeautotags
+{
+ my $s = shift;
+ $s =~ s/\b(afk|off|RETRO|\[missed ping from \d+s ago\])\b//g;
+ return $s;
}
sub parse
@@ -37,9 +46,9 @@ sub parse
my @tokens = split(/\s+/, $s);
# XXX FIXME: This may fail where huge numbers of tags are added:
# It appears TT shortens the human-readable date string to stay
- # under 80 characters per line.
+ # under 80 characters per line if possible.
for my $i (1..3) { pop(@tokens) } # Discard date string
-# print "parse: ", $_[0], @tokens;
+# print STDERR "parse: ", $_[0], @tokens;
return @tokens;
}
@@ -48,13 +57,19 @@ sub parse_timestamp
{
my $s = $_[0];
my @tokens = split(/\s+/, $s);
- print "parse_timestamp: ", $tokens[0];
+ print STDERR "parse_timestamp: ", $tokens[0];
return $tokens[0];
}
-open(my $f1, "<", $ARGV[0]) or die;
-open(my $f2, "<", $ARGV[1]) or die;
-open(my $fo, ">", $ARGV[2]) or die;
+open(my $f1, "<", shift) or die;
+open(my $f2, "<", shift) or die;
+my $outn = shift;
+my $fo;
+if ($outn) {
+ open($fo, ">", $outn) or die;
+} else {
+ open($fo, '>&', \*STDOUT) or die;
+}
# TODO: Should open the config file, and if we can, delete the .bee files
# associated with it. For extra credit, we should only remove the ones
@@ -117,12 +132,12 @@ sub parse_timestamp
# Any non-undefined files have unprocessed data in $lx
if (defined $l1) {
do {
-# print "Extra line in f1. Writing.\n", $l1;
+# print STDERR "Extra line in f1. Writing.\n", $l1;
print $fo $l1
} while ($l1 = <$f1>);
} elsif (defined $l2) {
do {
-# print "Extra line in f2. Writing.\n", $l2;
+# print STDERR "Extra line in f2. Writing.\n", $l2;
print $fo $l2
} while ($l2 = <$f2>);
}

0 comments on commit 34b75fc

Please sign in to comment.
Something went wrong with that request. Please try again.