Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Python_Engine/Python/src/python_toolkit/bhom/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import uuid
from functools import wraps
from typing import Any, Callable, Dict, List, Union
from datetime import datetime
from datetime import datetime, timezone

# pylint: enable=E0401

Expand Down Expand Up @@ -107,7 +107,7 @@ def summarise_usage_logs(usage_log_entries:List[UsageLogEntry]) -> List[Dict]:
return db_entries

def convert_exc_info_to_bhom_error(exc_info):
time = bson_unix_ticks(datetime.now(), short=True)
time = bson_unix_ticks(datetime.now(timezone.utc), short=True)
utcTime = bson_unix_ticks(short=True)
stack_trace = traceback.extract_tb(exc_info[2])
message = str(exc_info[1])
Expand Down
16 changes: 8 additions & 8 deletions Python_Engine/Python/src/python_toolkit/bhom/bhom_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,19 @@ def __init__(
self,
_t: str, #don't make default, as subclasses of this class should set this with super().__init__
name: str = "",
bhom_guid: uuid.UUID = uuid.uuid4(),
tags: List[str] = [],
fragments: List[Dict[str, object]] = [],
custom_data: Dict[str, object] = {},
bhom_guid: uuid.UUID = None,
tags: List[str] = None,
fragments: List[Dict[str, object]] = None,
custom_data: Dict[str, object] = None,
_bhom_version: str = None,
**kwargs
) -> 'BHoMObject':
self._t = _t
self.name = name
self.bhom_guid = bhom_guid
self.fragments = fragments
self.tags = tags
self.custom_data = custom_data
self.bhom_guid = bhom_guid or uuid.uuid4()
self.fragments = fragments or []
self.tags = tags or []
self.custom_data = custom_data or {}
self._bhom_version = _bhom_version

#set non-CustomData properties with reflection.
Expand Down
12 changes: 7 additions & 5 deletions Python_Engine/Python/src/python_toolkit/bhom/util.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
"""General utility functions."""
# pylint: disable=E0401
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
# pylint: enable=E0401


def bson_unix_ticks(date_time: datetime = datetime.utcnow(), short: bool = False) -> int:
def bson_unix_ticks(date_time: datetime = None, short: bool = False) -> int:
"""Python implementation of unix ticks.

Args:
date_time (datetime, optional): The datetime to convert to ticks. Defaults to datetime.utcnow().
date_time (datetime, optional): The datetime to convert to ticks. Defaults to datetime.now(timezone.utc).
short (bool, optional): Whether to return the short ticks. Defaults to False.

Returns:
int: The ticks.
"""

_ticks = (date_time - datetime(1970, 1, 1)).total_seconds() * 10**3
date_time = date_time or datetime.now(timezone.utc)

_ticks = (date_time - datetime(1970, 1, 1, tzinfo=timezone.utc)).total_seconds() * 10**3

if short:
return int(_ticks)
Expand All @@ -27,5 +29,5 @@ def bson_unix_ticks_to_datetime(ticks: int, short:bool = False) -> datetime:
if not short:
ticks = int(ticks / (10**3))

return datetime(1970, 1, 1) + timedelta(milliseconds=ticks)
return datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(milliseconds=ticks)

6 changes: 4 additions & 2 deletions Python_Engine/Python/src/python_toolkit/plot/cmap_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def cmap_sample_plot(
cmap: Union[str, Colormap],
bounds: Optional[tuple] = None,
figsize: tuple = (9, 1),
figsize: Optional[tuple] = None,
bins: int = 256
) -> Figure:

Expand All @@ -19,12 +19,14 @@ def cmap_sample_plot(
Args:
cmap: Either a colormap string (e.g., 'viridis') or a custom Colormap object
bounds: Optional tuple of (vmin, vmax) for normalization. If None, uses (0, 1)
figsize: Figure size as (width, height)
figsize: Figure size as (width, height). If None, defaults to (9, 1)
bins: Number of discrete bins for the gradient. Defaults to 256.
Returns:
Matplotlib Figure object
"""

figsize = figsize or (9, 1)

# Set bounds
if bounds is None:
bounds = (0, 1)
Expand Down
2 changes: 1 addition & 1 deletion Python_Engine/Python/src/python_toolkit/plot/diurnal.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def diurnal(
minor_ticks = target_idx
major_ticklabels = [f"{i:02d}:00" for i in major_ticks]
elif period == "weekly":
group = series.groupby([series.index.dayofweek, series.index.hour])
group = series.groupby([series.index.day_of_week, series.index.hour])
target_idx = pd.MultiIndex.from_product([range(7), range(24)])
major_ticks = range(len(target_idx))[::12]
minor_ticks = range(len(target_idx))[::3]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def set_dimensions(df: pd.DataFrame, tick_mark_count: int, dp:int) -> List[Dict[
@bhom_analytics()
def parallel_coordinate_plot(

df: pd.DataFrame = pd.DataFrame(),
df: pd.DataFrame,
variables_to_show: list = None,
decimal_places: int = 0,
tick_mark_count: int = 11,
Expand Down
Loading