Skip to content

Commit

Permalink
feat: sorting output, adding human readable and percent columns
Browse files Browse the repository at this point in the history
  • Loading branch information
kopardev committed Mar 1, 2024
1 parent 261940b commit 5201f5d
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions spacesavers2_pdq
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ from multiprocessing import Pool
import argparse
from pathlib import Path
import json
import os
import pandas as pd


def task(f):
Expand Down Expand Up @@ -127,6 +127,8 @@ def main():

outdict=dict()
outdict[str(p)]=dict()
col_names = ['uid', 'username', 'ninodes', 'nbytes', 'human_readable']
df = pd.DataFrame(columns = col_names)

for uid in bigdict.keys():
username = get_username_groupname(uid)
Expand All @@ -138,8 +140,27 @@ def main():
outdict[str(p)][str(uid)]['username']=username
outdict[str(p)][str(uid)]['ninodes']=ninodes
outdict[str(p)][str(uid)]['nbytes']=nbytes
outfh.write(f"{username}\t{ninodes}\t{nbytes}\n")

my_dict = {'uid':uid,
'username':username,
'ninodes':ninodes,
'nbytes':nbytes,
'human_readable':get_human_readable_size(nbytes)}
df.loc[len(df)] = my_dict
# outfh.write(f"{username}\t{ninodes}\t{nbytes}\n")

total_ninodes = df['ninodes'].sum()
total_nbytes = df['nbytes'].sum()
total_humanreadable = get_human_readable_size(total_nbytes)
my_dict = { 'uid':0,
'username':'allusers',
'ninodes':total_ninodes ,
'nbytes':total_nbytes,
'human_readable':total_humanreadable}
df.loc[len(df)] = my_dict
df.sort_values(by=['nbytes'],ascending=False,inplace=True)
df['percent'] = df['nbytes'] * 100.0 / total_nbytes
df['percent'] = df['percent'].apply(lambda x: float("{:.2f}".format(x)))
df.to_csv(outfh,sep="\t",index=False)
if args.json:
json.dump(outdict,outjson,indent=1)
outjson.close()
Expand Down

0 comments on commit 5201f5d

Please sign in to comment.