Skip to content

Commit

Permalink
Updating wbz
Browse files Browse the repository at this point in the history
  • Loading branch information
Wittline committed Apr 20, 2022
1 parent bb5704f commit 7963e24
Showing 1 changed file with 8 additions and 62 deletions.
70 changes: 8 additions & 62 deletions wbz/wbz.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@

class bzip2:

def __init__(self, fname, chunk_size, sc, verbose):
def __init__(self, fname, chunk_size, sc):
self.fname = fname
self.chunk_size = chunk_size
self.verbose = verbose
self.chunk_size = chunk_size
self.bwt = BWT(sc)
self.mtf = MTF()
self.tb = BitsBytes()
self.huf = Huffman()
self.fh = FileHandler()
self.rate = 1
self.name_file_encoded = None
self.fh = FileHandler()


def encode(self):
Expand All @@ -42,11 +39,7 @@ def encode(self):

size = ((len(datac) // 8) // prl.cpus) * 8

cdata = prl.parallel(datac, size, [self.tb])

c_len = len(cdata)

self.rate = ((100 * c_len) // o_len)
cdata = prl.parallel(datac, size, [self.tb])

seqwriter = self.fh.write_bytes(bytearray(cdata), self.fname, True)

Expand Down Expand Up @@ -90,66 +83,19 @@ def decode(self):

parser.add_argument('-f','--fname', type=str, help = "Name file", required=True)
parser.add_argument('-cs','--chunk_size', type=str, help = "Chunk size", required=True)
parser.add_argument('-ch','--special_chr', type=str, help = "Special char", required=True)
parser.add_argument('-v','--verbose', type=int, help = "Verbose", required=False)

args = parser.parse_args()
verbose = False

if args.verbose is not None:
if args.verbose == 1:
verbose = True
elif args.verbose == 0:
verbose = False
else:
print("The value: {} assigned to -v or --verbose is invalid, Verbose is inactive".format(args.verbose))
parser.add_argument('-ch','--special_chr', type=str, help = "Special char", required=True)

args = parser.parse_args()

if args.fname is not None and args.fname!= '':
if args.chunk_size is not None and args.chunk_size != '':
if args.special_chr is not None and args.special_chr != '':
if args.Action == 'encode':
bzip = bzip2(args.fname, int(args.chunk_size), args.special_chr, verbose)
bzip = bzip2(args.fname, int(args.chunk_size), args.special_chr)
bzip.encode()
elif args.Action == 'decode':
bzip = bzip2(args.fname, int(args.chunk_size), args.special_chr, verbose)
bzip = bzip2(args.fname, int(args.chunk_size), args.special_chr)
bzip.decode()
elif args.Action == 'performance':
chunk_sizes = [100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 7000, 8000, 9000, 10000, 12000, 15000, 18000, 20000, 25000, 30000, 35000] #40000, 50000]
files = ['data/data_1000000', 'data/data_500000', 'data/data_250000']
file_size = []
chunk_size = []
encoding_times = []
decoding_times = []
rates_compression = []

for f in files:
for size in chunk_sizes:
print(f, "start", size)
bzip = bzip2(f + '.csv', size, ';', False)
chunk_size.append(size)
file_size.append(f)
inicio = tiempo.default_timer()
bzip.encode()
fin = tiempo.default_timer()
encoding_times.append(format(fin-inicio, '.8f'))
rates_compression.append(bzip.rate)

bzip = bzip2(f + '.wbz', size, ';', False)
inicio = tiempo.default_timer()
bzip.decode()
fin = tiempo.default_timer()
decoding_times.append(format(fin-inicio, '.8f'))
print(f, "end", size)

performance_df = pd.DataFrame()
performance_df['file_size'] = file_size
performance_df['chunk_size'] = chunk_size
performance_df['encoding_time'] = encoding_times
performance_df['rate_compression'] = rates_compression
performance_df['decoding_time'] = decoding_times
performance_df.to_csv('data/performance_wbz.csv', index=False, sep=';')

else:
print("Action {} is invalid".format(args.Action))
else:
Expand Down

0 comments on commit 7963e24

Please sign in to comment.