Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tehcoderer committed Aug 7, 2023
1 parent 19e6b61 commit 7af58fc
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 78 deletions.
23 changes: 15 additions & 8 deletions frontend-components/tables/src/components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ export default function Table({
: columns[0];
const indexValue = indexLabel ? row[indexLabel] : null;
const value = row[column];
const only_numbers = value?.toString()?.split(".")?.pop()?.replace(/[^0-9]/g, "") ?? "";
const only_numbers =
value?.toString()?.split(".")?.[0]?.replace(/[^0-9]/g, "") ?? "";
const probablyDate =
only_numbers?.length >= 4 &&
(includesDateNames(column) ||
Expand All @@ -197,7 +198,11 @@ export default function Table({
indexValue.toLowerCase().includes("hour") ||
indexValue.toLowerCase().includes("minute"))));

if (probablyDate && isoYearRegex.test(value?.toString()))
if (
probablyDate &&
value?.length === 4 &&
isoYearRegex.test(value?.toString())
)
return value;

if (probablyDate) {
Expand All @@ -219,7 +224,8 @@ export default function Table({
const indexValue = indexLabel ? row.original[indexLabel] : null;
const value = row.original[column];
const valueType = typeof value;
const only_numbers = value?.toString()?.split(".")?.pop()?.replace(/[^0-9]/g, "") ?? "";
const only_numbers =
value?.toString()?.split(".")?.[0]?.replace(/[^0-9]/g, "") ?? "";
const probablyDate =
only_numbers?.length >= 4 &&
(includesDateNames(column) ||
Expand All @@ -246,14 +252,15 @@ export default function Table({
</a>
);
}
if (probablyDate && isoYearRegex.test(value?.toString())) {
return <p>{value}</p>;
}

if (
probablyDate &&
!isNaN(new Date(value).getTime()) &&
!isoYearRegex.test(value?.toString())
value?.length === 4 &&
isoYearRegex.test(value?.toString())
) {
return <p>{value}</p>;
}
if (probablyDate && !isNaN(new Date(value).getTime())) {
if (typeof value === "string") {
const date = value.split("T")[0];
const time = value.split("T")[1]?.split(".")[0];
Expand Down
3 changes: 2 additions & 1 deletion openbb_terminal/common/quantitative_analysis/qa_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def display_hist(

fig.update_layout(
xaxis_title="Value",
yaxis_title="Proportion",
margin=dict(r=40),
yaxis=dict(title="Proportion", title_standoff=40),
bargap=0.01,
bargroupgap=0,
)
Expand Down
61 changes: 35 additions & 26 deletions openbb_terminal/core/plots/plotly_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import sys
import textwrap
from datetime import datetime
from datetime import datetime, timedelta
from math import floor
from pathlib import Path
from typing import (
Expand Down Expand Up @@ -598,9 +598,9 @@ def _validate_x(data: Union[np.ndarray, pd.Series, type[TimeSeriesT]]):
colors = [None] * len(valid_x) # type: ignore

max_y = 0
for i, (x_i, name_i, color_i) in enumerate(zip(valid_x, name, colors)):
for i0, (x_i, name_i, color_i) in enumerate(zip(valid_x, name, colors)):
if not color_i:
color_i = theme.up_color if i % 2 == 0 else theme.down_color
color_i = theme.up_color if i0 % 2 == 0 else theme.down_color

res_mean, res_std = np.mean(x_i), np.std(x_i)
res_min, res_max = min(x_i), max(x_i)
Expand Down Expand Up @@ -639,13 +639,13 @@ def _validate_x(data: Union[np.ndarray, pd.Series, type[TimeSeriesT]]):
if show_rug:
self.add_scatter(
x=x_i,
y=[0.002] * len(x_i),
y=[0.00002] * len(x_i),
name=name_i if len(name) < 2 else name[1],
mode="markers",
marker=dict(
color=theme.down_color,
symbol="line-ns-open",
size=8,
size=10,
),
row=row,
col=col,
Expand Down Expand Up @@ -1340,6 +1340,7 @@ def hide_date_gaps(
return

# We get the missing days
is_daily = df_data.index[-1].time() == df_data.index[-2].time()
dt_days = pd.date_range(start=dt_start, end=dt_end, normalize=True)

# We get the dates that are missing
Expand All @@ -1351,17 +1352,22 @@ def hide_date_gaps(
if len(dt_missing_days) < 2_000:
rangebreaks = [dict(values=dt_missing_days)]

# We get the frequency of the data to hide intra-day gaps
if df_data.index[-1].time() != df_data.index[-2].time():
freq = df_data.index[1] - df_data.index[0]
freq_mins = int(freq.seconds / 60)
break_values = (
df_data.resample(f"{freq_mins}T")
.max()
.index.union(df_data.index)
.difference(df_data.index)
)
rangebreaks = [dict(values=break_values, dvalue=freq_mins * 60 * 1000)]
df_data = df_data.sort_index()
# We add a rangebreak if the first and second time are not the same
# since daily data will have the same time (00:00)
if not is_daily:
for i in range(len(df_data) - 1):
if df_data.index[i + 1] - df_data.index[i] > timedelta(hours=2):
rangebreaks.insert(
0,
dict(
bounds=[
df_data.index[i]
+ timedelta(minutes=60 - df_data.index[i].minute),
df_data.index[i + 1],
]
),
)

self.update_xaxes(rangebreaks=rangebreaks, row=row, col=col)

Expand All @@ -1372,16 +1378,19 @@ def add_rangebreaks(self) -> None:

for row, row_dict in self._subplot_xdates.items():
for col, values in row_dict.items():
x_values = (
pd.to_datetime(np.concatenate(values))
.to_pydatetime()
.astype("datetime64[ms]")
)
self.hide_date_gaps(
pd.DataFrame(index=x_values.tolist()),
row=row,
col=col,
)
try:
x_values = (
pd.to_datetime(np.concatenate(values))
.to_pydatetime()
.astype("datetime64[ms]")
)
self.hide_date_gaps(
pd.DataFrame(index=x_values.tolist()),
row=row,
col=col,
)
except ValueError:
continue

def to_subplot(
self,
Expand Down
Loading

0 comments on commit 7af58fc

Please sign in to comment.