Skip to content

Commit

Permalink
Merge pull request #230 from psrenergy/gb/fix-ts-creation-message
Browse files Browse the repository at this point in the history
Fix validation when creating time series via API
  • Loading branch information
guilhermebodin authored Nov 7, 2024
2 parents 9d95af3 + c5171db commit e7382f7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "PSRClassesInterface"
uuid = "1eab49e5-27d8-4905-b9f6-327b6ea666c4"
version = "0.17.2"
version = "0.17.3"

[deps]
DBInterface = "a10d1c49-ce27-4219-8d33-6db1a4562965"
Expand Down
9 changes: 9 additions & 0 deletions src/PSRDatabaseSQLite/collection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,15 @@ function _get_collection_time_series_files_tables(::SQLite.DB, collection_id::St
return string(collection_id, "_time_series_files")
end

function _dimensions_of_time_series_group(collection::Collection, group_id::String)
time_series = collection.time_series
for (_, time_series_attribute) in time_series
if time_series_attribute.group_id == group_id
return time_series_attribute.dimension_names
end
end
end

function _validate_actions_on_foreign_key(
collection_id::String,
table_name::String,
Expand Down
1 change: 0 additions & 1 deletion src/PSRDatabaseSQLite/create.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ function create_element!(
catch e
@error """
Error creating element in collection \"$collection_id\"
error message: $(e.msg)
"""
rethrow(e)
end
Expand Down
7 changes: 6 additions & 1 deletion src/PSRDatabaseSQLite/validate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,21 @@ function _throw_if_data_does_not_match_group(
df::DataFrame,
)
collection = _get_collection(db, collection_id)
dimensions_of_group = _dimensions_of_time_series_group(collection, group)
dimensions_in_df = []
attributes_in_df = []

for column in names(df)
if column in keys(collection.time_series)
# should be an attribute
push!(attributes_in_df, column)
else
elseif column in dimensions_of_group
# should be a dimension
push!(dimensions_in_df, column)
else
psr_database_sqlite_error(
"Attribute \"$column\" is not an attribute or dimension of the time series group \"$group\".",
)
end
end

Expand Down

2 comments on commit e7382f7

@guilhermebodin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/118926

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.17.3 -m "<description of version>" e7382f7e52d14ab6b58b1ef91a6e418825486f56
git push origin v0.17.3

Please sign in to comment.