Created
December 1, 2018 20:31
-
-
Save Wikunia/c1ecd45e542d2d2fd726dbcf662587f0 to your computer and use it in GitHub Desktop.
Kaggle Santa 2018 Julia animation
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
using CSV, DataFrames, Distances, Formatting, Plots | |
cities = CSV.read("cities_p.csv"); | |
subm_df = CSV.read("submission.csv"); | |
subm_path = subm_df[:Path]; | |
# this includes a column with primes true or false | |
cities_csv = CSV.read("cities_p.csv"); | |
subm_path = collect(skipmissing(subm_df[:Path])) | |
subm_path .+= 1 | |
gr() | |
prime_idx = findall(cities_csv[:primes] .== true); | |
width = 1920 | |
height = 1080 | |
each_length = 2 | |
anim = Animation() | |
plot(cities_csv[:X][prime_idx], cities_csv[:Y][prime_idx], markersize=1, seriestype=:scatter, | |
size = (width, height), label="", color=:orange, axis=false) | |
frame(anim) | |
for i=1:each_length:1200 #length(subm_path) | |
xlims_min = minimum(cities_csv[:X][subm_path[i:i+each_length]]) | |
xlims_max = maximum(cities_csv[:X][subm_path[i:i+each_length]]) | |
ylims_min = minimum(cities_csv[:Y][subm_path[i:i+each_length]]) | |
ylims_max = maximum(cities_csv[:Y][subm_path[i:i+each_length]]) | |
xlims_padding = (600-(xlims_max-xlims_min))/2 | |
ylims_padding = (337-(ylims_max-ylims_min))/2 | |
for k=i:i+each_length-1 | |
if k % 10 == 0 && !cities_csv[:primes][subm_path[i]] | |
plot!(cities_csv[:X][subm_path[k:k+1]], cities_csv[:Y][subm_path[k:k+1]], linewidth=4, | |
seriestype=:path,size = (width, height), color = :red, label="", axis=false, | |
xlims = (xlims_min-xlims_padding,xlims_max+xlims_padding), | |
ylims = (ylims_min-ylims_padding,ylims_max+ylims_padding) | |
) | |
elseif k % 10 == 0 | |
plot!(cities_csv[:X][subm_path[k:k+1]], cities_csv[:Y][subm_path[k:k+1]], linewidth=4, | |
seriestype=:path, color = :green, label="", axis=false) | |
else | |
plot!(cities_csv[:X][subm_path[k:k+1]], cities_csv[:Y][subm_path[k:k+1]], linewidth=1, | |
seriestype=:path, color = :blue, label="", axis=false) | |
end | |
end | |
frame(anim) | |
end | |
each_length = 10 | |
for i=1201:each_length:2200 #length(subm_path) | |
xlims_min = minimum(cities_csv[:X][subm_path[i:i+each_length]]) | |
xlims_max = maximum(cities_csv[:X][subm_path[i:i+each_length]]) | |
ylims_min = minimum(cities_csv[:Y][subm_path[i:i+each_length]]) | |
ylims_max = maximum(cities_csv[:Y][subm_path[i:i+each_length]]) | |
xlims_padding = (600+5*(i-1201)-(xlims_max-xlims_min))/2 | |
ylims_padding = (337+2.81*(i-1201)-(ylims_max-ylims_min))/2 | |
xlims_min = max(0, xlims_min-xlims_padding) | |
xlims_max = min(5100, xlims_max+xlims_padding) | |
ylims_min = max(0, ylims_min-ylims_padding) | |
ylims_max = min(3400, ylims_max+ylims_padding) | |
for k=i:i+each_length-1 | |
if k % 10 == 0 && !cities_csv[:primes][subm_path[i]] | |
plot!(cities_csv[:X][subm_path[k:k+1]], cities_csv[:Y][subm_path[k:k+1]], linewidth=4, | |
seriestype=:path,size = (width, height), color = :red, label="", axis=false, | |
xlims = (xlims_min,xlims_max), | |
ylims = (ylims_min,ylims_max) | |
) | |
elseif k % 10 == 0 | |
plot!(cities_csv[:X][subm_path[k:k+1]], cities_csv[:Y][subm_path[k:k+1]], linewidth=4, | |
seriestype=:path, color = :green, label="", axis=false) | |
else | |
plot!(cities_csv[:X][subm_path[k:k+1]], cities_csv[:Y][subm_path[k:k+1]], linewidth=1, | |
seriestype=:path, color = :blue, label="", axis=false) | |
end | |
end | |
frame(anim) | |
println("i: ", i) | |
end | |
each_length = 500 | |
for i=2201:each_length:length(subm_path)-each_length | |
plot!(cities_csv[:X][subm_path[i:i+each_length]], cities_csv[:Y][subm_path[i:i+each_length]], linewidth=4, | |
seriestype=:path,size = (width, height), color = :blue, label="", axis=false, | |
xlims = (0,5100), | |
ylims = (0,3400) | |
) | |
frame(anim) | |
println("i: ", i) | |
end | |
plot!(cities_csv[:X][subm_path[197701:length(subm_path)]], cities_csv[:Y][subm_path[197701:length(subm_path)]], linewidth=4, | |
seriestype=:path,size = (width, height), color = :blue, label="", axis=false, | |
xlims = (0,5100), | |
ylims = (0,3400) | |
) | |
for i = 1:200 | |
frame(anim) | |
end | |
mp4(anim, "path_prime_20.mp4", fps = 20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment