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

Insteon: Change Hopcount Calculation to a Moving Average #266

Merged
merged 4 commits into from
Oct 20, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions lib/Insteon/BaseInsteon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -258,22 +258,31 @@ Returns the highest hop count of the past 20 hop counts
sub default_hop_count
{
my ($self, $hop_count) = @_;
unshift(@{$$self{hop_array}}, $$self{default_hop_count}) if (!defined(@{$$self{hop_array}}));
if (defined($hop_count)){
::print_log("[Insteon::BaseObject] DEBUG3: Adding hop count of " . $hop_count . " to hop_array of "
. $self->get_object_name) if $main::Debug{insteon} >= 3;
unshift(@{$$self{hop_array}}, $hop_count)
}
pop(@{$$self{hop_array}}) if (scalar(@{$$self{hop_array}}) >20);
my $high = 0;
foreach (@{$$self{hop_array}}){
$high = $_ if ($high < $_);;
if (!defined(@{$$self{hop_array}})) {
unshift(@{$$self{hop_array}}, $$self{default_hop_count});
$$self{hop_sum} = $$self{default_hop_count};
}
#Calculate a simple moving average
unshift(@{$$self{hop_array}}, $hop_count);
$$self{hop_sum} += ${$$self{hop_array}}[0];
$$self{hop_sum} -= pop(@{$$self{hop_array}}) if (scalar(@{$$self{hop_array}}) >10);
$$self{default_hop_count} = int(($$self{hop_sum} / scalar(@{$$self{hop_array}})) + 0.5);

::print_log("[Insteon::BaseObject] DEBUG4: ".$self->get_object_name
."->default_hop_count()=".$$self{default_hop_count}
." :: hop_array[]=". join("",@{$$self{hop_array}}))
if $main::Debug{insteon} >= 4;
}
$$self{default_hop_count} = $high;

#Allow for per-device settings
$$self{default_hop_count} = $$self{max_hops} if ($$self{max_hops} &&
$$self{default_hop_count} > $$self{max_hops});
$$self{default_hop_count} = $$self{min_hops} if ($$self{min_hops} &&
$$self{default_hop_count} < $$self{min_hops});
$$self{default_hop_count} < $$self{min_hops});

return $$self{default_hop_count};
}

Expand Down Expand Up @@ -1714,7 +1723,8 @@ Hop Count, Engine Version, ALDB Type, ALDB Health, and Last ALDB Scan Time
sub log_aldb_status
{
my ($self) = @_;
main::print_log( " Hop Count: ".$self->default_hop_count());
main::print_log( " Device ID: ".$self->device_id());
main::print_log( " Hop Count: ".$self->default_hop_count()." :: [". join("",@{$$self{hop_array}})."]");
main::print_log( "Engine Version: ".$self->engine_version());
my $aldb = $self->get_root()->_aldb;
if ($aldb)
Expand Down