Skip to content

Commit

Permalink
Some minor refactring of code
Browse files Browse the repository at this point in the history
  • Loading branch information
hosseinmoein committed Sep 10, 2024
1 parent 829817b commit 18ff197
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 103 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<img src="docs/LionLookingUp.jpg" alt="DataFrame Lion" width="400" longdesc="https://htmlpreview.github.io/?https://github.com/hosseinmoein/DataFrame/blob/master/docs/HTML/DataFrame.html"/>

## <a href="https://htmlpreview.github.io/?https://github.com/hosseinmoein/DataFrame/blob/master/docs/HTML/DataFrame.html" target="_blank"><B>DataFrame documentation with code samples</B></a>
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) <BR>
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)<BR>
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 …<BR>
DataFrame also includes a large collection of analytical algorithms in form of visitors. These are from basic stats such as <I>Mean</I>, <I>Std Deviation</I>, <I>Return</I>, … to more involved analysis such as <I>Affinity Propagation</I>, <I>Polynomial Fit</I>, <I>Fast Fourier transform of arbitrary length</I> … including a good collection of trading indicators. You can also easily add your own algorithms.<BR>
DataFrame also employs extensive multithreading in almost all its API’s, for large datasets. That makes DataFrame especially suitable for analyzing large datasets.<BR>
Expand Down
166 changes: 64 additions & 102 deletions include/DataFrame/Internals/DataFrame_slice.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename I, typename H>
template<typename ... Ts>
DataFrame<DateTime, HeteroVector<std::size_t(H::align_value)>>
Expand All @@ -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_<Ts ...>(col_indices, idx_s));
Expand All @@ -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_<Ts ...>(col_indices, idx_s));
Expand All @@ -2625,31 +2619,38 @@ 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_<Ts ...>(col_indices, idx_s));
}

// ----------------------------------------------------------------------------

// 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<typename I, typename H>
template<typename ... Ts>
DataFrame<DateTime, HeteroVector<std::size_t(H::align_value)>>
Expand All @@ -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_<Ts ...>(col_indices, idx_s));
Expand All @@ -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_<Ts ...>(col_indices, idx_s));
Expand All @@ -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_<Ts ...>(col_indices, idx_s));
Expand Down

0 comments on commit 18ff197

Please sign in to comment.