From 43f57359cb6b69ab1e7cdcfbb810a3e7cb836e4b Mon Sep 17 00:00:00 2001
From: rs11g21 <rs11g21@soton.ac.uk>
Date: Tue, 2 May 2023 20:03:15 +0000
Subject: [PATCH] Implemented graphs

---
 cryptoGraphs.sh | 384 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 384 insertions(+)
 create mode 100644 cryptoGraphs.sh

diff --git a/cryptoGraphs.sh b/cryptoGraphs.sh
new file mode 100644
index 0000000..8062646
--- /dev/null
+++ b/cryptoGraphs.sh
@@ -0,0 +1,384 @@
+#! /usr/bin/bash
+
+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(){ #check whats the problem here
+
+
+
+/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 y1label "BitCoin Price"
+set y2label "BitCoin High"
+set y3label "BitCoin Low"
+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 "lowPrice.dat" using 1:2 with lines lw 2 title "Low Price"
+
+set ylabel "Y2-axis Label" offset 2
+
+plot "bitCoinPriceData.dat" using 1:2 axes x1y2 with lines lw 2 title "Current Price"
+
+set y1label "Y2-axis Label" offset 2
+
+plot "highPrice.dat" using 1:2 axes x1y2 with lines lw 2 title "High Price"
+
+unset multiplot
+
+EOF
+
+
+}
+
+
+
+
+
+choice=0
+
+while [ "$choice" -ne 11 ]; 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
+
-- 
GitLab