Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
fe3857a
add feature to read multiple files at once
RiteshKarki27 Dec 14, 2025
255f605
add implementation for new hook create chronics
RiteshKarki27 Dec 23, 2025
4cda1c4
fix issue with faulty bzip2 check in deps.sh
RiteshKarki27 Dec 31, 2025
a07f059
fix issue with faulty bzip2 check in deps.sh
RiteshKarki27 Dec 31, 2025
32cb936
fix (hook-create-chronics) include integration test for hook create-c…
RiteshKarki27 Jan 4, 2026
d0a9c1c
fix (hook-create-chronics): Fix filename mismatch to avoid integratio…
RiteshKarki27 Jan 4, 2026
9db5ec1
fix (hook-create-chronics: fix build issue with nix due to missing bzip2
RiteshKarki27 Jan 11, 2026
a0143ab
fix (hook-create-chronics: fix build issue with nix due to missing nl…
RiteshKarki27 Jan 11, 2026
0e6bebe
fix (hook-create-chronics): Fix cpp file format for CI pre-commit tests
RiteshKarki27 Jan 12, 2026
e1e09bf
fix (hook-create-chronics): Add configuration example for create_chro…
RiteshKarki27 Jan 12, 2026
ec10447
fix (hook-create-chronics): Fix build issue with fedora-minimal
RiteshKarki27 Jan 12, 2026
fa417e6
fix (hook-create-chronics): Add missing copyright and licensing infor…
RiteshKarki27 Jan 12, 2026
6180701
fix (hook-create-chronics): Fix build issue with fedora-minimal, add …
RiteshKarki27 Jan 12, 2026
2ebb53e
fix (hook-create-chronics): Remove redundant code from earlier implem…
RiteshKarki27 Mar 15, 2026
262d288
fix (hook-create-chronics): Improve example configuration file for cr…
RiteshKarki27 Mar 15, 2026
6760680
Merge branch 'master' into hook-timeseries-chronix-conversion
al3xa23 Mar 18, 2026
1569448
fix(hook-timeseries-chronix-conversion): build pipeline
al3xa23 Mar 19, 2026
e256839
Update tests/integration/hook-create_chronics.sh
RiteshKarki27 Mar 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pkg_check_modules(CGRAPH IMPORTED_TARGET libcgraph>=2.30)
pkg_check_modules(GVC IMPORTED_TARGET libgvc>=2.30)
pkg_check_modules(LIBUSB IMPORTED_TARGET libusb-1.0>=1.0.23)
pkg_check_modules(NANOMSG IMPORTED_TARGET nanomsg)
pkg_check_modules(BZIP2 IMPORTED_TARGET bzip2)

if(NOT NANOMSG_FOUND)
pkg_check_modules(NANOMSG IMPORTED_TARGET libnanomsg>=1.0.0)
endif()
Expand Down
39 changes: 39 additions & 0 deletions etc/examples/hooks/create_chronics.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# SPDX-FileCopyrightText: 2014-2026 Institute for Automation of Complex Power Systems, RWTH Aachen University
# SPDX-License-Identifier: Apache-2.0

nodes = {

file_node = {
type = "file"
format = {
type = "csv"
separator = ","
delimiter = "\n"
skip_first_line = false
header = true
}
uris = ("./Load1.csv", "./SGen1.csv")
uri = "test_uri"
in = {
read_mode = "all"
}

hooks = (
{
type = "create_chronics"
loads_dir = "./"
sgens_dir = "./"
grid = "./grid_file.json"
output = "./test_output"
round_decimals = 3
compress = true
}
)
}
}

paths = (
{
in = "file_node",
}
)
77 changes: 77 additions & 0 deletions include/villas/hooks/create_chronics.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* Create Chronics hook.
*
* Author: Ritesh Karki <ritesh.karki@rwth-aachen.de>
* SPDX-FileCopyrightText: 2014-2025 Institute for Automation of Complex Power Systems, RWTH Aachen University
* SPDX-License-Identifier: Apache-2.0
*/

#include <filesystem>
#include <unordered_map>
#include <vector>

#include <nlohmann/json.hpp>

#include <villas/hook.hpp>
#include <villas/sample.hpp>

namespace villas {
namespace node {

struct GridMapping {
std::unordered_map<int, int> load_bus;
std::unordered_map<int, int> sgen_bus;
};

struct ChronicsOptions {
std::filesystem::path loads_dir;
std::filesystem::path sgens_dir;
std::filesystem::path grid_path;
std::filesystem::path output_dir;
int round_decimals = 3;
bool compress = true;
bool negate_sgens = true;
float voltage = 20.0;

static ChronicsOptions from_json(const json_t &cfg);
};

class ChronicsHook : public Hook {

public:
using Hook::Hook;

void run();
void flush();
GridMapping load_grid();
void discover_files();
void process_load_files();
void process_sgen_files();
void process_samples_from_file(const std::string &filename,
const std::vector<Sample *> &samples);
void round_values();
void write_outputs();
void discover_files_from_node(struct file *f);

void prepare() override;
void start() override;
void stop() override;

private:
ChronicsOptions options;
GridMapping mapping;
std::vector<std::filesystem::path> load_files;
std::vector<std::filesystem::path> sgen_files;
std::vector<std::vector<double>> load_p_columns;
std::vector<std::vector<double>> load_q_columns;
std::vector<std::vector<double>> prod_p_columns;
std::vector<std::vector<double>> prod_q_columns;
std::vector<std::vector<double>> prod_v_columns;
std::vector<std::string> column_names;
std::string load_col_names;
std::string sgen_col_names;
bool done;
unsigned sgen_idx;
};

} // namespace node
} // namespace villas
22 changes: 22 additions & 0 deletions include/villas/nodes/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

#pragma once

#include <cstddef>
#include <cstdio>
#include <map>
#include <string>
#include <vector>

#include <villas/format.hpp>
#include <villas/task.hpp>
Expand Down Expand Up @@ -57,6 +61,24 @@ struct file {
struct timespec epoch; // The epoch timestamp from the configuration.
struct timespec
offset; // An offset between the timestamp in the input file and the current time

std::vector<Sample *> samples;
size_t read_pos;

enum class ReadMode { RATE_BASED, READ_ALL } read_mode;
bool read;

// For multi-file support
std::vector<std::string> uri_templates;
std::vector<std::string> uris;

std::map<std::string, std::vector<Sample *>>
file_samples; // Map: filename --> filesamples
std::map<std::string, size_t>
file_read_pos; // Map: filename --> current read position in file
bool multi_file_mode;
size_t
total_files_size; //To calculate the total number of lines to be read across multiple files
};

char *file_print(NodeCompat *n);
Expand Down
2 changes: 2 additions & 0 deletions lib/hooks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(HOOK_SRC
skip_first.cpp
stats.cpp
ts.cpp
create_chronics.cpp
)

if(WITH_LUA)
Expand All @@ -49,3 +50,4 @@ endif()
add_library(hooks STATIC ${HOOK_SRC})
target_include_directories(hooks PUBLIC ${INCLUDE_DIRS})
target_link_libraries(hooks PUBLIC ${LIBRARIES})
target_link_libraries(hooks PUBLIC ${BZIP2_LIBRARIES})
Loading
Loading