Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntervalValue does not accept integer or float #69

Closed
khoohuibo opened this issue Nov 19, 2020 · 2 comments
Closed

IntervalValue does not accept integer or float #69

khoohuibo opened this issue Nov 19, 2020 · 2 comments
Labels
needs-more-info Further information is requested

Comments

@khoohuibo
Copy link

I seem to be unable to insert values other than booleans into an IntervalValue, defined within types.py

I essentially run into this error upon hitting the following function:

    obj_dict.update(**self._value.to_json())

AttributeError: 'int' object has no attribute 'to_json'

And another exception occurs as well

    key = TYPE_MAPPING[type(self._value)]

KeyError: <class 'int'>

This is interesting because I am inserting a number '1' as the value, and json.dumps works on that number.

Now i noticed that TYPE_MAPPING is a dictionary defined at the top.

TYPE_MAPPING = {bool: "boolean"}

Obviously to circumvent the error, all one needs to do is insert the keys for int and/or float

Now my question is, is my integer and float type meant to fail? Does Cesium's interval values not accept intervalvalues of numbers apart from boolean values?

I am trying to create a time-varying width of polylines using the IntervalValues, considering that IntervalValues can accept BooleanValues. I would like to vary the width of the polylines between 1-5 dependent on another parameter in my simulation.

I am using Spyder 4.1.4, Python 3.7,7, My operating system is windows 10.

Here is the class in question

@attr.s(repr=False, frozen=True, kw_only=True)
class IntervalValue(BaseCZMLObject):
    """Value over some interval."""

    _start = attr.ib()
    _end = attr.ib()
    _value = attr.ib()

    def to_json(self):
        obj_dict = {"interval": TimeInterval(start=self._start, end=self._end)}

        try:
            obj_dict.update(**self._value.to_json())
        except AttributeError:
            key = TYPE_MAPPING[type(self._value)]
            obj_dict[key] = self._value

        return obj_dict
@astrojuanlu
Copy link
Member

Hi @khoohuibo , thanks for your interest in czml3! I guess you refer to this piece of code:

czml3/src/czml3/types.py

Lines 318 to 335 in d7f0b72

@attr.s(repr=False, frozen=True, kw_only=True)
class IntervalValue(BaseCZMLObject):
"""Value over some interval."""
_start = attr.ib()
_end = attr.ib()
_value = attr.ib()
def to_json(self):
obj_dict = {"interval": TimeInterval(start=self._start, end=self._end)}
try:
obj_dict.update(**self._value.to_json())
except AttributeError:
key = TYPE_MAPPING[type(self._value)]
obj_dict[key] = self._value
return obj_dict

And here are a couple of examples of how to use IntervalValue from the tests:

start = dt.datetime(2019, 1, 1, tzinfo=dt.timezone.utc)
end = dt.datetime(2019, 1, 2, tzinfo=dt.timezone.utc)
prop = IntervalValue(start=start, end=end, value=True)

clock=IntervalValue(
start=start, end=end, value=Clock(currentTime=start, multiplier=60)
),

Would you please paste here what code is producing the error you describe, so we can try to reproduce it? For my understanding everything is working as expected, but CZML documentation is sparse and it's also possible that I'm missing something.

@astrojuanlu astrojuanlu added the needs-more-info Further information is requested label Dec 11, 2020
@astrojuanlu
Copy link
Member

Closing because of inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-more-info Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants