blib/lib/Algorithm/MOS.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 36 CC 2 SCAR 12.0
CC
2
Cov
0%
mos
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.3
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 package Algorithm::MOS;
5 # ABSTRACT: Algorithm::MOS - Calculate MOS (Mean Opinion Score)
6  
7 use Carp;
8  
9 use parent 'Exporter';
10 our @EXPORT = ('calc_mos');
11  
12 sub mos {
13 my ( $average, $jitter, $packet_loss ) = @_
14 or croak 'mos( average, jitter, packet_loss )';
15  
16 my $r_value;
17 my $ret_val;
18  
19 # Take the average latency, add jitter, but double the impact to latency
20 # then add 10 for protocol latancies
21 my $effective_latency = ( $average + $jitter * 2 + 10 );
22  
23 # Implement a basic curve - deduct 4 for the r_value at 160ms of latency
24 # (round trip). Anything over that gets a much more agressive deduction
25 if ($effective_latency < 160) {
26 $r_value = 93.2 - ($effective_latency / 40);
27 }
28 else {
29 $r_value = 93.2 - ($effective_latency - 120) / 10;
30 }
31  
32 # Now, let's deduct 2.5 r_value per percentage of packet_loss
33 $r_value = $r_value - ($packet_loss * 2.5);
34  
35 # Convert the r_value into an MOS value. (this is a known formula)
36 $ret_val = 1 +
37 (0.035) *
38 $r_value +
39 (0.000007) *
40 $r_value *
41 ($r_value - 60) *
42 (100 - $r_value);
43 $ret_val = sprintf( "%.3f", $ret_val);
44  
45 return $ret_val;
46 }
47  
48 1;
49  
50 __END__