From 2a0a5f3a7aceca23993fa33aa012b9ccf5d1eade Mon Sep 17 00:00:00 2001 From: dakkar Date: Wed, 20 Mar 2019 13:43:48 +0000 Subject: plot the data from the BT server --- cpanfile | 3 +++ plot-log-plotly.pl | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 cpanfile create mode 100644 plot-log-plotly.pl diff --git a/cpanfile b/cpanfile new file mode 100644 index 0000000..0bbcc54 --- /dev/null +++ b/cpanfile @@ -0,0 +1,3 @@ +# -*- mode: perl -*- +requires 'Path::Tiny'; +requires 'Chart::Plotly'; diff --git a/plot-log-plotly.pl b/plot-log-plotly.pl new file mode 100644 index 0000000..27992af --- /dev/null +++ b/plot-log-plotly.pl @@ -0,0 +1,52 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.026; +use Path::Tiny; + +use Chart::Plotly; +use Chart::Plotly::Plot; +use Chart::Plotly::Trace::Scatter; + +my @rows = path($ARGV[0])->lines_utf8({chomp=>1}); + +my @column_names = qw(humidity temperature battery); +my %data_for_src; +for my $row (@rows) { + my %data;my $src; + ($data{dt},$src,@data{@column_names}) = + $row =~ m{ + \A \s* + ( \d{4}-\d{2}-\d{2} \s+ \d{2}:\d{2}:\d{2} ) + \s+ + (?: [0-9a-f:]+ ):([0-9a-f]+) # only take the last byte of the MAC, it's enough + \s+ + ( [0-9.]+ ) + \s+ + ( [0-9.]+ ) + \s+ + ( [0-9.]+ ) + \s* \z + }x or next; + for my $column ('dt',@column_names) { + push $data_for_src{$src}->{$column}->@*, $data{$column} + } +} + +my %plots; +for my $column (@column_names) { + my $plot = Chart::Plotly::Plot->new( + layout => { title => $column }, + ); + for my $src (sort keys %data_for_src) { + my $trace = Chart::Plotly::Trace::Scatter->new( + x => $data_for_src{$src}->{dt}, + y => $data_for_src{$src}->{$column}, + name => $src, + ); + $plot->add_trace($trace); + } + $plots{$column} = $plot; +} + +Chart::Plotly::show_plot(@plots{@column_names}); -- cgit v1.2.3