Skip to content

Commit

Permalink
Update package with latest version of Bestie Template (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
datejada authored Oct 9, 2024
1 parent a52c198 commit 34bc370
Show file tree
Hide file tree
Showing 26 changed files with 155 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .JuliaFormatter.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ format_docstrings = false
format_markdown = false
import_to_using = true
indent = 2
margin = 100
margin = 92
normalize_line_endings = "unix"
remove_extra_newlines = true
separate_kwargs_with_semicolon = true
Expand Down
11 changes: 6 additions & 5 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Changes here will be overwritten by Copier
AnswerStrategy: recommended
AuthorEmail: [email protected]
AuthorName: Greg Neustroev
Indentation: 2
JuliaMinVersion: '1.6'
Authors: Greg Neustroev <[email protected]> and contributors
CodeOfConductContact: G.Neustroev@tudelft.nl
JuliaIndentation: 2
JuliaMinVersion: 1.10.5
License: Apache-2.0
LicenseCopyrightHolders: Greg Neustroev
PackageName: TulipaClustering
PackageOwner: TulipaEnergy
PackageUUID: 314fac8b-c762-4aa3-9d12-851379729163
_commit: v0.7.0
_commit: v0.12.0
_src_path: https://github.com/JuliaBesties/BestieTemplate.jl
10 changes: 9 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ root = true
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_size = 2
indent_style = space
trim_trailing_whitespace = true

[*.jl]
indent_size = 2

[*.md]
indent_size = 2

[*.{yml,toml,json}]
indent_size = 2
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/10-bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ body:
Please, before submitting, make sure that:
- There is not an [existing issue](https://github.com/TulipaEnergy/TulipaClustering.jl/issues) with the same question
- You have read the [contributing guide](https://TulipaEnergy.github.io/TulipaClustering.jl/dev/90-contributing/)
- You are following the [code of conduct](https://github.com/TulipaEnergy/TulipaClustering.jl/blob/main/CODE_OF_CONDUCT.md)
The form below should help you in filling out this issue.
- type: textarea
id: description
Expand Down
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/20-feature-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ body:
Please, before submitting, make sure that:
- There is not an [existing issue](https://github.com/TulipaEnergy/TulipaClustering.jl/issues) with the same question
- You have read the [contributing guide](https://TulipaEnergy.github.io/TulipaClustering.jl/dev/90-contributing/)
- You are following the [code of conduct](https://github.com/TulipaEnergy/TulipaClustering.jl/blob/main/CODE_OF_CONDUCT.md)
The form below should help you in filling out this issue.
- type: textarea
id: description
Expand Down
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/30-usage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ body:
- You have checked the [documentation](https://TulipaEnergy.github.io/TulipaClustering.jl) and haven't found enough information
- There is not an [existing issue](https://github.com/TulipaEnergy/TulipaClustering.jl/issues) with the same question
- You have read the [contributing guide](https://TulipaEnergy.github.io/TulipaClustering.jl/dev/90-contributing/)
- You are following the [code of conduct](https://github.com/TulipaEnergy/TulipaClustering.jl/blob/main/CODE_OF_CONDUCT.md)
The form below should help you in filling out this issue.
- type: textarea
id: description
Expand Down
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/99-general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ body:
Please, before submitting, make sure that:
- There is not an [existing issue](https://github.com/TulipaEnergy/TulipaClustering.jl/issues) with the same question
- You have read the [contributing guide](https://TulipaEnergy.github.io/TulipaClustering.jl/dev/90-contributing/)
- You are following the [code of conduct](https://github.com/TulipaEnergy/TulipaClustering.jl/blob/main/CODE_OF_CONDUCT.md)
The form below should help you in filling out this issue.
- type: textarea
id: description
Expand Down
6 changes: 5 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<!--
Thanks for making a pull request to TulipaClustering.jl.
We have added this PR template to help you help us.
Make sure to read the contributing guidelines and abide to the code of conduct.
Make sure to read the contributing guidelines and abide by the code of conduct.
See the comments below, fill the required fields, and check the items.
-->

Expand All @@ -21,7 +23,9 @@ There is no related issue.

<!-- mark true if NA -->
<!-- leave PR as draft until all is checked -->

- [ ] I am following the [contributing guidelines](https://github.com/TulipaEnergy/TulipaClustering.jl/blob/main/docs/src/90-contributing.md)

- [ ] Tests are passing
- [ ] Lint workflow is passing
- [ ] Docs were updated and workflow is passing
10 changes: 7 additions & 3 deletions .github/workflows/Docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,23 @@ jobs:
version: "1"
- name: Use Julia cache
uses: julia-actions/cache@v2
- run: |
- name: Instantiate environment with development version of the package
run: |
julia --project=docs -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()'
- run: |
- name: Run doctest
run: |
julia --project=docs -e '
using Documenter: DocMeta, doctest
using TulipaClustering
DocMeta.setdocmeta!(TulipaClustering, :DocTestSetup, :(using TulipaClustering); recursive=true)
doctest(TulipaClustering)'
- run: julia --project=docs docs/make.jl
- name: Generate and deploy documentation
run: julia --project=docs docs/make.jl
env:
JULIA_PKG_SERVER: ""
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
GKSwstype: "100" # https://discourse.julialang.org/t/generation-of-documentation-fails-qt-qpa-xcb-could-not-connect-to-display/60988
6 changes: 6 additions & 0 deletions .github/workflows/Lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ jobs:
uses: julia-actions/cache@v2
- name: Install JuliaFormatter.jl
run: julia -e 'using Pkg; pkg"add JuliaFormatter"'
- name: Hack for setup-python cache # https://github.com/actions/setup-python/issues/807
run: touch requirements.txt
- name: Setup Python
uses: actions/setup-python@v5
with:
cache: "pip"
python-version: "3.11"
- name: Hack for setup-python cache # https://github.com/actions/setup-python/issues/807
run: rm requirements.txt
- name: Cache pre-commit
uses: actions/cache@v4
with:
Expand All @@ -53,3 +58,4 @@ jobs:
uses: lycheeverse/lychee-action@v1
with:
fail: true
args: --config '.lychee.toml' .
5 changes: 5 additions & 0 deletions .github/workflows/PreCommitUpdate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Hack for setup-python cache # https://github.com/actions/setup-python/issues/807
run: touch requirements.txt
- name: Setup Python
uses: actions/setup-python@v5
with:
cache: pip
python-version: "3.11"
- name: Hack for setup-python cache # https://github.com/actions/setup-python/issues/807
run: rm requirements.txt
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit's autoupdate
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
branches:
- main
tags: ["*"]

workflow_dispatch:

jobs:
Expand All @@ -23,7 +22,7 @@ jobs:
fail-fast: false
matrix:
version:
- "1.6"
- "1.10.5"
- "1"
os:
- ubuntu-latest
Expand Down
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
*.jl.*.cov
*.jl.cov
*.jl.mem
*.rej
.DS_Store
.benchmarkci
Manifest.toml
benchmark/*.json
coverage
docs/build/
env
/.benchmarkci
/benchmark/*.json
coverage/
*.rej
node_modules
.DS_Store
debugging
.vscode
node_modules
File renamed without changes.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ repos:
hooks:
- id: yamllint
- repo: https://github.com/domluna/JuliaFormatter.jl
rev: v1.0.61
rev: v1.0.60
hooks:
- id: julia-formatter
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ representative at an online or offline event.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
reported to the community leaders responsible for enforcement:
`[email protected]`.
All complaints will be reviewed and investigated promptly and fairly.

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
[![DOI](https://zenodo.org/badge/712902842.svg)](https://zenodo.org/doi/10.5281/zenodo.10419235)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
[![All Contributors](https://img.shields.io/github/all-contributors/TulipaEnergy/TulipaClustering.jl?labelColor=5e1ec7&color=c0ffee&style=flat-square)](#contributors)
[![BestieTemplate](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/JuliaBesties/BestieTemplate.jl/main/docs/src/assets/badge.json)](https://github.com/JuliaBesties/BestieTemplate.jl)

## How to Cite

Expand Down
33 changes: 12 additions & 21 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
using TulipaClustering
using Documenter

DocMeta.setdocmeta!(TulipaClustering, :DocTestSetup, :(using TulipaClustering); recursive = true)
DocMeta.setdocmeta!(
TulipaClustering,
:DocTestSetup,
:(using TulipaClustering);
recursive = true,
)

const page_rename = Dict("developer.md" => "Developer docs") # Without the numbers

function nice_name(file)
file = replace(file, r"^[0-9]*-" => "")
if haskey(page_rename, file)
return page_rename[file]
end
return splitext(file)[1] |> x -> replace(x, "-" => " ") |> titlecase
end
const numbered_pages = [
file for file in readdir(joinpath(@__DIR__, "src")) if
file != "index.md" && splitext(file)[2] == ".md"
]

makedocs(;
modules = [TulipaClustering],
doctest = true,
linkcheck = false, # Rely on Lint.yml/lychee for the links
authors = "Greg Neustroev <[email protected]> and contributors",
repo = "https://github.com/TulipaEnergy/TulipaClustering.jl/blob/{commit}{path}#{line}",
sitename = "TulipaClustering.jl",
format = Documenter.HTML(;
prettyurls = true,
canonical = "https://TulipaEnergy.github.io/TulipaClustering.jl",
assets = ["assets/style.css"],
),
pages = [
"Home" => "index.md"
[
nice_name(file) => file for
file in readdir(joinpath(@__DIR__, "src")) if file != "index.md" && splitext(file)[2] == ".md"
]
],
pages = ["index.md"; numbered_pages],
)

deploydocs(; repo = "github.com/TulipaEnergy/TulipaClustering.jl", push_preview = true)
deploydocs(; repo = "github.com/TulipaEnergy/TulipaClustering.jl")
21 changes: 17 additions & 4 deletions src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ julia> TulipaClustering.split_into_periods!(df)
3 │ 1 3 3
```
"""
function split_into_periods!(df::AbstractDataFrame; period_duration::Union{Int, Nothing} = nothing)
function split_into_periods!(
df::AbstractDataFrame;
period_duration::Union{Int, Nothing} = nothing,
)
# If the periods already exist, combine them into the time steps if necessary
combine_periods!(df)

Expand Down Expand Up @@ -197,9 +200,15 @@ function find_auxiliary_data(clustering_data::AbstractDataFrame)
key_columns = validate_df_and_find_key_columns(clustering_data)
n_periods = maximum(clustering_data.period)
period_duration = maximum(clustering_data.timestep)
last_period_duration = maximum(clustering_data[clustering_data.period .== n_periods, :timestep])
last_period_duration =
maximum(clustering_data[clustering_data.period .== n_periods, :timestep])

return AuxiliaryClusteringData(key_columns, period_duration, last_period_duration, n_periods)
return AuxiliaryClusteringData(
key_columns,
period_duration,
last_period_duration,
n_periods,
)
end

"""
Expand Down Expand Up @@ -409,7 +418,11 @@ function find_representative_periods(
# Check that the number of RPs makes sense. The first check can be done immediately,
# The second check is done after we compute the auxiliary data
if n_rp < 1
throw(ArgumentError("The number of representative periods is $n_rp but has to be at least 1."))
throw(
ArgumentError(
"The number of representative periods is $n_rp but has to be at least 1.",
),
)
end

# Find auxiliary data and pre-compute additional constants that are used multiple times alter
Expand Down
10 changes: 8 additions & 2 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Converts a weight matrix from a (sparse) matrix, which is more convenient for
internal computations, to a dataframe, which is better for saving into a file.
Zero weights are dropped to avoid cluttering the dataframe.
"""
function weight_matrix_to_df(weights::Union{SparseMatrixCSC{Float64, Int64}, Matrix{Float64}})
function weight_matrix_to_df(
weights::Union{SparseMatrixCSC{Float64, Int64}, Matrix{Float64}},
)
weights = sparse(weights)
periods, rep_periods, values = weights |> findnz
result = DataFrame(; period = periods, rep_period = rep_periods, weight = values)
Expand Down Expand Up @@ -39,7 +41,11 @@ function write_clustering_result_to_tables(
period_duration[end] = aux.last_period_duration
DuckDB.register_data_frame(
connection,
DataFrame(; rep_period = 1:num_rep_periods, num_timesteps = period_duration, resolution = 1.0),
DataFrame(;
rep_period = 1:num_rep_periods,
num_timesteps = period_duration,
resolution = 1.0,
),
"rep_periods_data",
)
return nothing
Expand Down
15 changes: 13 additions & 2 deletions src/structures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ mutable struct AuxiliaryClusteringData
last_period_duration::Int
n_periods::Int

function AuxiliaryClusteringData(key_columns, period_duration, last_period_duration, n_periods)
function AuxiliaryClusteringData(
key_columns,
period_duration,
last_period_duration,
n_periods,
)
return new(key_columns, period_duration, last_period_duration, n_periods)
end
end
Expand All @@ -23,7 +28,13 @@ mutable struct ClusteringResult
rp_matrix::Union{Matrix{Float64}, Nothing}
auxiliary_data::Union{AuxiliaryClusteringData, Nothing}

function ClusteringResult(profiles, weight_matrix, clustering_matrix, rp_matrix, auxiliary_data)
function ClusteringResult(
profiles,
weight_matrix,
clustering_matrix,
rp_matrix,
auxiliary_data,
)
return new(profiles, weight_matrix, clustering_matrix, rp_matrix, auxiliary_data)
end

Expand Down
Loading

0 comments on commit 34bc370

Please sign in to comment.