<commit_before># Script for populating the database. You can run it as:
#
#     mix run priv/repo/seeds.exs
#
# Inside the script, you can read and write to any of your
# repositories directly:
#
#     Mealprep.Repo.insert!(%Mealprep.SomeSchema{})
#
# We recommend using the bang functions (`insert!`, `update!`
# and so on) as they will fail if something goes wrong.

alias Mealprep.{
    Language,
    Repo
}
alias Mealprep.Nutrition.{
    FoodUnit,
    FoodUnitTr
}

# Insert hardcoded languages
[
    %Language{ietfTag: "fi-FI", nativeName: "suomi", englishName: "Finnish"},
    %Language{ietfTag: "sv-FI", nativeName: "svenska", englishName: "Swedish"},
    %Language{ietfTag: "en-US", nativeName: "English", englishName: "English"},
    %Language{ietfTag: "la", nativeName: "tieteellinen", englishName: "Scientific"}
]
|> Enum.each(fn(lang) -> Repo.insert!(lang) end)

# Insert food units
File.stream!(Path.expand("../../seed_data/foodunit_FI.csv", __DIR__))
|> CSV.decode!(separator: ?;)
|> Stream.drop(1)
|> Enum.each(fn([thscode, description, _]) ->
    lang = Repo.get_by!(Language, ietfTag: "fi-FI")
    unit = Repo.insert!(%FoodUnit{thscode: thscode})
    Repo.insert!(%FoodUnitTr{language_id: lang.id, food_unit_id: unit.id, description: description})
end)<commit_msg>Seed other food unit translations<commit_after># Script for populating the database. You can run it as:
#
#     mix run priv/repo/seeds.exs
#
# Inside the script, you can read and write to any of your
# repositories directly:
#
#     Mealprep.Repo.insert!(%Mealprep.SomeSchema{})
#
# We recommend using the bang functions (`insert!`, `update!`
# and so on) as they will fail if something goes wrong.

alias Mealprep.{
    Language,
    Repo
}
alias Mealprep.Nutrition.{
    FoodUnit,
    FoodUnitTr
}

# Insert hardcoded languages
[
    %Language{ietfTag: "fi-FI", nativeName: "suomi", englishName: "Finnish"},
    %Language{ietfTag: "sv-FI", nativeName: "svenska", englishName: "Swedish"},
    %Language{ietfTag: "en-US", nativeName: "English", englishName: "English"},
    %Language{ietfTag: "la", nativeName: "tieteellinen", englishName: "Scientific"}
]
|> Enum.each(fn(lang) -> Repo.insert!(lang) end)

# Insert food units, Finnish first
File.stream!(Path.expand("../../seed_data/foodunit_FI.csv", __DIR__))
|> CSV.decode!(separator: ?;)
|> Stream.drop(1)
|> Enum.each(fn([thscode, description, _]) ->
    lang = Repo.get_by!(Language, ietfTag: "fi-FI")
    unit = Repo.insert!(%FoodUnit{thscode: thscode})
    Repo.insert!(%FoodUnitTr{language_id: lang.id, food_unit_id: unit.id, description: description})
end)
# Then other languages
File.stream!(Path.expand("../../seed_data/foodunit_SV.csv", __DIR__))
|> CSV.decode!(separator: ?;)
|> Stream.drop(1)
|> Enum.each(fn([thscode, description, _]) ->
    lang = Repo.get_by!(Language, ietfTag: "sv-FI")
    unit = Repo.get_by!(FoodUnit, thscode: thscode)
    Repo.insert!(%FoodUnitTr{language_id: lang.id, food_unit_id: unit.id, description: description})
end)
File.stream!(Path.expand("../../seed_data/foodunit_EN.csv", __DIR__))
|> CSV.decode!(separator: ?;)
|> Stream.drop(1)
|> Enum.each(fn([thscode, description, _]) ->
    lang = Repo.get_by!(Language, ietfTag: "en-US")
    unit = Repo.get_by!(FoodUnit, thscode: thscode)
    Repo.insert!(%FoodUnitTr{language_id: lang.id, food_unit_id: unit.id, description: description})
end)
{'fraction_non_alphanumeric': 0.1680522565320665, 'fraction_numerical': 0.0011876484560570072, 'mean_word_length': 4.758974358974359, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1734591', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1194, 'n_words': 268}