Skip to content

Commit

Permalink
formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-lara committed Dec 21, 2023
1 parent 1192753 commit deebdbc
Show file tree
Hide file tree
Showing 37 changed files with 932 additions and 829 deletions.
86 changes: 43 additions & 43 deletions src/deterministic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ function Deterministic(;
name,
data,
resolution,
scaling_factor_multiplier=nothing,
normalization_factor=1.0,
internal=InfrastructureSystemsInternal(),
scaling_factor_multiplier = nothing,
normalization_factor = 1.0,
internal = InfrastructureSystemsInternal(),
)
data = handle_normalization_factor(convert_data(data), normalization_factor)
return Deterministic(name, data, resolution, scaling_factor_multiplier, internal)
Expand All @@ -54,15 +54,15 @@ function Deterministic(
name::AbstractString,
data::AbstractDict,
resolution::Dates.Period;
normalization_factor::NormalizationFactor=1.0,
scaling_factor_multiplier::Union{Nothing, Function}=nothing,
normalization_factor::NormalizationFactor = 1.0,
scaling_factor_multiplier::Union{Nothing, Function} = nothing,
)
return Deterministic(
name=name,
data=data,
resolution=resolution,
scaling_factor_multiplier=scaling_factor_multiplier,
internal=InfrastructureSystemsInternal(),
return Deterministic(;
name = name,
data = data,
resolution = resolution,
scaling_factor_multiplier = scaling_factor_multiplier,
internal = InfrastructureSystemsInternal(),
)
end

Expand All @@ -84,8 +84,8 @@ Construct Deterministic from a Dict of TimeArrays.
function Deterministic(
name::AbstractString,
input_data::AbstractDict{Dates.DateTime, <:TimeSeries.TimeArray};
normalization_factor::NormalizationFactor=1.0,
scaling_factor_multiplier::Union{Nothing, Function}=nothing,
normalization_factor::NormalizationFactor = 1.0,
scaling_factor_multiplier::Union{Nothing, Function} = nothing,
)
data_type = eltype(TimeSeries.values(first(values(input_data))))
data = SortedDict{Dates.DateTime, Vector{data_type}}()
Expand All @@ -99,12 +99,12 @@ function Deterministic(
data[k] = TimeSeries.values(v)
end

return Deterministic(
name=name,
data=data,
resolution=resolution,
normalization_factor=normalization_factor,
scaling_factor_multiplier=scaling_factor_multiplier,
return Deterministic(;
name = name,
data = data,
resolution = resolution,
normalization_factor = normalization_factor,
scaling_factor_multiplier = scaling_factor_multiplier,
)
end

Expand All @@ -128,17 +128,17 @@ function Deterministic(
filename::AbstractString,
component::InfrastructureSystemsComponent,
resolution::Dates.Period;
normalization_factor::NormalizationFactor=1.0,
scaling_factor_multiplier::Union{Nothing, Function}=nothing,
normalization_factor::NormalizationFactor = 1.0,
scaling_factor_multiplier::Union{Nothing, Function} = nothing,
)
component_name = get_name(component)
raw_data = read_time_series(Deterministic, filename, component_name)
return Deterministic(
name,
raw_data,
resolution;
normalization_factor=normalization_factor,
scaling_factor_multiplier=scaling_factor_multiplier,
normalization_factor = normalization_factor,
scaling_factor_multiplier = scaling_factor_multiplier,
)
end

Expand All @@ -149,25 +149,25 @@ function Deterministic(
name::AbstractString,
series_data::RawTimeSeries,
resolution::Dates.Period;
normalization_factor::NormalizationFactor=1.0,
scaling_factor_multiplier::Union{Nothing, Function}=nothing,
normalization_factor::NormalizationFactor = 1.0,
scaling_factor_multiplier::Union{Nothing, Function} = nothing,
)
return Deterministic(
name=name,
data=series_data.data,
resolution=resolution,
normalization_factor=normalization_factor,
scaling_factor_multiplier=scaling_factor_multiplier,
return Deterministic(;
name = name,
data = series_data.data,
resolution = resolution,
normalization_factor = normalization_factor,
scaling_factor_multiplier = scaling_factor_multiplier,
)
end

function Deterministic(ts_metadata::DeterministicMetadata, data::SortedDict)
return Deterministic(
name=get_name(ts_metadata),
resolution=get_resolution(ts_metadata),
data=data,
scaling_factor_multiplier=get_scaling_factor_multiplier(ts_metadata),
internal=InfrastructureSystemsInternal(get_time_series_uuid(ts_metadata)),
return Deterministic(;
name = get_name(ts_metadata),
resolution = get_resolution(ts_metadata),
data = data,
scaling_factor_multiplier = get_scaling_factor_multiplier(ts_metadata),
internal = InfrastructureSystemsInternal(get_time_series_uuid(ts_metadata)),
)
end

Expand All @@ -176,8 +176,8 @@ function Deterministic(info::TimeSeriesParsedInfo)
info.name,
info.data,
info.resolution;
normalization_factor=info.normalization_factor,
scaling_factor_multiplier=info.scaling_factor_multiplier,
normalization_factor = info.normalization_factor,
scaling_factor_multiplier = info.scaling_factor_multiplier,
)
end

Expand Down Expand Up @@ -278,16 +278,16 @@ get_initial_times(forecast::Deterministic) = get_initial_times_common(forecast)
get_initial_timestamp(forecast::Deterministic) = get_initial_timestamp_common(forecast)
get_interval(forecast::Deterministic) = get_interval_common(forecast)
iterate_windows(forecast::Deterministic) = iterate_windows_common(forecast)
get_window(f::Deterministic, initial_time::Dates.DateTime; len=nothing) =
get_window_common(f, initial_time; len=len)
get_window(f::Deterministic, initial_time::Dates.DateTime; len = nothing) =
get_window_common(f, initial_time; len = len)

function make_time_array(forecast::Deterministic)
# Artificial limitation to reduce scope.
@assert_op get_count(forecast) == 1
timestamps = range(
get_initial_timestamp(forecast);
step=get_resolution(forecast),
length=get_horizon(forecast),
step = get_resolution(forecast),
length = get_horizon(forecast),
)
data = first(values(get_data(forecast)))
return TimeSeries.TimeArray(timestamps, data)
Expand Down
4 changes: 2 additions & 2 deletions src/deterministic_single_time_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ get_resolution(val::DeterministicSingleTimeSeries) = get_resolution(val.single_t
function get_window(
forecast::DeterministicSingleTimeSeries,
initial_time::Dates.DateTime;
len::Union{Nothing, Int}=nothing,
len::Union{Nothing, Int} = nothing,
)
tdiff = Dates.Millisecond(initial_time - forecast.initial_timestamp)
interval_ms = Dates.Millisecond(forecast.interval)
Expand Down Expand Up @@ -134,7 +134,7 @@ function iterate_windows(forecast::DeterministicSingleTimeSeries)
end

initial_times =
range(forecast.initial_timestamp; step=forecast.interval, length=forecast.count)
range(forecast.initial_timestamp; step = forecast.interval, length = forecast.count)
return (get_window(forecast, it) for it in initial_times)
end

Expand Down
14 changes: 7 additions & 7 deletions src/forecasts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ end
"""
Return the forecast window corresponsing to interval index.
"""
function get_window(forecast::Forecast, index::Int; len=nothing)
return get_window(forecast, index_to_initial_time(forecast, index); len=len)
function get_window(forecast::Forecast, index::Int; len = nothing)
return get_window(forecast, index_to_initial_time(forecast, index); len = len)

Check warning on line 65 in src/forecasts.jl

View check run for this annotation

Codecov / codecov/patch

src/forecasts.jl#L64-L65

Added lines #L64 - L65 were not covered by tests
end

function iterate_windows_common(forecast)
Expand All @@ -82,17 +82,17 @@ Return a TimeSeries.TimeArray for one forecast window.
function make_time_array(
forecast::Forecast,
start_time::Dates.DateTime;
len::Union{Nothing, Int}=nothing,
len::Union{Nothing, Int} = nothing,
)
return get_window(forecast, start_time; len=len)
return get_window(forecast, start_time; len = len)
end

function make_timestamps(forecast::Forecast, initial_time::Dates.DateTime, len=nothing)
function make_timestamps(forecast::Forecast, initial_time::Dates.DateTime, len = nothing)
if len === nothing
len = get_horizon(forecast)
end

return range(initial_time; length=len, step=get_resolution(forecast))
return range(initial_time; length = len, step = get_resolution(forecast))
end

# This method requires that the forecast type implement a `get_data` method like
Expand All @@ -118,7 +118,7 @@ end
function get_window_common(
forecast,
initial_time::Dates.DateTime;
len::Union{Nothing, Int}=nothing,
len::Union{Nothing, Int} = nothing,
)
horizon = get_horizon(forecast)
if len === nothing
Expand Down
55 changes: 29 additions & 26 deletions src/hdf5_time_series_storage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ Constructs Hdf5TimeSeriesStorage.
"""
function Hdf5TimeSeriesStorage(
create_file::Bool;
filename=nothing,
directory=nothing,
read_only=false,
compression=CompressionSettings(),
filename = nothing,
directory = nothing,
read_only = false,
compression = CompressionSettings(),
)
if create_file
if isnothing(filename)
Expand Down Expand Up @@ -72,8 +72,8 @@ Constructs Hdf5TimeSeriesStorage from an existing file.
function from_file(
::Type{Hdf5TimeSeriesStorage},
filename::AbstractString;
read_only=false,
directory=nothing,
read_only = false,
directory = nothing,
)
if !isfile(filename)
error("time series storage $filename does not exist")
Expand All @@ -88,7 +88,7 @@ function from_file(
copy_h5_file(filename, file_path)
end

storage = Hdf5TimeSeriesStorage(false; filename=file_path, read_only=read_only)
storage = Hdf5TimeSeriesStorage(false; filename = file_path, read_only = read_only)
if !read_only
version = read_data_format_version(storage)
if version == "1.0.0"
Expand Down Expand Up @@ -117,7 +117,7 @@ undergoing a deepcopy.
- `storage::Hdf5TimeSeriesStorage`: storage instance
- `directory::String`: If nothing, use tempdir
"""
function copy_to_new_file!(storage::Hdf5TimeSeriesStorage, directory=nothing)
function copy_to_new_file!(storage::Hdf5TimeSeriesStorage, directory = nothing)
if directory === nothing
directory = tempdir()
end
Expand Down Expand Up @@ -181,12 +181,12 @@ function serialize_time_series!(
settings = storage.compression
if settings.enabled
if settings.type == CompressionTypes.BLOSC
group["data", blosc=settings.level] = data
group["data", blosc = settings.level] = data
elseif settings.type == CompressionTypes.DEFLATE
if settings.shuffle
group["data", shuffle=(), deflate=settings.level] = data
group["data", shuffle = (), deflate = settings.level] = data
else
group["data", deflate=settings.level] = data
group["data", deflate = settings.level] = data
end
else
error("not implemented for type=$(settings.type)")
Expand Down Expand Up @@ -402,8 +402,8 @@ function deserialize_time_series(
TimeSeries.TimeArray(
range(
attributes["start_time"];
length=length(rows),
step=attributes["resolution"],
length = length(rows),
step = attributes["resolution"],
),
data,
),
Expand Down Expand Up @@ -459,7 +459,8 @@ function get_hdf_array(
data[start_time] = dataset[rows, columns.start]
else
data_read = dataset[rows, columns]
for (i, it) in enumerate(range(start_time; length=length(columns), step=interval))
for (i, it) in
enumerate(range(start_time; length = length(columns), step = interval))
data[it] = @view data_read[1:length(rows), i]
end
end
Expand All @@ -481,7 +482,8 @@ function get_hdf_array(
data[start_time] = retransform_hdf_array(dataset[rows, columns.start, :], type)
else
data_read = retransform_hdf_array(dataset[rows, columns, :], type)
for (i, it) in enumerate(range(start_time; length=length(columns), step=interval))
for (i, it) in
enumerate(range(start_time; length = length(columns), step = interval))
data[it] = @view data_read[1:length(rows), i]
end
end
Expand All @@ -503,7 +505,8 @@ function get_hdf_array(
data[start_time] = retransform_hdf_array(dataset[rows, columns.start, :, :], type)
else
data_read = retransform_hdf_array(dataset[rows, columns, :, :], type)
for (i, it) in enumerate(range(start_time; length=length(columns), step=interval))
for (i, it) in
enumerate(range(start_time; length = length(columns), step = interval))
data[it] = @view data_read[1:length(rows), i]
end
end
Expand Down Expand Up @@ -622,7 +625,7 @@ function deserialize_time_series(
[3, 2, 1],
)
for (i, it) in enumerate(
range(start_time; length=length(columns), step=attributes["interval"]),
range(start_time; length = length(columns), step = attributes["interval"]),
)
data[it] = @view data_read[i, 1:length(rows), 1:total_percentiles]
end
Expand Down Expand Up @@ -661,7 +664,7 @@ function deserialize_time_series(
data_read =
PermutedDimsArray(path["data"][1:total_scenarios, rows, columns], [3, 2, 1])
for (i, it) in enumerate(
range(start_time; length=length(columns), step=attributes["interval"]),
range(start_time; length = length(columns), step = attributes["interval"]),
)
data[it] = @view data_read[i, 1:length(rows), 1:total_scenarios]
end
Expand Down Expand Up @@ -735,11 +738,11 @@ end
function _deserialize_compression_settings!(storage::Hdf5TimeSeriesStorage)
HDF5.h5open(storage.file_path, "r+") do file
root = _get_root(storage, file)
storage.compression = CompressionSettings(
enabled=HDF5.read(HDF5.attributes(root)["compression_enabled"]),
type=CompressionTypes(HDF5.read(HDF5.attributes(root)["compression_type"])),
level=HDF5.read(HDF5.attributes(root)["compression_level"]),
shuffle=HDF5.read(HDF5.attributes(root)["compression_shuffle"]),
storage.compression = CompressionSettings(;
enabled = HDF5.read(HDF5.attributes(root)["compression_enabled"]),
type = CompressionTypes(HDF5.read(HDF5.attributes(root)["compression_type"])),
level = HDF5.read(HDF5.attributes(root)["compression_level"]),
shuffle = HDF5.read(HDF5.attributes(root)["compression_shuffle"]),
)
return
end
Expand Down Expand Up @@ -768,10 +771,10 @@ is_read_only(storage::Hdf5TimeSeriesStorage) = storage.read_only
function compare_values(
x::Hdf5TimeSeriesStorage,
y::Hdf5TimeSeriesStorage;
compare_uuids=false,
compare_uuids = false,
)
item_x = sort!(collect(iterate_time_series(x)), by=z -> z[1])
item_y = sort!(collect(iterate_time_series(y)), by=z -> z[1])
item_x = sort!(collect(iterate_time_series(x)); by = z -> z[1])
item_y = sort!(collect(iterate_time_series(y)); by = z -> z[1])
if length(item_x) != length(item_y)
@error "lengths don't match" length(item_x) length(item_y)
return false
Expand Down
Loading

0 comments on commit deebdbc

Please sign in to comment.