lib/AI/MicroStructure/ObjectSet.pm

filter: Statementstmt 27.7% 33 / 119 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 47.8% 11 / 23 Podpod 0.0% 0 / 6 totaltotal 27.1% 44 / 162 CC 17 SCAR 30.3
CC
17
Cov
25%
final
72.0
new
30.0
xdecruft
6.0
CRAP 20.7
« script/websock002.pl ↑ Summary lib/AI/MicroStructure/Util.pm »
1 #!/usr/bin/perl
2  
3  
4 package AI::MicroStructure::Object;
5  
6  
7 2 ▶ use Cache::Memcached::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 our $memd = new Cache::Memcached::Fast({
10 servers => [ { address => 'localhost:11211', weight => 2.5 }],
11 namespace => 'my:',
12 connect_timeout => 0.2,
13 io_timeout => 0.1,
14 close_on_error => 1,
15 compress_threshold => 100_000,
16 compress_ratio => 0.9,
17 max_failures => 1,
18 max_size => 512 * 1024,
19 });
20  
21  
22 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use Data::Printer;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 sub new {
28 0 ▶ my $pkg = shift;
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
29 0 my $self = bless {}, $pkg;
30  
31  
32 0 my $i = 0;
33  
34 0 $self->{md5} = md5_hex(@_);
35 0 $self->{name} = "@_";
36  
37 0 $self->{micro} = [split("\n",$self->check("@_","micrownet"))] ;
38 0 $self->{second}->{$_}=[split("\n",$self->check("$_","micrownet") )] for @{$self->{micro}};
39 0 $self->{weight} = {};
40  
41 0 foreach(@{$self->{micro}}){
42  
43  
44 0 foreach(@{$self->{second}->{$_}}){
45  
46 0 ▶ if($self->{weight}->{$_})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'weight'}{$_}) { } 0 0 0
47 {
48 0 $self->{weight}->{$_}++;
49 }else{
50 0 $self->{weight}->{$_} = 1;
51 }
52 }
53 }
54  
55 # foreach(keys %{$self->{weight}}){
56 # delete $self->{weight}->{$_} unless($self->{weight}->{$_}>1);
57 # }
58  
59  
60  
61 0 return $self;
62 }
63  
64 sub xdecruft {
65 0 ▶ my $self = shift;
Subroutine xdecruft: not called CC=2 SCAR=17.9
Pod undocumented
66 0 my($file) = @_;
67 0 my($cruftSet) = q{%§&|#[^+*( ]),'"; };
68 0 my $clean = $file;
69 0 $clean=~s/\Q$_//g for split("",$cruftSet);
70  
71 0 return $clean;
72 }
73  
74 sub xTO_JSON {
75 0 ▶ my $self = shift;
Subroutine xTO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
76 0 return { class => 'Object', data => { %$self } };
77 }
78  
79  
80 sub tools {
81 0 ▶ my $self = shift;
Subroutine tools: not called CC=1 SCAR=6.9
Pod undocumented
82 0 $self->{tools} = \@_;
83  
84  
85 }
86  
87 0 ▶sub check { my $self = shift;
Subroutine check: not called CC=2 SCAR=17.9
Pod undocumented
88 0 my $name = shift;
89 0 my $prog = shift;
90 0 $name = $self->decruft($name);
91  
92 0 ▶ if(defined(my $ret = $memd->get(sprintf("%s_%s",$name,$prog)))){
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ret = $AI::MicroStructure::Object::memd->get(sprintf('%s_%s', $name, $prog)))) { } 0 0 0
93 0 return $ret;
94 }else{
95 0 my $ret = `$prog $name`;
96 0 $memd->set(sprintf("%s_%s",$name,$prog),$ret);
97 0 return $ret;
98 }
99 }
100  
101  
102  
103 sub name {
104  
105 0 ▶ my $self = shift;
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
106 0 return $self->{name};
107 }
108 1;
109  
110 package AI::MicroStructure::ObjectSet;
111  
112 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
113 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
114 2 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
115 2 ▶use Statistics::Basic qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
116 2 ▶use List::Util qw(max min);
Subroutine BEGIN: called CC=1 SCAR=0.0
117 2 ▶use Data::Printer;
Subroutine BEGIN: called CC=1 SCAR=0.0
118  
119  
120 sub new {
121 0 ▶ my $pkg = shift;
Subroutine new: not called CC=2 SCAR=17.9
122 0 my $self = bless {obj=>{IN=>[@_]}}, $pkg;
123 0 my $syntetic = {};
124  
125 0 ▶ $self->insert(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
126  
127  
128  
129 0 return $self;
130 }
131 sub decruft {
132 0 ▶ my $self = shift;
Subroutine decruft: not called CC=2 SCAR=17.9
133 0 my($file) = @_;
134 0 my($cruftSet) = q{%§&|#[^+*( ]),'"; };
135 0 my $clean = $file;
136 0 $clean=~s/\Q$_//g for split("",$cruftSet);
137  
138 0 return $clean;
139 }
140  
141 sub check {
142 0 ▶ my $self = shift;
Subroutine check: not called CC=2 SCAR=17.9
143 0 my $name = shift;
144 0 my $prog = shift;
145 0 $name = $self->decruft($name);
146  
147 0 ▶ if(defined(my $ret = $memd->get(sprintf("%s_%s",$name,$prog)))){
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ret = $AI::MicroStructure::Object::memd->get(sprintf('%s_%s', $name, $prog)))) { } 0 0 0
148 0 return $ret;
149 }else{
150 0 my $ret = `$prog $name`;
151 0 $memd->set(sprintf("%s_%s",$name,$prog),$ret);
152 0 return $ret;
153 }
154 }
155  
156 sub final {
157  
158 0 ▶ my $self = shift;
Subroutine final: not called CC=8 SCAR=42.8
159  
160  
161  
162  
163 0 foreach(@{$self->{micro}}){
164  
165  
166 0 foreach(@{$self->{second}->{$_}}){
167  
168 0 ▶ if($self->{weight}->{$_})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'weight'}{$_}) { } 0 0 0
169 {
170 0 $self->{weight}->{$_}++;
171 }else{
172 0 $self->{weight}->{$_} = 1;
173 }
174 }
175 }
176  
177 0 $self->{obj}->{mean} = sprintf "%d.3", mean values %{$self->{obj}->{center}};
178  
179  
180 0 foreach ( keys %{$self->{obj}->{center}}) {
181  
182 0 ▶ next unless $self->{obj}->{center}->{$_}>=$self->{obj}->{mean};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"obj"}{"center"}{$_} >= $self->{"obj"}{"mean"} 0 0 0
183  
184  
185 0 $self->{obj}->{dense}->{$_} = $self->{obj}->{center}->{$_};
186  
187 }
188  
189 0 $self->{obj}->{max} = sprintf max values %{$self->{obj}->{dense}};
190 0 $self->{obj}->{min} = sprintf min values %{$self->{obj}->{dense}};
191  
192  
193  
194 0 foreach ( keys %{$self->{obj}->{dense}}) {
195  
196 0 ▶ next if $self->{obj}->{dense}->{$_}!=$self->{obj}->{max};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"obj"}{"dense"}{$_} != $self->{"obj"}{"max"} 0 0 0
197  
198  
199 0 $self->{obj}->{menu}->{$_} = $self->{obj}->{dense}->{$_};
200  
201 }
202  
203 0 $self->{obj}->{www} = [split("\n",`micro-relation $self->{obj}->{name} | data-freq --limit 100`)];
204  
205 #5 my $check = "";
206  
207 #foreach ( keys %{$self->{obj}->{dense}}) {
208 # my $arg = sprintf("micro-relation %s",$_);
209 # my $check .= sprintf("\n%s",`$arg`);
210 #}
211  
212  
213 0 return $self;
214 }
215  
216 sub members {
217 0 ▶ return values %{$_[0]};
Subroutine members: not called CC=1 SCAR=6.9
218 }
219  
220 sub size {
221 0 ▶ return scalar keys %{$_[0]};
Subroutine size: not called CC=1 SCAR=6.9
222 }
223  
224 sub insert {
225 my $self = shift;
226 foreach my $element (@_) {
227 if(ref $element eq "AI::MicroStructure::Object")
228 {
229  
230 $self->{ $element->name } = $element;
231 if($element->{files}){
232 foreach(values $element->{files}){
233 $self->{files}->{ $element->name } = $_; }
234 }}
235 $self->{obj}->{center}->{$_} = defined($self->{obj}->{center}->{$_}) ?
236 $self->{obj}->{center}->{$_} + 1 : 1
237 for keys %{$element->{weight}};
238 }
239  
240  
241  
242 # `clear`;
243 # p $self->{obj}->{center};
244  
245 }
246  
247 sub domain {
248 my $self = shift;
249 croak("neds args") unless($ARGV[0]);
250 $self->{obj}->{domain}=sprintf("%s_%s",$ARGV[0] ,md5_hex(@ARGV));
251 $self->{obj}->{name} = $ARGV[0];
252 foreach(@ARGV){
253 my $ob = AI::MicroStructure::Object->new();
254 my @t = split("\n",$ob->check($_,"micrownet")) unless(!@ARGV);
255  
256 foreach my $e(@t){
257 $ob = AI::MicroStructure::Object->new($e);
258 $self->insert($ob);
259 }
260 }
261  
262 }
263 sub retrieve { $_[0]->{$_[1]} }
264 sub includes { exists $_[0]->{ $_[1]->name } }
265 sub includes_name { exists $_[0]->{ $_[1] } }
266  
267 1;
« script/websock002.pl ↑ Summary lib/AI/MicroStructure/Util.pm »