Skip to content

Instantly share code, notes, and snippets.

function raw_to_df(raw_data)
df = DataFrame(raw_data[1])
df_names = Symbol.(vcat(raw_data[2]...))
df = DataFrames.rename(df, df_names)
timestamps = df[!,:timestamp]
select!(df, Not([:timestamp]))
for col in eachcol(df)
function plot_price_vol_data(index::Int64, duration::Int64, window::Int64)
# Retrieve data from various helper functions
Price_df, Candle_df, Vol_df = get_price_data_single(currencies[index])
# Make sure that duration does not exceed the number of rows - max(windows) in the DataFrame
# This allows calculation of MA for the longest duration
if duration > size(Price_df)[1]-maximum(windows)
duration = size(Price_df)[1]-maximum(windows)
end
callback!(
app,
Output("graph", "figure"),
Input("mode_ID", "value"),
Input("pair_ID", "value"),
Input("window_ID", "value"),
Input("duration_ID", "value"),
) do mode_ID, pair_ID, window_ID, duration_ID
t1, t2, t3, t4, t5, t6 = plot_price_vol_data(pair_ID, duration_ID, window_ID)
# GitHub link
const URL = "https://raw.githubusercontent.com/vnegi10/Health_data_analysis/master/data"
# CSV files from Samsung Health app
files = ["com.samsung.shealth.tracker.pedometer_day_summary.202110031456.csv",
"com.samsung.shealth.tracker.heart_rate.202110031456.csv",
"com.samsung.health.floors_climbed.202110031456.csv"]
# Function to generate url
gen_url(file::String, url::String=URL) = joinpath(url, file)
# 1 - Check size of the DataFrame, returns (rows, columns)
size(df_pedometer_raw)
# 1 - Result
# (3221, 20)
# 2- List column names
names(df_pedometer_raw)
# 2- Result
# Create an independent copy
df_pedometer = deepcopy(df_pedometer_raw)
# Set format for the DateTime object
datef = dateformat"y-m-d H:M:S.s"
# Convert create_time column from string into DateTime objects
df_pedometer[!, :create_time] = DateTime.(df_pedometer_raw[!, :create_time], datef)
# Convert distance into km and time into minutes
cumul_distance = Float64[]
day_type, day, month = (String[] for i = 1:3)
year = Int64[]
for i = 1:size(df_pedometer)[1]
push!(cumul_distance, sum(df_pedometer[!, :distance][1:i]))
push!(day, Dates.dayname(df_pedometer[!, :create_time][i]))
push!(month, Dates.monthname(df_pedometer[!, :create_time][i]))
push!(year, Dates.year(df_pedometer[!, :create_time][i]))
df_pedometer_filter = df_pedometer |>
@filter(_.create_time > start_date && _.create_time < end_date) |> DataFrame
df_pedometer_filter |> @vlplot("mark"={:area, "line" = {"color" = "seagreen"},
"color"={"x1"=1, "y1"=1, "x2"=1, "y2"=0,
"gradient"=:linear, "stops" = [
{"offset"=0, "color"="white"},
{"offset"=1, "color"="green"}]}},
x = {:create_time, "axis" = {"title" = "Time", "labelFontSize" = 12, "titleFontSize" = 14}, "type" = "temporal"},
y = {:step_count, "axis" = {"title" = "Daily steps", "labelFontSize" = 12, "titleFontSize" = 14 }},
width = 750, height = 500,
"title" = {"text" = "Daily steps from $(Date.(start_date)) to $(Date.(end_date))", "fontSize" = 16})
figure2 = df_pedometer_filter |>
@vlplot(:bar,
x = {:step_count, "axis" = {"title" = "Number of steps", "labelFontSize" = 12, "titleFontSize" = 14}, "bin" = {"maxbins" = bins1}},
y = {"count()", "axis" = {"title" = "Number of counts", "labelFontSize" = 12, "titleFontSize" = 14 }},
width = 850, height = 500,
"title" = {"text" = "Step count distribution from $(Date.(start_date)) to $(Date.(end_date))", "fontSize" = 16},
color = "year:n")