Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
removed job seekers
Browse files Browse the repository at this point in the history
  • Loading branch information
augnustin committed Apr 19, 2022
1 parent afbcfbc commit 1e33bb4
Show file tree
Hide file tree
Showing 23 changed files with 126 additions and 1,411 deletions.
87 changes: 0 additions & 87 deletions lib/mix/tasks/statistics/top_certifications.ex

This file was deleted.

150 changes: 76 additions & 74 deletions lib/vae/campaign_diffuser/datalake.ex
Original file line number Diff line number Diff line change
@@ -1,90 +1,92 @@
defmodule Vae.CampaignDiffuser.Datalake do
require Logger
alias Vae.{JobSeeker, Repo}
alias VaeWeb.{JobSeekerEmail, Mailer}
# NOT USED ANYMORE

def process_both(date \\ nil) do
process_primo_inscrits(date)
process_reinscrits(date)
end
# require Logger
# alias Vae.{JobSeeker, Repo}
# alias VaeWeb.{JobSeekerEmail, Mailer}

def process_primo_inscrits(date \\ nil), do:
process(:primo_inscrits, date)
# def process_both(date \\ nil) do
# process_primo_inscrits(date)
# process_reinscrits(date)
# end

def process_reinscrits(date \\ nil), do:
process(:reinscrits, date)
# def process_primo_inscrits(date \\ nil), do:
# process(:primo_inscrits, date)

defp process(type, date) when type in [:primo_inscrits, :reinscrits] do
results = extract_zip(type, date || Vae.Date.last_monday())
|> extract_csv()
|> Enum.map(&handle_row(&1))
# def process_reinscrits(date \\ nil), do:
# process(:reinscrits, date)

Logger.info("#{length(results)} campaign mails sent")
end
# defp process(type, date) when type in [:primo_inscrits, :reinscrits] do
# results = extract_zip(type, date || Vae.Date.last_monday())
# |> extract_csv()
# |> Enum.map(&handle_row(&1))

defp handle_row({:ok, csv_row}) do
job_seeker_data = build_job_seeker_data(csv_row)
# Logger.info("#{length(results)} campaign mails sent")
# end

(Repo.get_by(JobSeeker, email: job_seeker_data.email) || %JobSeeker{})
|> JobSeeker.changeset(job_seeker_data)
|> Repo.insert_or_update()
|> case do
{:ok, %JobSeeker{} = job_seeker} ->
job_seeker
|> JobSeekerEmail.campaign()
|> Mailer.send()
{:error, error} -> Logger.error("Error: #{inspect(error)}")
end
end
# defp handle_row({:ok, csv_row}) do
# job_seeker_data = build_job_seeker_data(csv_row)

defp build_job_seeker_data(csv_row) do
%{
identifier: csv_row["kn_individu_national"],
first_name: csv_row["prenom"] |> String.trim() |> String.capitalize(),
last_name: csv_row["nom"] |> String.trim() |> String.capitalize(),
email: csv_row["courriel"] |> String.trim() |> String.downcase(),
telephone: csv_row["telephone"] |> String.trim(),
postal_code: csv_row["code_postal"] |> String.trim(),
education_level: csv_row["listeformation"],
experience:
csv_row["dc_listeromemetierrech"]
|> String.split("|")
|> Enum.reject(&(&1 in [nil, "", "NULL"]))
|> Enum.reduce(%{}, fn
rome, acc ->
[key, _, value] = String.split(rome, "-", parts: 3)
Map.put_new(acc, String.trim(key), String.trim(value))
end)
}
end
# (Repo.get_by(JobSeeker, email: job_seeker_data.email) || %JobSeeker{})
# |> JobSeeker.changeset(job_seeker_data)
# |> Repo.insert_or_update()
# |> case do
# {:ok, %JobSeeker{} = job_seeker} ->
# job_seeker
# |> JobSeekerEmail.campaign()
# |> Mailer.send()
# {:error, error} -> Logger.error("Error: #{inspect(error)}")
# end
# end

defp extract_zip(type, date) do
case System.cmd("/bin/sh", ["-c", "bunzip2 -kc #{get_zip_path(type, date)}"]) do
{data, 0} ->
csv_path = get_csv_path(type, date)
{ File.write!(csv_path, data), csv_path}
_ ->
{:error, %{type: type}}
end
end
# defp build_job_seeker_data(csv_row) do
# %{
# identifier: csv_row["kn_individu_national"],
# first_name: csv_row["prenom"] |> String.trim() |> String.capitalize(),
# last_name: csv_row["nom"] |> String.trim() |> String.capitalize(),
# email: csv_row["courriel"] |> String.trim() |> String.downcase(),
# telephone: csv_row["telephone"] |> String.trim(),
# postal_code: csv_row["code_postal"] |> String.trim(),
# education_level: csv_row["listeformation"],
# experience:
# csv_row["dc_listeromemetierrech"]
# |> String.split("|")
# |> Enum.reject(&(&1 in [nil, "", "NULL"]))
# |> Enum.reduce(%{}, fn
# rome, acc ->
# [key, _, value] = String.split(rome, "-", parts: 3)
# Map.put_new(acc, String.trim(key), String.trim(value))
# end)
# }
# end

defp extract_csv({:ok, csv_path}) do
csv_path
|> File.stream!()
|> CSV.decode(separator: ?;, headers: true)
end
# defp extract_zip(type, date) do
# case System.cmd("/bin/sh", ["-c", "bunzip2 -kc #{get_zip_path(type, date)}"]) do
# {data, 0} ->
# csv_path = get_csv_path(type, date)
# { File.write!(csv_path, data), csv_path}
# _ ->
# {:error, %{type: type}}
# end
# end

defp extract_csv({:error, _} = error), do: error
# defp extract_csv({:ok, csv_path}) do
# csv_path
# |> File.stream!()
# |> CSV.decode(separator: ?;, headers: true)
# end

defp get_csv_path(type, date), do: "/tmp/emails_#{type}_#{date}.csv"
# defp extract_csv({:error, _} = error), do: error

defp get_zip_path(type, date) do
if System.get_env("CAMPAIGN_BASE_PATH") do
"#{System.get_env("CAMPAIGN_BASE_PATH")}/avril_de_#{type}_delta_#{Timex.format!(date, "{YYYY}{0M}{0D}")}*.bz2"
else
# Debugging
"priv/avril_de_#{type}_delta_#{Timex.format!(date, "{YYYY}{0M}{0D}")}*.bz2"
end
end
# defp get_csv_path(type, date), do: "/tmp/emails_#{type}_#{date}.csv"

# defp get_zip_path(type, date) do
# if System.get_env("CAMPAIGN_BASE_PATH") do
# "#{System.get_env("CAMPAIGN_BASE_PATH")}/avril_de_#{type}_delta_#{Timex.format!(date, "{YYYY}{0M}{0D}")}*.bz2"
# else
# # Debugging
# "priv/avril_de_#{type}_delta_#{Timex.format!(date, "{YYYY}{0M}{0D}")}*.bz2"
# end
# end

end
14 changes: 0 additions & 14 deletions lib/vae/event/api.ex

This file was deleted.

29 changes: 0 additions & 29 deletions lib/vae/event/event_supervisor.ex

This file was deleted.

36 changes: 0 additions & 36 deletions lib/vae/event/handler.ex

This file was deleted.

6 changes: 1 addition & 5 deletions lib/vae/pole_emploi/mappers/user_info.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Vae.PoleEmploi.Mappers.UserInfoMapper do
alias Vae.{JobSeeker, Repo}
alias Vae.Repo

def map(%OAuth2.Response{body: body}) do
%{
Expand All @@ -8,10 +8,6 @@ defmodule Vae.PoleEmploi.Mappers.UserInfoMapper do
first_name: Vae.String.capitalize(body["given_name"]),
last_name: Vae.String.capitalize(body["family_name"]),
pe_id: body["idIdentiteExterne"],
job_seeker:
Repo.get_by(JobSeeker,
email: String.downcase(body["email"])
),
email_confirmed_at: Timex.now()
}
end
Expand Down
Loading

0 comments on commit 1e33bb4

Please sign in to comment.