From 18ff1972fb0dfcd576fd7c7c774e637943e7d956 Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Tue, 10 Sep 2024 10:50:21 -0400 Subject: [PATCH] Some minor refactring of code --- README.md | 2 +- .../DataFrame/Internals/DataFrame_slice.tcc | 166 +++++++----------- 2 files changed, 65 insertions(+), 103 deletions(-) diff --git a/README.md b/README.md index 6c093265..c9d72887 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. DataFrame Lion ## DataFrame documentation with code samples -This is a C++ analytical library designed for data analysis similar to libraries in Python and R. For example, you would compare this to [Pandas](https://pandas.pydata.org), [R data.frame](https://www.w3schools.com/r/r_data_frames.asp), or [Polars](https://www.pola.rs)
+This is a C++ analytical library designed for data analysis similar to libraries in Python and R. For example, you would compare this to [Pandas](https://pandas.pydata.org) or [R data.frame](https://www.w3schools.com/r/r_data_frames.asp)
You can slice the data in many different ways. You can join, merge, group-by the data. You can run various statistical, summarization, financial, and ML algorithms on the data. You can add your custom algorithms easily. You can multi-column sort, custom pick and delete the data. And more …
DataFrame also includes a large collection of analytical algorithms in form of visitors. These are from basic stats such as Mean, Std Deviation, Return, … to more involved analysis such as Affinity Propagation, Polynomial Fit, Fast Fourier transform of arbitrary length … including a good collection of trading indicators. You can also easily add your own algorithms.
DataFrame also employs extensive multithreading in almost all its API’s, for large datasets. That makes DataFrame especially suitable for analyzing large datasets.
diff --git a/include/DataFrame/Internals/DataFrame_slice.tcc b/include/DataFrame/Internals/DataFrame_slice.tcc index 3b30a8b5..06011733 100644 --- a/include/DataFrame/Internals/DataFrame_slice.tcc +++ b/include/DataFrame/Internals/DataFrame_slice.tcc @@ -2523,6 +2523,26 @@ get_view_at_times(DateTime::HourType hr, // ---------------------------------------------------------------------------- +// Benchmark time vs. Data time +// +inline static bool +_DT_before_times_(DateTime::HourType b_hr, + DateTime::MinuteType b_mn, + DateTime::SecondType b_sc, + DateTime::MillisecondType b_msc, + DateTime::HourType d_hr, + DateTime::MinuteType d_mn, + DateTime::SecondType d_sc, + DateTime::MillisecondType d_msc) { + + return ((d_hr < b_hr) || + (d_hr == b_hr && d_mn < b_mn) || + (d_mn == b_mn && d_sc < b_sc) || + (d_sc == b_sc && d_msc < b_msc)); +} + +// ---------------------------------------------------------------------------- + template template DataFrame> @@ -2541,24 +2561,11 @@ get_data_before_times(DateTime::HourType hr, col_indices.reserve(idx_s / 5); for (size_type i = 0; i < idx_s; ++i) { - if (indices_[i].hour() < hr) { + const auto &idx = indices_[i]; + + if (_DT_before_times_(hr, mn, sc, msc, + idx.hour(), idx.minute(), idx.sec(), idx.msec())) col_indices.push_back(i); - } - else if (indices_[i].hour() == hr) { - if (indices_[i].minute() < mn) { - col_indices.push_back(i); - } - else if (indices_[i].minute() == mn) { - if (indices_[i].sec() < sc) { - col_indices.push_back(i); - } - else if (indices_[i].sec() == sc) { - if (indices_[i].msec() < msc) { - col_indices.push_back(i); - } - } - } - } } return (data_by_sel_common_(col_indices, idx_s)); @@ -2583,24 +2590,11 @@ get_view_before_times(DateTime::HourType hr, col_indices.reserve(idx_s / 5); for (size_type i = 0; i < idx_s; ++i) { - if (indices_[i].hour() < hr) { + const auto &idx = indices_[i]; + + if (_DT_before_times_(hr, mn, sc, msc, + idx.hour(), idx.minute(), idx.sec(), idx.msec())) col_indices.push_back(i); - } - else if (indices_[i].hour() == hr) { - if (indices_[i].minute() < mn) { - col_indices.push_back(i); - } - else if (indices_[i].minute() == mn) { - if (indices_[i].sec() < sc) { - col_indices.push_back(i); - } - else if (indices_[i].sec() == sc) { - if (indices_[i].msec() < msc) { - col_indices.push_back(i); - } - } - } - } } return (view_by_sel_common_(col_indices, idx_s)); @@ -2625,24 +2619,11 @@ get_view_before_times(DateTime::HourType hr, col_indices.reserve(idx_s / 5); for (size_type i = 0; i < idx_s; ++i) { - if (indices_[i].hour() < hr) { + const auto &idx = indices_[i]; + + if (_DT_before_times_(hr, mn, sc, msc, + idx.hour(), idx.minute(), idx.sec(), idx.msec())) col_indices.push_back(i); - } - else if (indices_[i].hour() == hr) { - if (indices_[i].minute() < mn) { - col_indices.push_back(i); - } - else if (indices_[i].minute() == mn) { - if (indices_[i].sec() < sc) { - col_indices.push_back(i); - } - else if (indices_[i].sec() == sc) { - if (indices_[i].msec() < msc) { - col_indices.push_back(i); - } - } - } - } } return (view_by_sel_common_(col_indices, idx_s)); @@ -2650,6 +2631,26 @@ get_view_before_times(DateTime::HourType hr, // ---------------------------------------------------------------------------- +// Benchmark time vs. Data time +// +inline static bool +_DT_after_times_(DateTime::HourType b_hr, + DateTime::MinuteType b_mn, + DateTime::SecondType b_sc, + DateTime::MillisecondType b_msc, + DateTime::HourType d_hr, + DateTime::MinuteType d_mn, + DateTime::SecondType d_sc, + DateTime::MillisecondType d_msc) { + + return ((d_hr > b_hr) || + (d_hr == b_hr && d_mn > b_mn) || + (d_mn == b_mn && d_sc > b_sc) || + (d_sc == b_sc && d_msc > b_msc)); +} + +// ---------------------------------------------------------------------------- + template template DataFrame> @@ -2668,24 +2669,11 @@ get_data_after_times(DateTime::HourType hr, col_indices.reserve(idx_s / 5); for (size_type i = 0; i < idx_s; ++i) { - if (indices_[i].hour() > hr) { + const auto &idx = indices_[i]; + + if (_DT_after_times_(hr, mn, sc, msc, + idx.hour(), idx.minute(), idx.sec(), idx.msec())) col_indices.push_back(i); - } - else if (indices_[i].hour() == hr) { - if (indices_[i].minute() > mn) { - col_indices.push_back(i); - } - else if (indices_[i].minute() == mn) { - if (indices_[i].sec() > sc) { - col_indices.push_back(i); - } - else if (indices_[i].sec() == sc) { - if (indices_[i].msec() > msc) { - col_indices.push_back(i); - } - } - } - } } return (data_by_sel_common_(col_indices, idx_s)); @@ -2710,24 +2698,11 @@ get_view_after_times(DateTime::HourType hr, col_indices.reserve(idx_s / 5); for (size_type i = 0; i < idx_s; ++i) { - if (indices_[i].hour() > hr) { + const auto &idx = indices_[i]; + + if (_DT_after_times_(hr, mn, sc, msc, + idx.hour(), idx.minute(), idx.sec(), idx.msec())) col_indices.push_back(i); - } - else if (indices_[i].hour() == hr) { - if (indices_[i].minute() > mn) { - col_indices.push_back(i); - } - else if (indices_[i].minute() == mn) { - if (indices_[i].sec() > sc) { - col_indices.push_back(i); - } - else if (indices_[i].sec() == sc) { - if (indices_[i].msec() > msc) { - col_indices.push_back(i); - } - } - } - } } return (view_by_sel_common_(col_indices, idx_s)); @@ -2752,24 +2727,11 @@ get_view_after_times(DateTime::HourType hr, col_indices.reserve(idx_s / 5); for (size_type i = 0; i < idx_s; ++i) { - if (indices_[i].hour() > hr) { + const auto &idx = indices_[i]; + + if (_DT_after_times_(hr, mn, sc, msc, + idx.hour(), idx.minute(), idx.sec(), idx.msec())) col_indices.push_back(i); - } - else if (indices_[i].hour() == hr) { - if (indices_[i].minute() > mn) { - col_indices.push_back(i); - } - else if (indices_[i].minute() == mn) { - if (indices_[i].sec() > sc) { - col_indices.push_back(i); - } - else if (indices_[i].sec() == sc) { - if (indices_[i].msec() > msc) { - col_indices.push_back(i); - } - } - } - } } return (view_by_sel_common_(col_indices, idx_s));