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

Ia7 #537

Merged
merged 11 commits into from
Sep 14, 2015
Merged
123 changes: 123 additions & 0 deletions code/common/ia7_phonelogs.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Category=IA7

#@ Code that loads the phone logs into the dynamic IA7 json data tables. User code needs to be
#@ added that hooks new_*_call into inbound and outbound calls.


#read in 3 files
# if record

use Data::Dumper;

#config parm, page size
my $page_size = 30;# unless config page size
my $field_line = 1;
my $field_type = 1;
my $logfiles = 3;



if ($Startup or $Reload) {
&json_table_create("phone_in");
my @phone_in_headers = ("Time","Phone Number","Name");
push (@phone_in_headers,"Line") if ($field_line);
push (@phone_in_headers,"Type") if ($field_type);
for my $i (0 .. $#phone_in_headers) {
&json_table_put_header("phone_in",$i,$phone_in_headers[$i]);
}
&get_phone_inbound_data(0,$page_size);
&json_table_set_page_size("phone_in",$page_size);
&json_table_set_fetch_routine("phone_in","get_phone_inbound_data")

&json_table_create("phone_out");
my @phone_out_headers = ("Time","Phone Number","Name");
push (@phone_out_headers,"Line") if ($field_line);
push (@phone_out_headers,"Type") if ($field_type);
for my $i (0 .. $#phone_out_headers) {
&json_table_put_header("phone_out",$i,$phone_out_headers[$i]);
}
&get_phone_outbound_data(0,$page_size);
&json_table_set_page_size("phone_out",$page_size);
&json_table_set_fetch_routine("phone_out","get_phone_outbound_data")

}

sub _get_data {
my ($type,$start, $recs) = @_;
#print "db: get_data type=$type start=$start recs=$recs\n";

my $log = $type;
my $table = "phone_" . $type;
$log = 'callerid' if $log eq 'in';
$log = 'phone' if $log eq 'out';

# read from call db
my $records = $start + $recs;
my @logs = &read_phone_logs1($log);
my @calls = &read_phone_logs2($records, @logs);
#print "db: logs=" . scalar @logs . " calls= " . scalar @calls;
my $count = -1;
$start = 0 unless ($start);
#need to filter to start...
for my $r (@calls) {
$count++;
next if ($count < $start);
my ($time, $num, $name, $line, $type) = $r =~ /date=(.+) number=(.+) name=(.+) line=(.*) type=(.*)/;
($time, $num, $name) = $r =~ /(.+\d+:\d+:\d+) (\S+) (.+)/ unless $name;
my $display_name = $name;
$display_name =~ s/_/ /g; # remove underscores to make it print pretty
#print "db: [$table] $count, $time, $num,$display_name\n";
next unless $num;

my $type_no = 3;
&json_table_put_data($table,$count,0,$time);
&json_table_put_data($table,$count,1,$num);
&json_table_put_data($table,$count,2,$display_name);
if ($field_line) {
&json_table_put_data($table,$count,3,$line);
$type_no = 4;
}
&json_table_put_data($table,$count,$type_no,$type) if ($field_type);
}
&json_table_push($table);

}

sub _new_call {
my ($table,$time,$number,$name,$line,$type) = @_;
my @data = ($time,$number,$name);
push (@data,$line) if ($field_line);
push (@data,$type) if ($field_type);
my $json_table = "phone_$table";
#print "db: time=$time number=$number name=$name line=$line type=$type\n";
#print "db:table=$json_table, data=[" . join(";", @data) . "]\n";
&json_table_insert_data_row($json_table,0,[@data])
&json_table_push($json_table);
}

sub get_phone_inbound_data {
my ($start, $recs) = @_;

&_get_data("in",$start,$recs);
}

sub get_phone_outbound_data {
my ($start, $recs) = @_;

&_get_data("out",$start,$recs);

}

sub new_inbound_call {
my ($time,$number,$name,$line,$type) = @_;

&_new_call("in",$time,$number,$name,$line,$type);
}

sub new_outbound_call {
my ($time,$number,$name,$line,$type) = @_;

&_new_call("out",$time,$number,$name,$line,$type);

}

18 changes: 9 additions & 9 deletions data/web/collections.json
Original file line number Diff line number Diff line change
Expand Up @@ -636,47 +636,47 @@
"117" : {
"icon" : "fa-leaf",
"name" : "Outdoor Temp",
"link" : "/bin/weather_graph.pl?tempout"
"link" : "/ia7/#path=/rrd?now-6hour?outdoor_temp"
},
"118" : {
"icon" : "wi-thermometer",
"name" : "Indoor Temp",
"link" : "/bin/weather_graph.pl?tempin"
"link" : "/ia7/#path=/rrd?now-6hour?indoor_temp"
},
"119" : {
"icon" : "wi-sprinkle",
"name" : "Outdoor Humidity",
"link" : "/bin/weather_graph.pl?humout"
"link" : "/ia7/#path=/rrd?now-6hour?outdoor_humid"
},
"120" : {
"icon" : "wi-sprinkles",
"name" : "Indoor Humidity",
"link" : "/bin/weather_graph.pl?humin"
"link" : "/ia7/#path=/rrd?now-6hour?indoor_humid"
},
"121" : {
"icon" : "wi-strong-wind",
"name" : "Wind Speed",
"link" : "/bin/weather_graph.pl?windspeed"
"link" : "/ia7/#path=/rrd?now-6hour?wind_speed"
},
"122" : {
"icon" : "fa-arrows",
"name" : "Wind Direction",
"link" : "/bin/weather_graph.pl?winddir"
"link" : "/ia7/#path=/rrd?now-6hour?wind_dir"
},
"123" : {
"icon" : "wi-rain",
"name" : "Total Rain",
"link" : "/bin/weather_graph.pl?raintotal"
"link" : "/ia7/#path=/rrd?now-6hour?rain"
},
"124" : {
"icon" : "wi-sprinkle",
"name" : "Rain Rate",
"link" : "/bin/weather_graph.pl?rainrate"
"link" : "/ia7/#path=/rrd?now-6hour?rain_rate"
},
"125" : {
"icon" : "wi-cloud-refresh",
"name" : "Baro Pressure",
"link" : "/bin/weather_graph.pl?press"
"link" : "/ia7/#path=/rrd?now-6hour?outside_press"
},

"92" : {
Expand Down
192 changes: 192 additions & 0 deletions data/web/ia7_rrd_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
{
"prefs" : {
"default_cf" :"AVERAGE",
"uom" : "celsius"
},
"ds" : {
"temp" : {
"type" : "temperature",
"label" : "Outside Temperature",
"color" : "#330099",
"round" : "1",
"group" : "outdoor_temp,temp"
},
"dew" : {
"type" : "temperature",
"label" : "Dew Point",
"color" : "#00ff00",
"round" : "1",
"group" : "outdoor_temp,temp"
},
"apparent" : {
"type" : "temperature",
"label" : "Apparent Temperature",
"color" : "#3300FF",
"round" : "1",
"group" : "outdoor_temp,temp"
},
"humid" : {
"type" : "humidity",
"label" : "Outside Humidity",
"color" : "#330099",
"round" : "1",
"group" : "outdoor_humid,humid"
},
"intemp" : {
"type" : "temperature",
"label" : "Indoor Temp",
"color" : "#2B65EC",
"round" : "1",
"group" : "indoor_temp,temp"
},
"tempspare1" : {
"type" : "temperature",
"label" : "Temp1",
"color" : "#FF0000",
"round" : "1",
"group" : "indoor_temp,temp"
},
"tempspare2" : {
"type" : "temperature",
"label" : "Temp2",
"color" : "#009933",
"round" : "1",
"group" : "indoor_temp,temp"
},
"tempspare3" : {
"type" : "temperature",
"label" : "Temp3",
"color" : "#FBB117",
"round" : "1",
"group" : "indoor_temp,temp"
},
"tempspare4" : {
"type" : "temperature",
"label" : "Temp4",
"color" : "#CC33CC",
"round" : "1",
"group" : "indoor_temp,temp"
},
"tempspare5" : {
"type" : "temperature",
"label" : "Temp5",
"color" : "#00FF00",
"round" : "1",
"group" : "indoor_temp,temp"
},
"tempspare6" : {
"type" : "temperature",
"label" : "Temp6",
"color" : "#FF99CC",
"round" : "1",
"group" : "indoor_temp,temp"
},
"tempspare7" : {
"type" : "bar",
"label" : "Main Heating",
"color" : "red",
"cf" : "MAX",
"group" : "area,temp"
},
"tempspare8" : {
"type" : "bar",
"label" : "Main Cooling",
"color" : "blue",
"cf" : "MAX",
"group" : "area"
},
"tempspare9" : {
"type" : "bar",
"label" : "Second Heating",
"color" : "red",
"cf" : "MAX",
"group" : "area,temp"
},
"tempspare10" : {
"type" : "bar",
"label" : "Second Cooling",
"color" : "blue",
"cf" : "MAX",
"group" : "area,temp"
},
"inhumid" : {
"type" : "humidity",
"label" : "Indoor Humidity",
"color" : "#990000",
"group" : "indoor_humid,humid"
},
"humidspare1" : {
"type" : "humidity",
"label" : "Humid 1",
"color" : "#FF0000",
"group" : "indoor_humid,humid"
},
"speed" : {
"type" : "speed",
"label" : "Wind Speed",
"color" : "#330099",
"group" : "wind_speed"
},
"dir" : {
"type" : "direction",
"label" : "Wind Direction",
"color" : "#330099",
"group" : "wind_dir"
},
"press" : {
"type" : "pressure",
"label" : "Barometer",
"color" : "#330099",
"group" : "outside_press"
},
"rain" : {
"type" : "rain",
"label" : "Total Rain",
"color" : "#3300FF",
"group" : "rain"
},
"rate" : {
"type" : "rain",
"label" : "Rain Rate",
"color" : "#330099",
"group" : "rain"
}
},
"options" : {
"legend": {
"show": "true"
},
"xaxis": {
"mode" : "time",
"timezone": "browser"
},
"grid": {
"hoverable" : "true"
},
"yaxes" : [{
"position" : "left"
},
{
"max" : "1",
"show" : "false",
"ticks" : 0
}],
"selection": {
"mode": "x"
}
},
"periods" : {
"1" : "6 hours,now-6hour",
"2" : "12 hours,now-12hour",
"3" : "1 day,now-1day",
"4" : "2 days,now-2day",
"5" : "1 week,now-1week",
"6" : "2 week,now-2week",
"7" : "1 month,now-1month",
"8" : "2 months,now-2month",
"9" : "6 months,now-6month",
"10" : "1 year,now-1year",
"11" : "2 years,now-2year",
"12" : "5 years,now-5year"
}
}
Loading