2023-07-22 17:22:35 +07:00
|
|
|
|
|
|
|
using SearchLight, SearchLightPostgreSQL, LibPQ, JSON3
|
|
|
|
using DataFrames
|
|
|
|
include("../lib/DatabaseSupport.jl")
|
|
|
|
using .DatabaseSupport
|
|
|
|
|
|
|
|
function table_to_json(name,df)
|
|
|
|
ar = []
|
|
|
|
for df_row in eachrow(df)
|
|
|
|
dict = Dict()
|
|
|
|
for id in names(df_row)
|
|
|
|
dict[id] = df_row[id]
|
|
|
|
end
|
|
|
|
push!(ar,dict)
|
|
|
|
end
|
|
|
|
open("public/assets/"*name*".json", "w") do io
|
|
|
|
JSON3.write(io, ar)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-28 21:49:29 +07:00
|
|
|
function compile(name)
|
|
|
|
df = select_from_table([name => ["*"]])
|
|
|
|
table_to_json(name,df)
|
2023-07-22 17:22:35 +07:00
|
|
|
end
|
|
|
|
|
2023-07-28 21:49:29 +07:00
|
|
|
function move_requests(name)
|
|
|
|
df_requests = select_from_table(["$(name)_requests" => ["*"]], where_data=["verified" => true, "added" => false])
|
|
|
|
df = select_from_table([name => ["*"]])
|
2023-07-22 17:22:35 +07:00
|
|
|
latitudes = df.latitude
|
|
|
|
longitudes = df.longitude
|
|
|
|
for df_row in eachrow(df_requests)
|
|
|
|
ind_id_given = ismissing(df_row.id_given) ? nothing : findfirst(df_row.id_given.==df.id)
|
|
|
|
if (!isnothing(ind_id_given))
|
|
|
|
id = df[ind_id_given,:id]
|
|
|
|
row_found = df[ind_id_given,Not(:id)]
|
|
|
|
dict = Dict(zip(names(row_found),values(row_found)))
|
|
|
|
dict["members"] += 1
|
2023-07-28 21:49:29 +07:00
|
|
|
update_table(name,dict, where_data=["id" => id])
|
2023-07-22 17:22:35 +07:00
|
|
|
else
|
|
|
|
id = df_row.id
|
|
|
|
dict_update = Dict("added" => true)
|
2023-07-28 21:49:29 +07:00
|
|
|
update_table("$(name)_requests",dict_update, where_data=["id" => id])
|
2023-07-22 17:22:35 +07:00
|
|
|
|
|
|
|
df_row_to_add = df_row[Not(:id_given)]
|
|
|
|
df_row_to_add = df_row_to_add[Not(:verified)]
|
|
|
|
df_row_to_add = df_row_to_add[Not(:added)]
|
|
|
|
df_row_to_add = df_row_to_add[Not(:id)]
|
|
|
|
dict = Dict(zip(names(df_row_to_add),values(df_row_to_add)))
|
|
|
|
dict["members"] = 1
|
2023-07-28 21:49:29 +07:00
|
|
|
insert_into_table(name,dict)
|
2023-07-22 17:22:35 +07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2023-08-17 16:05:53 +07:00
|
|
|
#move_requests("groups")
|
2023-07-28 21:49:29 +07:00
|
|
|
compile("groups")
|
|
|
|
|
2023-07-28 21:51:43 +07:00
|
|
|
## move_requests("communes")
|
2023-07-28 21:49:29 +07:00
|
|
|
compile("communes")
|
|
|
|
|
|
|
|
compile("cooperatives")
|
|
|
|
|
|
|
|
compile("parties")
|
|
|
|
|
2023-08-17 16:03:57 +07:00
|
|
|
compile("partners")
|
|
|
|
|
|
|
|
compile("trade_unions")
|