Skip to content
Merged
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
20 changes: 17 additions & 3 deletions TM1py/Services/CellService.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import asyncio
import math
import csv
import functools
import itertools
Expand Down Expand Up @@ -62,6 +63,13 @@ def wrapper(self, cellset_id, *args, **kwargs):
return wrapper


def frame_to_significant_digits(x, digits=15):
if x == 0 or not math.isfinite(x):
return str(x).replace('e+', 'E')
digits -= math.ceil(math.log10(abs(x)))
return str(round(x, digits)).replace('e+', 'E')


def manage_transaction_log(func):
""" Control state of transaction log during and after write operation for a given cube through:
`deactivate_transaction_log` and `reactivate_transaction_log`.
Expand Down Expand Up @@ -847,7 +855,7 @@ def _build_attribute_update_statements(cube_name, cellset_as_dict, precision: in

@staticmethod
def _build_cell_update_statements(cube_name: str, cellset_as_dict: Dict, increment: bool,
measure_dimension_elements: Dict, precision: int, skip_non_updateable: bool):
measure_dimension_elements: Dict, skip_non_updateable: bool, precision: int=None):
statements = list()

for coordinates, value in cellset_as_dict.items():
Expand All @@ -874,13 +882,19 @@ def _build_cell_update_statements(cube_name: str, cellset_as_dict: Dict, increme
# number strings must not exceed float range
if isinstance(value, str):
try:
value_str = format(float(value), f'.{precision}f')
if precision:
value_str = format(float(value), f'.{precision}f')
else:
value_str = frame_to_significant_digits(float(value))
except ValueError:
value_str = f'{value}'
elif value is None:
value_str = '0'
else:
value_str = format(value, f'.{precision}f')
if precision:
value_str = format(float(value), f'.{precision}f')
else:
value_str = frame_to_significant_digits(float(value))

comma_separated_elements = ",".join("'" + element.replace("'", "''") + "'" for element in coordinates)

Expand Down