Skip to content
Snippets Groups Projects
Commit 5054336b authored by rs11g21's avatar rs11g21
Browse files

Completed version (Implemented extra error handling)

parent e7038f6d
No related branches found
No related tags found
No related merge requests found
#! /usr/bin/bash
output=$(/opt/lampp/bin/mysql -u root -e"USE cryptoTracker; SELECT * FROM crypto;" --skip-column-names 2>&1)
status=$?
# Check the status and handle the error
if [ $status -ne 0 ]; then
echo "MySQL error: $output"
else
echo "MySQL working."
function plot_changeInValue(){
/opt/lampp/bin/mysql -u root -e "use cryptoTracker; SELECT collected,value FROM changeInValue WHERE collected BETWEEN '2023-04-30 14:00:00' AND '2023-05-01 14:01:00';" | sed 's/\([0-9.-]\+\)$/* \1/' | tail -n +2 > changeInValue.dat
#WORKING
gnuplot <<EOF
set title "Change In Value for Bitcoin in 24 Hours"
set xlabel "Time"
set ylabel "Value"
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set format x "%Y-%m-%d \n %H:%M"
set datafile separator '*'
set ytics 100
set terminal png size 800,600
set style line 1 linecolor rgb '#5e9606' linetype 1 linewidth 2 pointtype 7 pointsize 1.5
set output 'changeInValue_plot.png'
set terminal pngcairo enhanced font 'Arial,10'
plot 'changeInValue.dat' using 1:2 with linespoints ls 1
EOF
echo "Change In Value graph has been generated."
}
function plot_bitCoinPrice(){
/opt/lampp/bin/mysql -u root -e "use cryptoTracker; SELECT collected,value FROM cryptoPrice WHERE collected BETWEEN '2023-04-30 14:00:00' AND '2023-05-01 14:01:00';" | sed 's/\([0-9.-]\+\)$/* \1/' | tail -n +2 > bitCoinPriceData.dat
#WORKING
gnuplot <<EOF
set title "Change In Bitcoin Price in 24 Hours"
set xlabel "Time"
set ylabel "Value"
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set format x "%Y-%m-%d \n %H:%M"
set datafile separator '*'
set ytics 100
set terminal png size 800,600
set style line 1 linecolor rgb '#5e9606' linetype 1 linewidth 2 pointtype 7 pointsize 1.5
set output 'bitCoinPrice_plot.png'
set terminal pngcairo enhanced font 'Arial,10'
plot 'bitCoinPriceData.dat' using 1:2 with linespoints ls 1
EOF
echo "Bitcoin Price graph has been generated."
}
function plot_24HourHigh(){
/opt/lampp/bin/mysql -u root -e "use cryptoTracker; SELECT collected,value FROM highPrice WHERE collected BETWEEN '2023-04-30 14:00:00' AND '2023-05-01 14:01:00';" | sed 's/\([0-9.-]\+\)$/* \1/' | tail -n +2 > highPrice.dat
#WORKING
gnuplot <<EOF
set title "Change In Bitcoin High Price in 24 Hours"
set xlabel "Time"
set ylabel "Value"
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set format x "%Y-%m-%d \n %H:%M"
set datafile separator '*'
set ytics 100
set terminal png size 800,600
set style line 1 linecolor rgb '#5e9606' linetype 1 linewidth 2 pointtype 7 pointsize 1.5
set output 'highPrice_plot.png'
set terminal pngcairo enhanced font 'Arial,10'
plot 'highPrice.dat' using 1:2 with linespoints ls 1
EOF
echo "Bitcoin High Price graph has been generated."
}
function plot_24HourLow(){
/opt/lampp/bin/mysql -u root -e "use cryptoTracker; SELECT collected,value FROM lowPrice WHERE collected BETWEEN '2023-04-30 14:00:00' AND '2023-05-01 14:01:00';" | sed 's/\([0-9.-]\+\)$/* \1/' | tail -n +2 > lowPrice.dat
#WORKING
gnuplot <<EOF
set title "Change In Bitcoin Low Price in 24 Hours"
set xlabel "Time"
set ylabel "Value"
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set format x "%Y-%m-%d \n %H:%M"
set datafile separator '*'
set ytics 100
set terminal png size 800,600
set style line 1 linecolor rgb '#5e9606' linetype 1 linewidth 2 pointtype 7 pointsize 1.5
set output 'lowPrice_plot.png'
set terminal pngcairo enhanced font 'Arial,10'
plot 'lowPrice.dat' using 1:2 with linespoints ls 1
EOF
echo "Bitcoin Low Price graph has been generated."
}
function plot_24HourOpen(){
/opt/lampp/bin/mysql -u root -e "use cryptoTracker; SELECT collected,value FROM openPrice WHERE collected BETWEEN '2023-04-30 14:00:00' AND '2023-05-01 14:01:00';" | sed 's/\([0-9.-]\+\)$/* \1/' | tail -n +2 > openPrice.dat
#WORKING
gnuplot <<EOF
set title "Change In Bitcoin Open Price in 24 Hours"
set xlabel "Time"
set ylabel "Value"
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set format x "%Y-%m-%d \n %H:%M"
set datafile separator '*'
set ytics 100
set terminal png size 800,600
set style line 1 linecolor rgb '#5e9606' linetype 1 linewidth 2 pointtype 7 pointsize 1.5
set output 'openPrice_plot.png'
set terminal pngcairo enhanced font 'Arial,10'
plot 'openPrice.dat' using 1:2 with linespoints ls 1
EOF
echo "Bitcoin Open Price graph has been generated."
}
function plot_marketCap(){
/opt/lampp/bin/mysql -u root -e "use cryptoTracker; SELECT collected,value FROM marketCap WHERE collected BETWEEN '2023-04-30 14:00:00' AND '2023-05-01 14:01:00';" | sed 's/\([0-9.-]\+\)$/* \1/' | tail -n +2 > marketCap.dat
#WORKING
gnuplot <<EOF
set title "Change In Bitcoin Market Cap in 24 Hours"
set xlabel "Time"
set ylabel "Value"
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set format x "%Y-%m-%d \n %H:%M"
set datafile separator '*'
set ytics 100
set terminal png size 800,600
set style line 1 linecolor rgb '#5e9606' linetype 1 linewidth 2 pointtype 7 pointsize 1.5
set output 'marketCap_plot.png'
set terminal pngcairo enhanced font 'Arial,10'
plot 'marketCap.dat' using 1:2 with linespoints ls 1
EOF
echo "Bitcoin Market Cap graph has been generated."
}
function plot_returnPercentage(){
/opt/lampp/bin/mysql -u root -e "use cryptoTracker; SELECT collected,value FROM returnPercentage WHERE collected BETWEEN '2023-04-30 14:00:00' AND '2023-05-01 14:01:00';" | sed 's/\([0-9.-]\+\)$/* \1/' | tail -n +2 > returnPercentage.dat
#WORKING
gnuplot <<EOF
set title "Change In Bitcoin Return Percentage in 24 Hours"
set xlabel "Time"
set ylabel "Value"
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set format x "%Y-%m-%d \n %H:%M"
set datafile separator '*'
set ytics 100
set terminal png size 800,600
set style line 1 linecolor rgb '#5e9606' linetype 1 linewidth 2 pointtype 7 pointsize 1.5
set output 'returnPercentage_plot.png'
set terminal pngcairo enhanced font 'Arial,10'
plot 'returnPercentage.dat' using 1:2 with linespoints ls 1
EOF
echo "Bitcoin Return Percentage graph has been generated."
}
function plot_transactionCount(){
/opt/lampp/bin/mysql -u root -e "use cryptoTracker; SELECT collected,value FROM transactionCount WHERE collected BETWEEN '2023-04-30 14:00:00' AND '2023-05-01 14:01:00';" | sed 's/\([0-9.-]\+\)$/* \1/' | tail -n +2 > transactionCount.dat
#WORKING
gnuplot <<EOF
set title "Change In Bitcoin Transaction Count in 24 Hours"
set xlabel "Time"
set ylabel "Value"
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set format x "%Y-%m-%d \n %H:%M"
set datafile separator '*'
set ytics 25000
set terminal png size 800,600
set style line 1 linecolor rgb '#5e9606' linetype 1 linewidth 2 pointtype 7 pointsize 1.5
set output 'transactionCount_plot.png'
set terminal pngcairo enhanced font 'Arial,10'
plot 'transactionCount.dat' using 1:2 with linespoints ls 1
EOF
echo "Bitcoin Transaction Count graph has been generated."
}
function plot_transactionFee(){
/opt/lampp/bin/mysql -u root -e "use cryptoTracker; SELECT collected,value FROM transactionFee WHERE collected BETWEEN '2023-04-30 14:00:00' AND '2023-05-01 14:01:00';" | sed 's/\([0-9.-]\+\)$/* \1/' | tail -n +2 > transactionFee.dat
#WORKING
gnuplot <<EOF
set title "Change In Bitcoin Transaction Fee in 24 Hours"
set xlabel "Time"
set ylabel "Value"
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set format x "%Y-%m-%d \n %H:%M"
set datafile separator '*'
set ytics 0.1
set terminal png size 800,600
set style line 1 linecolor rgb '#5e9606' linetype 1 linewidth 2 pointtype 7 pointsize 1.5
set output 'transactionFee_plot.png'
set terminal pngcairo enhanced font 'Arial,10'
plot 'transactionFee.dat' using 1:2 with linespoints ls 1
EOF
echo "Bitcoin Transaction Fee graph has been generated."
}
function plot_volatility(){
/opt/lampp/bin/mysql -u root -e "use cryptoTracker; SELECT collected,value FROM volatility WHERE collected BETWEEN '2023-04-30 14:00:00' AND '2023-05-01 14:01:00';" | sed 's/\([0-9.-]\+\)$/* \1/' | tail -n +2 > volatility.dat
#WORKING
gnuplot <<EOF
set title "Change In Bitcoin Volatility in 24 Hours"
set xlabel "Time"
set ylabel "Value"
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set format x "%Y-%m-%d \n %H:%M"
set datafile separator '*'
set ytics 0.025
set terminal png size 800,600
set style line 1 linecolor rgb '#5e9606' linetype 1 linewidth 2 pointtype 7 pointsize 1.5
set output 'volatility_plot.png'
set terminal pngcairo enhanced font 'Arial,10'
plot 'volatility.dat' using 1:2 with linespoints ls 1
EOF
echo "Bitcoin Volatility graph has been generated."
}
function function_priceMultiPlot(){
/opt/lampp/bin/mysql -u root -e "use cryptoTracker; SELECT collected,value FROM lowPrice WHERE collected BETWEEN '2023-04-30 14:00:00' AND '2023-05-01 14:01:00';" | sed 's/\([0-9.-]\+\)$/* \1/' | tail -n +2 > lowPrice.dat
/opt/lampp/bin/mysql -u root -e "use cryptoTracker; SELECT collected,value FROM highPrice WHERE collected BETWEEN '2023-04-30 14:00:00' AND '2023-05-01 14:01:00';" | sed 's/\([0-9.-]\+\)$/* \1/' | tail -n +2 > highPrice.dat
/opt/lampp/bin/mysql -u root -e "use cryptoTracker; SELECT collected,value FROM cryptoPrice WHERE collected BETWEEN '2023-04-30 14:00:00' AND '2023-05-01 14:01:00';" | sed 's/\([0-9.-]\+\)$/* \1/' | tail -n +2 > bitCoinPriceData.dat
gnuplot << EOF
set title "Change In Bitcoin Current , Low and High Price in 24 Hours"
set xlabel "Time"
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set format x "%Y-%m-%d \n %H:%M"
set datafile separator '*'
set ytics 100
set output 'multiplotBitcoinPrice.png'
set terminal pngcairo enhanced font 'Arial,10'
set multiplot
plot "highPrice.dat" using 1:2 with lines lw 2 title "High Price" , "lowPrice.dat" using 1:2 with lines lw 2 title "Low Price" , "bitCoinPriceData.dat" using 1:2 with lines lw 2 title "Current Price"
unset multiplot
EOF
printf "BitCoin Multiplot (Current,High and Low) has been generated."
}
choice=0
while [ "$choice" -ne 12 ]; do
printf "\n"
echo "Which Bitcoin graph do you want to generate ? Choose a number :
1) BitCoinPrice
2) 24 Hour High Price
3) 24 Hour Low Price
4) 24 Hour Open Price
5) Market Cap
6) Change In Value
7) Return Percentage
8) Volatility
9) Transaction Count
10) Transaction Fee
11) BitCoin Multiplot (Current,High and Low)
12) End
"
read choice
case $choice in
1)
plot_bitCoinPrice;;
2)
plot_24HourHigh;;
3)
plot_24HourLow;;
4)
plot_24HourOpen;;
5)
plot_marketCap;;
6)
plot_changeInValue;;
7)
plot_returnPercentage;;
8)
plot_volatility;;
9)
plot_transactionCount;;
10)
plot_transactionFee;;
11)
function_priceMultiPlot;;
12)
echo "Program ended";;
*)
echo "Invalid choice";;
esac
done
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment