Skip to content

Instantly share code, notes, and snippets.

@andrefs
Last active December 25, 2015 04:39
Show Gist options
  • Save andrefs/6919212 to your computer and use it in GitHub Desktop.
Save andrefs/6919212 to your computer and use it in GitHub Desktop.
makefile
SHELL := /bin/bash
copy2cloud: covers_percentage_small_pt_title.txt covers_percentage_small_title.txt last_small_covers_pt_title.txt last_small_covers_title.txt
cp last_small_covers_pt_title.txt covers_percentage_small_pt_title.txt covers_percentage_small_title.txt last_small_covers_title.txt ~/public_html/CloudPT/sapo/banca_covers_stats
# ALL PT
all_covers_pt.txt: all_covers_pt.json
cat all_covers_pt.json | head -n-1 | tail -n+2 | sed 's/^[^0-9]*\([0-9]\+\)[^0-9]*/\1/' | sort -n > all_covers_pt.txt
# TOTAL SMALL
total_small_covers_lite.txt : total_small_covers_lite.json
cat total_small_covers_lite.json | head -n-1 | tail -n+2 | sed 's/^\s*{\s*"//' | sed 's/"\s*:\s*/\t/' | sed 's/\s*},\?\s*$$//' | sort -k2 -n -r | column -t > total_small_covers_lite.txt
total_small_covers_lite.json : total_small_covers.json
cat total_small_covers.json | sed 's/^\s*"Source.ItemID"\s*:\s*"\s*/"/' | sed 's/"total"\s*:\s*//' | sed 's/",/" :/' | jsonlint -f > total_small_covers_lite.json
total_small_covers_pt_lite.txt: all_covers_pt.txt total_small_covers_lite.txt
grep -f <(paste -d^ <(yes ""| head -$$(wc -l all_covers_pt.txt | cut -d' ' -f1)) all_covers_pt.txt) total_small_covers_lite.txt | cat <(echo -e "ID Small\n------ ------") - | column -t > total_small_covers_pt_lite.txt
# LAST SMALL
last_small_covers_pt_title.txt : last_small_covers_pt.txt all_titles_lite.txt
grep -f <(paste -d^ <(yes ""| head -$$(wc -l last_small_covers_pt.txt | cut -d' ' -f1)) last_small_covers_pt.txt) all_titles_lite.txt | sed 's/\s\+/|/' | cat <(echo -e "ID|Title\n------|------") - | column -t -s'|' > last_small_covers_pt_title.txt
last_small_covers_title.txt : last_small_covers.txt all_titles_lite.txt
grep -f <(paste -d^ <(yes ""| head -$$(wc -l last_small_covers.txt | cut -d' ' -f1)) last_small_covers.txt) all_titles_lite.txt | sed 's/\s\+/|/' | cat <(echo -e "ID|Title\n------|------") - | column -t -s'|' > last_small_covers_title.txt
last_small_covers_pt.txt : last_small_covers_pt.json
cat last_small_covers_pt.json | head -n-1 | tail -n+2 | sed 's/^[^0-9]*\([0-9]\+\)[^0-9]*/\1/' | sort -n | cat <(echo -e "ID\n------") - > last_small_covers_pt.txt
last_small_covers.txt : last_small_covers.json
cat last_small_covers.json | head -n-1 | tail -n+2 | sed 's/^[^0-9]*\([0-9]\+\)[^0-9]*/\1/' | sort -n | cat <(echo -e "ID\n------") - > last_small_covers.txt
# PERCENTAGE
covers_percentage_small_pt.txt: all_covers_pt.txt covers_percentage_small.txt
grep -f <(paste -d^ <(yes ""| head -$$(wc -l all_covers_pt.txt | cut -d' ' -f1)) all_covers_pt.txt) covers_percentage_small.txt | cat <(echo -e "ID Total Small %\n------ ------ ------ ------") - | column -t > covers_percentage_small_pt.txt
covers_percentage_small.txt: total_covers_lite.txt total_small_covers_lite.txt
join <(sort -n total_covers_lite.txt) <(sort -n total_small_covers_lite.txt) | awk '{print $$1 " " $$2 " " $$3 " " $$3*100/$$2}' | sort -k4nr -k2nr | cat <(echo -e "ID Total Small %\n------ ------ ------ ------") - | column -t > covers_percentage_small.txt
# COVERS WITH TITLES
covers_percentage_small_pt_title.txt : covers_percentage_small_pt.txt all_titles_lite.txt
join <(cat covers_percentage_small_pt.txt |tail -n+3| sed 's/\s\+/|/g' | sed 's/|/ /' | sort) all_titles_lite.txt | sed 's/\s\+/|/' | sed 's/\s\+/|/' | sort -t'|' -k4nr -k2nr | cat <(echo -e "ID|Total|Small|%|Title\n------|------|------|------|------") - | column -t -s'|' > covers_percentage_small_pt_title.txt
covers_percentage_small_title.txt : covers_percentage_small.txt all_titles_lite.txt
join <(cat covers_percentage_small.txt |tail -n+3| sed 's/\s\+/|/g' | sed 's/|/ /' | sort) all_titles_lite.txt | sed 's/\s\+/|/' | sed 's/\s\+/|/' | sort -t'|' -k4nr -k2nr | cat <(echo -e "ID|Total|Small|%|Title\n------|------|------|------|------") - | column -t -s'|' > covers_percentage_small_title.txt
# TOTAL COVERS
total_covers_lite.txt : total_covers_lite.json
cat total_covers_lite.json | head -n-1 | tail -n+2 | sed 's/^\s*{\s*"//' | sed 's/"\s*:\s*/\t/' | sed 's/\s*},\?\s*$$//' | sort -k2nr | column -t > total_covers_lite.txt
total_covers_lite.json : total_covers.json
cat total_covers.json | sed 's/^\s*"Source.ItemID"\s*:\s*"\s*/"/' | sed 's/"total"\s*:\s*//' | sed 's/",/" :/' | jsonlint -f > total_covers_lite.json
# ALL TITLES
all_titles_lite.txt : all_titles_lite.json
cat all_titles_lite.json | head -n-1 | tail -n+2 | sed 's/^\s*{\s*"//' | sed 's/"\s*:\s*/\t/' | sed 's/\s*},\?\s*$$//' | sed 's/\s/\t/' | sort -n | column -t -s$$'\t' > all_titles_lite.txt
all_titles_lite.json : all_titles.json
cat all_titles.json | sed 's/"Source"[^0-9]\+\([0-9]\+\)[^0-9]*$$/"\1"/' | sed 's/"Title"\s*//' | jsonlint -f > all_titles_lite.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment