Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TT on multiple machines final(?) patchset #38

Merged
merged 7 commits into from Feb 28, 2014
Merged
15 changes: 10 additions & 5 deletions beeminder.pl
Expand Up @@ -19,7 +19,7 @@
$usrslug = shift; # like alice/weight
$usrslug =~ /^(?:.*?(?:\.\/)?data\/)?([^\+\/\.]*)[\+\/]([^\.]*)/;
($usr, $slug) = ($1, $2);
$beef = "$usr+$slug.bee"; # beef = bee file (cache of data on bmndr)
$beef = "${path}$usr+$slug.bee"; # beef = bee file (cache of data on bmndr)

if(defined(@beeminder)) { # for backward compatibility
print "Deprecation warning: Get your settings file in line!\n";
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -185,15 +185,20 @@
$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); }
elsif($p1 < $p0) { $minus += ($p0-$p1); }
beemupdate($usr, $slug, $b, $t, ($p1*$ping), splur($p1,"ping").": ".$s1);
#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";
Expand Down
35 changes: 25 additions & 10 deletions 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
Expand All @@ -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
Expand All @@ -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;
}

Expand All @@ -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;
}

# Read initial lines from files
my $l1 = <$f1>;
Expand Down Expand Up @@ -112,12 +127,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>);
}
Expand Down