示例#1
0
    def toJsonFragment(self, suppressName):
        if getattr(self.bins[0][1], "quantity", None) is not None:
            binsName = self.bins[0][1].quantity.name
        elif getattr(self.bins[0][1], "quantityName", None) is not None:
            binsName = self.bins[0][1].quantityName
        else:
            binsName = None

        return maybeAdd(
            {
                "entries":
                floatToJson(self.entries),
                "bins:type":
                self.bins[0][1].name,
                "bins": [{
                    "center": floatToJson(c),
                    "data": v.toJsonFragment(True)
                } for c, v in self.bins],
                "nanflow:type":
                self.nanflow.name,
                "nanflow":
                self.nanflow.toJsonFragment(False),
            }, **{
                "name": None if suppressName else self.quantity.name,
                "bins:name": binsName
            })
示例#2
0
    def toJsonFragment(self, suppressName):
        if self.range == "N":
            aslist = sorted(x for x in self.values.items() if x[0] != "nan")
            if "nan" in self.values:
                aslist.append(("nan", self.values["nan"]))

        elif self.range[0] == "N":
            class Sorter(object):
                def __init__(self, x):
                    self.x = x

                def __lt__(self, other):
                    for xi, yi in zip(self.x, other.x):
                        if isinstance(xi, str) and isinstance(yi, float):
                            return False
                        elif isinstance(xi, float) and isinstance(yi, str):
                            return True
                        elif xi < yi:
                            return True
                        elif xi > yi:
                            return False
                    return False
            aslist = sorted((x for x in self.values.items()), key=lambda y: tuple(Sorter(z) for z in y))

        else:
            aslist = sorted(x for x in self.values.items())

        return maybeAdd({
            "entries": floatToJson(self.entries),
            "values": [{"w": floatToJson(n), "v": rangeToJson(v)} for v, n in aslist],
            "range": self.range,
        }, name=(None if suppressName else self.quantity.name))
示例#3
0
 def toJsonFragment(self, suppressName):
     return maybeAdd(
         {
             "entries": floatToJson(self.entries),
             "max": floatToJson(self.max)
         },
         name=(None if suppressName else self.quantity.name))
示例#4
0
    def toJsonFragment(self, suppressName):
        if isinstance(self.value, Container):
            if getattr(self.value, "quantity", None) is not None:
                binsName = self.value.quantity.name
            elif getattr(self.value, "quantityName", None) is not None:
                binsName = self.value.quantityName
            else:
                binsName = None
        elif len(self.bins) > 0:
            if getattr(list(self.bins.values())[0], "quantity",
                       None) is not None:
                binsName = list(self.bins.values())[0].quantity.name
            elif getattr(list(self.bins.values())[0], "quantityName",
                         None) is not None:
                binsName = list(self.bins.values())[0].quantityName
            else:
                binsName = None
        else:
            binsName = None

        if len(self.bins) > 0:
            bins_type = list(self.bins.values())[0].name
        elif self.value is not None:
            bins_type = self.value.name
        else:
            bins_type = self.contentType

        return maybeAdd(
            {
                "binWidth":
                floatToJson(self.binWidth),
                "entries":
                floatToJson(self.entries),
                "bins:type":
                bins_type,
                "bins":
                dict((str(i), v.toJsonFragment(True))
                     for i, v in self.bins.items()),
                "nanflow:type":
                self.nanflow.name,
                "nanflow":
                self.nanflow.toJsonFragment(False),
                "origin":
                self.origin,
            }, **{
                "name": None if suppressName else self.quantity.name,
                "bins:name": binsName
            })
示例#5
0
 def toJsonFragment(self, suppressName):
     return {
         "entries":
         floatToJson(self.entries),
         "sub:type":
         self.values[0].name,
         "data":
         dict((k, v.toJsonFragment(False)) for k, v in self.pairs.items())
     }
示例#6
0
 def toJsonFragment(self, suppressName):
     return {
         "entries":
         floatToJson(self.entries),
         "data": [{
             "type": x.name,
             "data": x.toJsonFragment(False)
         } for x in self.values]
     }
示例#7
0
 def toJsonFragment(self, suppressName):
     return {
         "entries":
         floatToJson(self.entries),
         "data":
         dict((k, {
             "type": v.name,
             "data": v.toJsonFragment(False)
         }) for k, v in self.pairs.items())
     }
示例#8
0
    def toJsonFragment(self, suppressName):
        if getattr(self.numerator, "quantity", None) is not None:
            binsName = self.numerator.quantity.name
        elif getattr(self.numerator, "quantityName", None) is not None:
            binsName = self.numerator.quantityName
        else:
            binsName = None

        return maybeAdd({
            "entries": floatToJson(self.entries),
            "sub:type": self.numerator.name,
            "numerator": self.numerator.toJsonFragment(True),
            "denominator": self.denominator.toJsonFragment(True),
        }, **{"name": None if suppressName else self.quantity.name,
              "sub:name": binsName})
    def toJsonFragment(self, suppressName):
        if isinstance(self.value, Container):
            if getattr(self.value, "quantity", None) is not None:
                binsName = self.value.quantity.name
            elif getattr(self.value, "quantityName", None) is not None:
                binsName = self.value.quantityName
            else:
                binsName = None
        elif len(self.bins) > 0:
            if getattr(list(self.bins.values())[0], "quantity",
                       None) is not None:
                binsName = list(self.bins.values())[0].quantity.name
            elif getattr(list(self.bins.values())[0], "quantityName",
                         None) is not None:
                binsName = list(self.bins.values())[0].quantityName
            else:
                binsName = None
        else:
            binsName = None

        if len(self.bins) > 0:
            bins_type = list(self.bins.values())[0].name
        elif self.value is not None:
            bins_type = self.value.name
        else:
            bins_type = self.contentType

        return maybeAdd(
            {
                # for json serialization all keys need to be strings, else json libs throws TypeError
                # e.g. boolean keys get converted to strings here
                "entries":
                floatToJson(self.entries),
                "bins:type":
                bins_type,
                "bins":
                dict((str(k), v.toJsonFragment(True))
                     for k, v in self.bins.items()),
            },
            **{
                "name": None if suppressName else self.quantity.name,
                "bins:name": binsName
            })
示例#10
0
 def toJsonFragment(self, suppressName):
     return {
         "entries": floatToJson(self.entries),
         "sub:type": self.values[0].name,
         "data": [x.toJsonFragment(False) for x in self.values]
     }
示例#11
0
 def toJsonFragment(self, suppressName):
     return floatToJson(self.entries)