<commit_before>from __future__ import absolute_import, division, print_function

import time
import json
import os
import tempfile
import threading
from collections import defaultdict, namedtuple, Iterable
import numpy as np
from lcm import LCM
from robotlocomotion import viewer2_comms_t
from director.thirdparty import transformations


class ClientIDFactory(object):
    def __init__(self):
        self.pid = os.getpid()
        self.counter = 0

    def new_client_id(self):
        self.counter += 1
        return "py_{:d}_{:d}".format(self.pid, self.counter)


CLIENT_ID_FACTORY = ClientIDFactory()


def to_lcm(data):
    msg = viewer2_comms_t()
    msg.utime = data["utime"]
    msg.format = "treeviewer_json"
    msg.format_version_major = 1
    msg.format_version_minor = 0
    msg.data = json.dumps(data)
    msg.num_bytes = len(msg.data)
    return msg


def serialize_transform(tform):
    return {
        "translation": list(transformations.translation_from_matrix(tform)),
        "quaternion": list(transformations.quaternion_from_matrix(tform))
    }


class GeometryData(object):
    __slots__ = ["geometry", "color", "transform"]

    def __init__(self, geometry, color=(1., 1., 1., 1.), transform=np.eye(4)):
        self.geometry = geometry
        self.color = color
        self.transform = transform

    def serialize(self):
        params = self.geometry.serialize()
        params["color"] = list(self.color)
        params["transform"] = serialize_transform(self.transform)
        return params


class BaseGeometry(object):
    def serialize(self):
        raise NotImplementedError()


class Box(BaseGeometry, namedtuple("Box", ["lengths"])):
    def serialize(self):
        return {
            "type": "box",
            "lengths": list(self.lengths)
        }


class Sphere(BaseGeometry, namedtuple("Sphere", ["radius"])):
    def serialize(self):
        return {
            "type": "sphere",
            "radius": self.radius
        }


class Ellipsoid(BaseGeometry, namedtuple("Ellipsoid", ["radii"])):
    def serialize(self):
        return {
            "type": "ellipsoid",
            "radii": list(self.radii)
        }


class Cylinder(BaseGeometry, namedtuple("Cylinder", ["length", "radius"])):
    def serialize(self):
        return {
            "type": "cylinder",
            "length": self.length,
            "radius": self.radius
        }


class Triad(BaseGeometry):
    __slots__ = ["tube", "scale"]<commit_msg>change all viewerclient geometries from namedtuples to regular classes<commit_after>from __future__ import absolute_import, division, print_function

import time
import json
import os
import tempfile
import threading
from collections import defaultdict, Iterable
import numpy as np
from lcm import LCM
from robotlocomotion import viewer2_comms_t
from director.thirdparty import transformations


class ClientIDFactory(object):
    def __init__(self):
        self.pid = os.getpid()
        self.counter = 0

    def new_client_id(self):
        self.counter += 1
        return "py_{:d}_{:d}".format(self.pid, self.counter)


CLIENT_ID_FACTORY = ClientIDFactory()


def to_lcm(data):
    msg = viewer2_comms_t()
    msg.utime = data["utime"]
    msg.format = "treeviewer_json"
    msg.format_version_major = 1
    msg.format_version_minor = 0
    msg.data = json.dumps(data)
    msg.num_bytes = len(msg.data)
    return msg


def serialize_transform(tform):
    return {
        "translation": list(transformations.translation_from_matrix(tform)),
        "quaternion": list(transformations.quaternion_from_matrix(tform))
    }


class GeometryData(object):
    __slots__ = ["geometry", "color", "transform"]
    def __init__(self, geometry, color=(1., 1., 1., 1.), transform=np.eye(4)):
        self.geometry = geometry
        self.color = color
        self.transform = transform

    def serialize(self):
        params = self.geometry.serialize()
        params["color"] = list(self.color)
        params["transform"] = serialize_transform(self.transform)
        return params


class BaseGeometry(object):
    def serialize(self):
        raise NotImplementedError()


class Box(BaseGeometry):
    __slots__ = ["lengths"]
    def __init__(self, lengths=[1,1,1]):
        self.lengths = lengths

    def serialize(self):
        return {
            "type": "box",
            "lengths": list(self.lengths)
        }


class Sphere(BaseGeometry):
    __slots__ = ["radius"]
    def __init__(self, radius=1):
        self.radius = radius

    def serialize(self):
        return {
            "type": "sphere",
            "radius": self.radius
        }


class Ellipsoid(BaseGeometry):
    __slots__ = ["radii"]
    def __init__(self, radii=[1,1,1]):
        self.radii = radii

    def serialize(self):
        return {
            "type": "ellipsoid",
            "radii": list(self.radii)
        }


class Cylinder(BaseGeometry):
    __slots__ = ["length", "radius"]
    def __init__(self, length=1, radius=1):
        self.length = length
        self.radius = radius

    def serialize(self):
        return {
            "type": "cylinder",
            "length": self.length,
            "radius": self.radius
        }


class Triad(BaseGeometry):
    __slots__ = ["tube", "scale"]
{'fraction_non_alphanumeric': 0.11857332574464048, 'fraction_numerical': 0.005881236956934168, 'mean_word_length': 2.848175182481752, 'pattern_counts': {'":': 22, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7571162', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1583, 'n_words': 365}