Permalink
Browse files

Checkpoint save.

  • Loading branch information...
1 parent 96070b4 commit 9ab90d258491347861547ef48df4ff39c54905fa Barry Carter committed Oct 24, 2011
Showing with 108 additions and 84 deletions.
  1. +1 −1 bc-delaunay-temperature.pl
  2. +2 −75 bc-get-cycle-files.pl
  3. +2 −2 bc-kml-lib.pl
  4. +6 −6 bc-pennyauction-sniff.pl
  5. 0 bc-svgtile.pl
  6. +97 −0 bc-voronoi-temperature.pl
@@ -146,7 +146,7 @@
system("zip file3.kmz file3.kml");
# this file is generated on a different machine, so copy file over
-system("rsync /tmp/bcdtp/file3.kmz root\@data.barrycarter.info:/sites/DATA/current-temperatures.kmz");
+system("rsync /tmp/bcdtp/file3.kmz root\@data.barrycarter.info:/sites/DATA/current-delaunay.kmz");
# sleep 2.5 minutes and call myself again
sleep(150);
View
@@ -102,6 +102,8 @@
}
+die "TESTING";
+
# rsync (uses private key)
system("rsync ../weather.db root\@barrycarter.info:/sites/DB/weather.db.new");
system("ssh root\@barrycarter.info 'cd /sites/DB; mv weather.db weather.db.old; mv weather.db.new weather.db'");
@@ -113,78 +115,3 @@
# TODO: use entire command line, not just $0
sleep(10);
exec("$0 --debug");
-
-# note: all routines below hardcode, which is ok, since they're not
-# intended to be general
-
-# thin wrapper around parse_metar
-sub handle_metar {
- my($file) = @_;
- debug("HANDLE_METAR($file)");
- my($data) = read_file($file);
-
- for $i (split(/\n/, $data)) {
- # ignore empty, comments, NIL=
- if ($i=~/\#|^\s*$|^\s*NIL\=$/) {next;}
- $i=~s/^(METAR|SPECI)\s*//isg;
- push(@queries, hash2query(parse_metar($i)));
- }
-
- transact(@queries);
-}
-
-# trivial wrapper around parse_ship
-sub handle_ship {
- my($file) = @_;
- debug("HANDLE_SHIP($file)");
- my($data) = read_file($file);
- my(@queries);
- while ($data=~s/BBXX\s*(.*?)\s*\=//s) {
- $i = $1;
- $i=~s/\s+/ /isg;
- push(@queries, hash2query(parse_ship($i)));
- }
-
- transact(@queries);
-}
-
-sub handle_buoy {
- my($file) = @_;
- debug("HANDLE_BUOY($file)");
- my($data) = read_file($file);
- my(@queries);
- while ($data=~s/ZZYY\s*(.*?)\s*\=//s) {
- $i = $1;
- $i=~s/\s+/ /isg;
- push(@queries, hash2query(parse_buoy($i)));
- }
-
- transact(@queries);
-}
-
-# below not yet used
-sub handle_synop {}
-
-# convert hash to query (trivial)
-sub hash2query {
- my(%hash) = @_;
- my(@vals);
-
- for $i (@fields) {push(@vals, "'$hash{$i}'");}
-
- my($keys) = join(", ", @fields);
- my($vals) = join(", ", @vals);
-
- return "REPLACE INTO weather ($keys) VALUES ($vals)",
- "REPLACE INTO nowweather ($keys) VALUES ($vals)";
-}
-
-# send bunch of queries to weather.db in transaction
-sub transact {
- my(@queries) = @_;
- unshift(@queries, "BEGIN");
- push(@queries, "COMMIT");
- my($now) = stardate(time()).$$;
- write_file(join(";\n",@queries).";\n", "../commands.$now");
- system("sqlite3 ../weather.db < ../commands.$now 1> ../$now.out 2> ../$now.err");
-}
View
@@ -23,8 +23,8 @@ sub voronoi_map {
open(A,">$tmpfile.kml");
# header/footer
- my($header) = read_file("kmlhead.txt");
- my($footer) = read_file("kmlfoot.txt");
+ my($header) = read_file("/usr/local/lib/kmlhead.txt");
+ my($footer) = read_file("/usr/local/lib/kmlfoot.txt");
print A "$header\n";
# the Voronoi diagram
@@ -9,7 +9,7 @@
# TODO: get these numbers directly, don't hardcode
# Ugly possibility: include ALL numbers 1-999 below (penny handles
# this, but yuck)
-$ids = "207,265";
+$ids = "313";
# TODO: fix cache_command so I don't have to do this
$globopts{nocache} = 1;
@@ -45,8 +45,8 @@
# age of bid
$age = $cur - $lastbid{$i}{$j};
- # kill bids over 60s
- if ($age > 60) {
+ # kill bids over 2m
+ if ($age > 120) {
delete $lastbid{$i}{$j};
next;
}
@@ -56,10 +56,10 @@
print "$i: ".join(", ",@bidders)."\n";
- # alert me when exactly 2 bidders
- if ($#bidders == 1) {
+ # alert me when down to 3 bidders
+ if ($#bidders <= 2) {
system("pkill -f 'PENNY: $i'");
- system("xmessage 'PENNY: $i has 2 bidders' &");
+ system("xmessage 'PENNY: $i has 3 bidders' &");
}
}
View
0 bc-svgtile.pl 100644 → 100755
No changes.
@@ -0,0 +1,97 @@
+#!/bin/perl
+
+# bc-voronoi-temperature (not to be confused w bc-temperature-voronoi)
+# is a clone of bc-delaunay-temperature, but using voronoi instead of
+# delaunay
+
+# NOTE: this program starts off as an exact copy of delaunay
+
+push(@INC,"/home/barrycarter/BCGIT", "/usr/local/bin/");
+require "bclib.pl";
+require "bc-weather-lib.pl";
+require "bc-kml-lib.pl";
+
+# all work in temporary directory
+chdir("/tmp/bcvtp");
+
+# obtain current weather
+@w = recent_weather();
+
+for $i (@w) {
+ %hash = %{$i};
+
+ # confirm numeric
+ unless ($hash{latitude}=~/^[0-9\-\.]+$/ && $hash{longitude}=~/^[0-9\-\.]+$/) {
+# warn("BAD DATA: %hash");
+ next;
+ }
+
+ # TODO: mercator version?
+ # fields for voronoi_map()
+ $hash{x} = $hash{longitude};
+ $hash{y} = $hash{latitude};
+ $hash{id} = $hash{station_id};
+ $hash{label} = ""; # TODO: change this, maybe
+ $f= $hash{temp_c}*1.8+32;
+ $hue = 5/6-($f/100)*5/6;
+ $hash{color} = hsv2rgb($hue, 1, 1, "kml=1&opacity=80");
+ push(@wok, {%hash});
+
+}
+
+$res = voronoi_map(\@wok);
+
+# this file is generated on a different machine, so copy file over
+system("rsync $res root\@data.barrycarter.info:/sites/DATA/current-voronoi.kmz");
+
+# sleep 2.5 minutes and call myself again
+sleep(150);
+exec($0);
+
+# TODO: reinstate this code for Voronoi maps
+# update time in various timezones (silly!)
+
+=item comment
+
+$now = time(); # just so we don't get second slippage
+
+for $i ("UTC", "EST5EDT", "MST7MDT", "Japan") {
+ $ENV{TZ} = $i;
+ push(@desc, strftime("%c", localtime($now)));
+}
+
+$desc = join("<br>\n", @desc);
+
+open(A,">file3.kml");
+
+# special marker below is at 4 Corners + indicates update time
+print A << "MARK";
+<?xml version="1.0" encoding="UTF-8"?>
+<kml xmlns="http://www.opengis.net/kml/2.2">
+<Document>
+
+<Placemark>
+<name>Last updated:</name>
+<description>
+<![CDATA[
+<font size=-1>
+$desc
+</font>
+]]>
+</description>
+<Point>
+<coordinates>-109,37</coordinates>
+</Point>
+</Placemark>
+
+MARK
+;
+
+print A join("\n", @kml);
+print A "\n</Document></kml>\n";
+close(A);
+
+system("zip file3.kmz file3.kml");
+
+=cut
+

0 comments on commit 9ab90d2

Please sign in to comment.