pricecharts

track prices of consumer electronics
Log | Files | Refs | README

commit 639a27bf7cd0d522120697ddc334ca8477c649e2
parent 65097d38adef0b4f6ac441a039d1e0d2b7c9c8ca
Author: Kyle Milz <kyle@getaddrinfo.net>
Date:   Sun, 15 Mar 2015 19:39:56 -0600

gen_svg: bring back online

Make colors work, give the path the last color encountered for a vendor, remove
found_one stuff. Add a product css class and put a border around search results.

Diffstat:
MMakefile | 3++-
Mgen_svg | 32++++++++++++++++----------------
Mhtml/pricechart.css | 6++++++
Mhtml/search.tt2 | 9++++++---
4 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/Makefile b/Makefile @@ -3,7 +3,7 @@ PERL_LIBDATA=/usr/local/libdata/perl5/site_perl HTDOCS=/var/www/htdocs DEV_BIN=/home/kyle/src/pricechart -BINS=price_scraper product_scraper gen_index pc_fcgi +BINS=price_scraper product_scraper gen_index pc_fcgi gen_svg LIBS=PriceChart.pm install: @@ -15,6 +15,7 @@ install: chmod 555 /etc/rc.d/pc_fcgi mkdir -p $(HTDOCS)/pricechart + mkdir -p $(HTDOCS)/pricechart/svg cp -R html/* $(HTDOCS)/pricechart/ chown -R www $(HTDOCS)/pricechart diff --git a/gen_svg b/gen_svg @@ -19,8 +19,11 @@ $| = 1 if ($args{v}); my $cfg = get_config(); my $dbh = get_dbh($cfg->{"general"}); -my $svg_dir = "/var/www/htdocs/pricechart/svg"; -mkdir $svg_dir; +my $svg_dir = $cfg->{"http"}{"chroot"} . $cfg->{"http"}{"htdocs"} . "/svg"; +print "info: rendering svgs to $svg_dir\n" if ($args{v}); +unless (-d $svg_dir) { + mkdir $svg_dir or die "can't mkdir $svg_dir: $!"; +} my ($left, $width, $right, $top, $height, $bottom) = (30, 900, 70, 20, 160, 20); my $total_width = $right + $width + $left; @@ -42,7 +45,6 @@ my $vendor_sth = $dbh->prepare($sql); $sql = "select manufacturer, part_num, description from products"; my $parts_sth = $dbh->prepare($sql); -my $found_one = undef; $parts_sth->execute(); while (my ($brand, $part_num, $description) = $parts_sth->fetchrow_array()) { $sql = "select min(date), max(date), min(price), max(price) " . @@ -56,8 +58,7 @@ while (my ($brand, $part_num, $description) = $parts_sth->fetchrow_array()) { my ($domain, $range) = ($x_max - $x_min, $y_max - $y_min); next if ($domain == 0 || $range == 0); - print "info: $part_num: domain = $domain, range = $range" if ($args{v}); - my $found_one = 1; + print "info: $part_num: domain = $domain, range = $range\n" if ($args{v}); my $svg = SVG->new(viewBox => "0 0 $total_width $total_height"); my ($x_scale, $y_scale) = ($width / $domain, $height / $range); @@ -65,10 +66,10 @@ while (my ($brand, $part_num, $description) = $parts_sth->fetchrow_array()) { $vendor_sth->execute($part_num); while (my ($vendor) = $vendor_sth->fetchrow_array()) { my $info_hdr = "info: $part_num: $vendor"; - print "$info_hdr\n" if ($args{v}); my (@xs, @ys); $point_sth->execute($part_num, $vendor); + my $line_color = "#000"; while (my ($date, $price, $color) = $point_sth->fetchrow_array) { push @xs, ($date - $x_min) * $x_scale + $left; push @ys, ($price - $y_min) * $y_scale + $top; @@ -77,12 +78,13 @@ while (my ($brand, $part_num, $description) = $parts_sth->fetchrow_array()) { cx => $xs[-1], cy => $ys[-1], r => 2, style => { - "fill" => $color, - "stroke" => $color + "fill" => "#$color", + "stroke" => "#$color" } ); + $line_color = $color; } - printf "$info_hdr: %i data pairs\n", scalar @xs if ($args{v}); + printf "$info_hdr (%i data pairs)\n", scalar @xs if ($args{v}); my $px = compute_control_points(\@xs); my $py = compute_control_points(\@ys); @@ -95,13 +97,14 @@ while (my ($brand, $part_num, $description) = $parts_sth->fetchrow_array()) { $xs[$_ + 1], $ys[$_ + 1] ); } + print "$info_hdr: making path, color = $line_color\n" if ($args{v}); $svg->path( d => $p, id => $vendor, style => { "fill-opacity" => 0, - # fill => $color, - # stroke => $color, + fill => "#$line_color", + stroke => "#$line_color", "stroke-width" => 2, } ); @@ -120,6 +123,7 @@ while (my ($brand, $part_num, $description) = $parts_sth->fetchrow_array()) { values => "0;1000", dur => "0.8s", fill => "freeze", + -method => "" ); my $num_labels = 5; @@ -153,7 +157,7 @@ while (my ($brand, $part_num, $description) = $parts_sth->fetchrow_array()) { $svg->text( id => "time_$time", x => $x, y => $total_height, - style => "font-size: 14px; fill: #666", + style => "font-size: 12px; fill: #666", "text-anchor" => "middle" )->cdata($date); @@ -172,10 +176,6 @@ while (my ($brand, $part_num, $description) = $parts_sth->fetchrow_array()) { close $svg_fh; } -unless ($found_one && $args{v}) { - print "info: no products with non-zero domain and range found\n"; -} - # print $log @$part_nums . " products generated\n"; # close $log; diff --git a/html/pricechart.css b/html/pricechart.css @@ -35,6 +35,12 @@ p { float: left; } +.product { + border: 1px solid black; + padding: 10px; + margin: 10px; +} + @media (max-width: 640px) { .column { width: 90%; diff --git a/html/search.tt2 b/html/search.tt2 @@ -8,8 +8,11 @@ for <b>[% query %]</b>:</p> [% FOREACH part_num IN results %] - [% part_num.1 %] [% part_num.2 %] ([% part_num.0 %])<br> - <object data="/svg/[% part_num.0 %].svg" type="image/svg+xml"> - </object> + <div class="product"> + <b>[% part_num.1 %]</b> [% part_num.0 %]<br> + [% part_num.2 %] <br> + <object data="/svg/[% part_num.0 %].svg" type="image/svg+xml"> + </object> + </div> [% END %] [% END %]