This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
countries = ["France", "Russia", "Italy", "Iran", "India", "Germany", "Brazil"]; | |
y, y_r, y_d = DataFrame(), DataFrame(), DataFrame() # separate empty dataframes to keep things simple | |
################## For total confirmed cases ##################### | |
for country in countries | |
data_dfr = find_country(data_df,country); # returns a dataframe row | |
data_dfr = DataFrame(data_dfr); # convert dataframe row back to a dataframe | |
rows, cols = size(data_dfr); | |
data_dfl = stack(data_dfr, 5:cols); # convert dataframe into long format | |
y[!,Symbol("$country")] = data_dfl[!,:value] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
confirmed_cases = vec(convert(Array, last(y,1))) # convert last dataframe row into a 1-D array | |
recovered_cases = vec(convert(Array, last(y_r,1))) | |
deaths = vec(convert(Array, last(y_d,1))) | |
Y = Array{Float64,2}(undef, length(names(y_r)), 4) # 2-D array with number of confirmed, recovered and deaths | |
Y[:,1] = deaths | |
Y[:,2] = confirmed_cases | |
Y[:,3] = recovered_cases | |
Y[:,4] = Y[:,2] - (Y[:,3] + Y[:,1]) # number of currently infected = confirmed - (recovered + deaths) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gr(size=(800,500)) | |
display(groupedbar(names(y), Y, | |
bar_position = :dodge, | |
bar_width=0.75, | |
ylabel = "Number of cases", | |
xlabel = "Countries", | |
label=["Deaths" "Confirmed" "Recovered" "Currently infected"], | |
framestyle = :semi, | |
formatter = :plain, | |
legend = :topleft, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sort!(data_df_recovered,Symbol("7/31/20"),rev=true) # sort original DataFrame in descending order based on values in last column (latest date) | |
countries_sort_r = data_df_recovered[1:5,Symbol("Country/Region")] # list of top 5 countries | |
latest_recovered_cases = data_df_recovered[1:5,Symbol("7/31/20")] # number of recovered cases in top 5 countries | |
gr(size=(700,400)) | |
display(bar(countries_sort_r, latest_recovered_cases, | |
orientation = :h, | |
xlabel = "Total number of recovered cases", | |
ylabel = "Countries", | |
legend = false, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Top_five_anim = @animate for i in 50:length(names(data_df)) # loop through dates | |
sort!(data_df, :($i), rev = true) # sort original DataFrame in descending order based on values in last column (latest date) | |
countries_sort = data_df[1:5,Symbol("Country/Region")] # list of top 5 countries | |
latest_reported_cases = data_df[1:5,i] # number of reported cases in top 5 countries | |
labels = string.(latest_reported_cases) | |
gr(size=(800,500)) | |
bar(countries_sort, latest_reported_cases, | |
ylabel = "Total number of confirmed cases", | |
xlabel = "Countries", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_ratings_data(currency::String) | |
date = Dates.today() | |
main_dir = pwd() | |
cd("data") | |
# Look for present day's CSV file, if not found, download and save data to a new file | |
if isfile("$(currency)_metrics_data_$(date).csv") | |
metrics_df = CSV.File("$(currency)_metrics_data_$(date).csv") |> DataFrames.DataFrame | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Cleanup csv files from previous days | |
try | |
main_dir = pwd() | |
cd("data") | |
files = readdir() | |
rx1 = r"data" | |
rx2 = r".csv" | |
for file in files | |
ts = Dates.unix2datetime(stat(file).mtime) | |
file_date = Date(ts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function average_price_df(currency::String, df_in::DataFrame, df_out_price::DataFrame, df_out_candle::DataFrame) | |
if isempty(names(df_out_price)) | |
df_out_price[!,:Date] = df_in[!,:Date] | |
end | |
df_out_price[!,Symbol("$currency")] = (df_in[!,Symbol("open (EUR)")] + df_in[!,Symbol("high (EUR)")] + df_in[!,Symbol("low (EUR)")] + df_in[!,Symbol("close (EUR)")])/4 | |
candle_col = [] | |
for i in 1:size(df_in)[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# UI part of the tool | |
app = dash() | |
app.layout = html_div() do | |
html_h1("Crypto Dashboard", | |
style= ( | |
textAlign = "center", | |
) | |
), | |
html_div( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_price_data_single(currency::String) | |
df_out_price = DataFrame() | |
df_out_vol = DataFrame() | |
df_out_candle = DataFrame() | |
date = Dates.today() | |
main_dir = pwd() | |
cd("data") |