<s> """<STR_LIT>""" <EOL> from random import randint <EOL> from math import floor <EOL> from numpy import zeros , float32 , int32 , nan <EOL> class NMARDestroyer ( object ) : <EOL> def destroy ( self , timeseries , ** args ) : <EOL> percentage = args [ '<STR_LIT>' ] <EOL> min_length = args [ '<STR_LIT>' ] <EOL> max_length = args [ '<STR_LIT:max_length>' ] <EOL> lseries = timeseries . shape [ <NUM_LIT:0> ] <EOL> marked = <NUM_LIT:0> <EOL> marked_intervals = [ ] <EOL> while ( marked < int ( floor ( ( lseries * percentage ) ) ) ) : <EOL> start = randint ( <NUM_LIT:0> , lseries - <NUM_LIT:1> ) <EOL> end = randint ( start + min_length , start + max_length ) <EOL> while ( end > lseries - <NUM_LIT:1> ) : <EOL> start = randint ( <NUM_LIT:0> , lseries - <NUM_LIT:1> ) <EOL> end = randint ( start + min_length , start + max_length ) <EOL> marked += ( end - start ) <EOL> marked_intervals . append ( ( start , end ) ) <EOL> exceptions = [ <NUM_LIT:0> , lseries - <NUM_LIT:1> ] <EOL> if ( '<STR_LIT>' in args . keys ( ) ) : <EOL> exceptions = exceptions + args [ '<STR_LIT>' ] <EOL> removed_indices = [ ] <EOL> index_old = <NUM_LIT:0> <EOL> while index_old < lseries : <EOL> for interval in marked_intervals : <EOL> ( start , end ) = interval <EOL> if ( ( start <= index_old <= end ) and index_old not in exceptions ) : <EOL> removed_indices . append ( index_old ) <EOL> break <EOL> index_old += <NUM_LIT:1> <EOL> new_amount = lseries - len ( removed_indices ) <EOL> new_mat = zeros ( ( new_amount , ) , dtype = [ ( '<STR_LIT:date>' , int32 ) , ( '<STR_LIT>' , float32 ) , ( '<STR_LIT>' , float32 ) ] ) <EOL> index_old = <NUM_LIT:0> <EOL> index_new = <NUM_LIT:0> <EOL> while index_old < lseries : <EOL> if ( index_old in removed_indices ) : <EOL> index_old += <NUM_LIT:1> <EOL> else : <EOL> new_mat [ index_new ] = timeseries [ index_old ] <EOL> index_old += <NUM_LIT:1> <EOL> index_new += <NUM_LIT:1> <EOL> return new_mat , removed_indices </s>
