Skip to content

Commit efceeb3

Browse files
authored
IRVE : utilisation de floats en base de données pour la valeur puissance_nominale (#5531)
1 parent cb9c168 commit efceeb3

4 files changed

Lines changed: 33 additions & 12 deletions

File tree

apps/transport/lib/db/irve_valid_pdc.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ defmodule DB.IRVEValidPDC do
3131
field(:nbre_pdc, :integer, null: false)
3232
field(:id_pdc_itinerance, :string, null: false)
3333
field(:id_pdc_local, :string)
34-
field(:puissance_nominale, :decimal, null: false)
34+
field(:puissance_nominale, :float, null: false)
3535
field(:prise_type_ef, :boolean, null: false)
3636
field(:prise_type_2, :boolean, null: false)
3737
field(:prise_type_combo_ccs, :boolean, null: false)

apps/transport/lib/irve/data_frame.ex

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,9 @@ defmodule Transport.IRVE.DataFrame do
116116
117117
Congratulations for reading this far.
118118
"""
119+
119120
def dataframe_from_csv_body!(body, schema \\ Transport.IRVE.StaticIRVESchema.schema_content(), strict \\ true) do
120-
dtypes =
121-
schema
122-
|> Map.fetch!("fields")
123-
|> Enum.map(fn %{"name" => name, "type" => type} ->
124-
{
125-
String.to_atom(name),
126-
String.to_atom(type)
127-
|> Transport.IRVE.DataFrame.remap_schema_type(strict)
128-
}
129-
end)
121+
dtypes = schema_dtypes(schema, strict)
130122

131123
delimiter = guess_delimiter!(body)
132124

@@ -137,6 +129,26 @@ defmodule Transport.IRVE.DataFrame do
137129
end
138130
end
139131

132+
@doc """
133+
Computes Explorer dtypes from a TableSchema, using `remap_schema_type/2`.
134+
135+
iex> Transport.IRVE.DataFrame.schema_dtypes() |> Keyword.fetch!(:puissance_nominale)
136+
{:f, 64}
137+
iex> Transport.IRVE.DataFrame.schema_dtypes() |> Keyword.fetch!(:id_pdc_itinerance)
138+
:string
139+
"""
140+
def schema_dtypes(schema \\ Transport.IRVE.StaticIRVESchema.schema_content(), strict \\ true) do
141+
schema
142+
|> Map.fetch!("fields")
143+
|> Enum.map(fn %{"name" => name, "type" => type} ->
144+
{
145+
String.to_atom(name),
146+
String.to_atom(type)
147+
|> Transport.IRVE.DataFrame.remap_schema_type(strict)
148+
}
149+
end)
150+
end
151+
140152
defmodule ColumnDelimiterGuessError do
141153
@moduledoc """
142154
Raised when the code could not determine the proper delimiter.

apps/transport/lib/irve/database_exporter.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ defmodule Transport.IRVE.DatabaseExporter do
3030
stream
3131
|> Stream.map(&Map.merge(elem(&1, 0), elem(&1, 1)))
3232
|> Enum.into([])
33-
|> Explorer.DataFrame.new()
33+
|> Explorer.DataFrame.new(dtypes: Transport.IRVE.DataFrame.schema_dtypes())
3434

3535
{:ok, result}
3636
end,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule DB.Repo.Migrations.ChangeIrvePuissanceNominaleToFloat do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:irve_valid_pdc) do
6+
modify(:puissance_nominale, :float, from: :decimal)
7+
end
8+
end
9+
end

0 commit comments

Comments
 (0)