[FUN] Get some stats of your project/s


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [FUN] Get some stats of your project/s
# 1  
Old 05-06-2015
[FUN] Get some stats of your project/s

Heya

Ever wanted to have some basic stats of your projects?
Like:
Code:
./stats.sh 
########################################
	Project stats for "tui"
########################################
260 kb	in bin
24 kb	in conf.etc
12 kb	in conf.home
32 kb	in docs/samples
176 kb	in docs/wiki
280 kb	in docs
192 kb	in man
1984 kb	in screenshots
12 kb	in templates/manpage
32 kb	in templates/scripts
12 kb	in templates/usr
64 kb	in templates
36 kb	in themes
13 folders with a total of 3116 kbytes
########################################
Spread across 190 files, there are:
Lines Total: 		 14542
Comment lines: 		 2409
Blank lines: 		 201
Avrg lines p. file: 	 76

Was created using these few lines:
Code:
#!/bin/bash
#
#	Vars
#
	LINER="########################################"
	COMMENTS=0
	LINES=0
	BLANKS=0
#
#	Action
#
	echo "$LINER"
	echo -e "\tProject stats for \"$(basename $PWD)\""
# Size
	echo "$LINER"
	for DIR in * ; do [ -d "$DIR" ] && LIST+=" $DIR" ; done
	du $LIST  | awk '{print $1" kb\tin "$2;SUM=SUM+$1} END {print NR" folders with a total of "SUM" kbytes"}'
# Files
	echo "$LINER"
	FILES=$(find|grep -ve ".git" -ve ".jpg"| wc -l)
	echo "Spread across $FILES files, there are:"
# Lines
	for F in $(find|grep -ve ".git" -ve ".jpg")
	do	[ -f "$F" ] && \
			COMMENTS=$(( $COMMENTS + $(grep ^"#" "$F" | wc -l) )) && \
			LINES=$(( $LINES + $(cat "$F" | wc -l) )) && \
			BLANKS=$(( $BLANKS + $(grep ^[[:space:]]$ "$F" | wc -l) ))
	done
# Summary
	echo -e "Lines Total: \t\t $LINES"
	echo -e "Comment lines: \t\t $COMMENTS"
	echo -e "Blank lines: \t\t $BLANKS"
	echo -e "Avrg lines p. file: \t $(( $LINES / $FILES ))"

I wanted to share it when i wrote it, but figured i didnt.

Have fun
# 2  
Old 05-07-2015
You could replace your Lines section with the below for more speed:

Code:
# Lines
vals=( $( awk -v q="^#,.*,^[[:space:]]*$" '
       BEGIN{cc=split(q,crit,",")}
       { for(i in crit) t[i]+=($0 ~ crit[i]) }
       END { for(i=1; i<=cc;i++) printf "%d ",t[i] }' \
       $(find . -type f -name "st*") )
)
((COMMENTS=vals[0]))
((LINES=vals[1]))
((BLANKS=vals[2]))

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 05-07-2015
Limiting the files found to only files starting with st* is alot faster, due to a smaller list size.

After changing the find line to:
Code:
 $(find . -type f -name "*"|grep -ve jpg$ -ve png$ -ve svg$ -ve \.git) )

Its printing (almost) the same stats in quite near range (imo, regarding the task done)....
Org:
Code:
real	0m0.581s
user	0m0.195s
sys	0m0.742s

New:
Code:
real	0m0.402s
user	0m0.385s
sys	0m0.026s

Only value changed is 'blank lines', raised from ~200 to ~1800. Smilie
Eventhough i've (theoreticly) removed more image files - which shouldnt contain empty lines anyway....

Last edited by sea; 05-07-2015 at 06:05 AM..
# 4  
Old 05-07-2015
I wonder if you want to skip .git directories.
Then a -prune in find is more efficient.
Also it is more efficient to run the find once, and count the FILES in the loop.
Code:
FILES=0
for F in $(find . -type d -name ".git" -prune -o -type f \! -name ".jpg" -print)
do
    ((FILES+=1))
    ... # only files, dont need to test again
done

NB the -print is needed: by explicitly printing the files it will not print the pruned directories.
This User Gave Thanks to MadeInGermany For This Post:
# 5  
Old 05-07-2015
Just asking, are you aware that i created this thread with solved status?
Hence the [FUN] tag.

Anyway, for some reason the lines found jumped from 14541 to 22469, probably cause by the fact that the jpg files are still listed.

So to try it:
Code:
for F in $(find . -type d -name ".git" -prune -o -type f \! -name ".jpg" \! -name ".png" -print)
do	echo "$F"
	COMMENTS=$(( $COMMENTS + $(grep ^"#" "$F" | wc -l) ))
	LINES=$(( $LINES + $(cat "$F" | wc -l) ))
	BLANKS=$(( $BLANKS + $(grep ^[[:space:]]$ "$F" | wc -l) ))
	((FILES+=1))
done

Even with escaped "\.jpg" and/or unescaped "!", the screenshots are shown and their lines counted.
Ironicly, it reports only 2 files more... Smilie

Full output:
Code:
time ./stats.sh
########################################
	Project stats for "tui"
########################################
264 kb	in bin
24 kb	in conf.etc
12 kb	in conf.home
32 kb	in docs/samples
176 kb	in docs/wiki
280 kb	in docs
192 kb	in man
1984 kb	in screenshots
12 kb	in templates/manpage
32 kb	in templates/scripts
12 kb	in templates/usr
64 kb	in templates
36 kb	in themes
13 folders with a total of 3120 kbytes
########################################
./install.sh
./conf.etc/apps.conf
./conf.etc/status.conf
./conf.etc/commands.conf
./conf.etc/tui.conf
./conf.etc/colors.conf
./screenshots/examples-interface_ds_make_kickstart.jpg
./screenshots/tui-list.jpg
./screenshots/compare-themes-xterm.jpg
./screenshots/compare-themes-lxterminal.jpg
./screenshots/compare_with_root_mode.jpg
./screenshots/mini-demo-tui.jpg
./screenshots/tui-browser_textmode_root.jpg
./screenshots/tui-psm.jpg
./screenshots/demo_working_with_conf_files.jpg
./screenshots/tui-log.jpg
./screenshots/examlpes_tui-browser.jpg
./screenshots/tui-status.jpg
./screenshots/tui-printf_splitting.jpg
./screenshots/tui-browser_long.jpg
./screenshots/tui-select.jpg
./screenshots/demo-interface.jpg
./screenshots/tui-progress-examples.jpg
./docs/README.md
./docs/CONFIG.md
./docs/samples/demo-compare-with-bash.sh
./docs/samples/sample_tui-conf-get_and_set.sh
./docs/samples/sample_tui-progress.sh
./docs/samples/demo-interface-top-bottom.sh
./docs/samples/demo-interface-select-loop.sh
./docs/samples/sample_tui-status.sh
./docs/samples/sample_tui-log.sh
./docs/LICENSE
./docs/README-new.md
./docs/INSTALL.md
./docs/wiki/tui-conf-set.md
...
./man/tui-log.1
./man/tui-new-browser.1
./man/tui-new-manpage.1
./man/tui-str-usb.1
./man/tui-press.1
./man/tui-read.1
./man/tui-conf-get.1
...
./bin/tui-bol-gui
./bin/tui-install
./bin/tui-str-extension
./bin/tui-str-genfilename
./bin/tui-str-usb
./bin/tui-indi
Spread across 192 files, there are:
Lines Total: 		 22470
Comment lines: 		 2426
Blank lines: 		 206
Avrg lines p. file: 	 117

real	0m0.751s
user	0m0.290s
sys	0m0.848s

Smilie
# 6  
Old 05-07-2015
Sorry for the confusion. It must be
\! -name "*.jpg" \! -name "*.png" .
This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

FINDING DUPLICATE PROJECT ( directory project )

I have a project tree like that. after running find command with the -no -empty option, i am able to have a list of non empty directory DO_MY_SEARCH="find . -type d -not -empty -print0" MY_EXCLUDE_DIR1=" -e NOT_IN_USE -e RTMAP -e NOT_USEFULL " echo " " > $MY_TEMP_RESULT_1 while... (2 Replies)
Discussion started by: jcdole
2 Replies

2. News, Links, Events and Announcements

A new project was posted on The UNIX and Linux Forums project board.

A new project was posted on your project board. Project title: Bash Shell Tutoring Estimated Budget: $50/hr Start date: Immediately Required skills: Linux, Bash, Shell, UNIX I work as a datawarehouse designer and developer. Although I usually stick to the role of an analyst,... (0 Replies)
Discussion started by: Neo
0 Replies

3. Solaris

what is the use of /etc/project file and project administration commands?

i have two doubts.. 1. what is the use /etc/project file. i renamed this file and when i tried to switch user or login with some user account the login was happening slowly. but when i renamed it to original name it was working fine... why so? 2. unix already has useradd and grouadd for... (4 Replies)
Discussion started by: chidori
4 Replies

4. What is on Your Mind?

fun scripts

Lets get a list of everyones funny scripts (8 Replies)
Discussion started by: JamieMurry
8 Replies

5. Solaris

SSH doesn't pick up user's project from /etc/project

We have a system running ssh. When a user logs in, they do not get the project they are assigned to (they run under "system"). I verify the project using the command "ps -e -o user,pid,ppid,args,project". If you do a "su - username", the user does get the project they are assigned to (and all... (2 Replies)
Discussion started by: kurgan
2 Replies

6. News, Links, Events and Announcements

Fun with FreeBSD

Fun With Automounting on FreeBSD Link: Nice tips for FreeBSD Unix. http://ezine.daemonnews.org/200202/automounting.html (2 Replies)
Discussion started by: killerserv
2 Replies
Login or Register to Ask a Question