コード例 #1
0
class D3Sankey(widgets.DOMWidget):
    # the name of the requirejs module (no .js!)
    _view_module = traitlets.Unicode(
        'nbextensions/ipythond3sankey/js/widget_d3sankey',
        sync=True)

    # the name of the Backbone.View subclass to be used
    _view_name = traitlets.Unicode(
        'D3SankeyView',
        sync=True
    )

    # the name of the CSS file to load with this widget
    _view_style = traitlets.Unicode(
        'nbextensions/ipythond3sankey/css/widget_d3sankey',
        sync=True
    )

    # the actual value: lists of nodes and links
    nodes = traitlets.List(sync=True)
    links = traitlets.List(sync=True)

    # margins & size
    margin_top = traitlets.Float(1, sync=True)
    margin_right = traitlets.Float(1, sync=True)
    margin_bottom = traitlets.Float(6, sync=True)
    margin_left = traitlets.Float(1, sync=True)
    width = traitlets.Float(960, sync=True)
    height = traitlets.Float(500, sync=True)

    unit = traitlets.Unicode('', sync=True)
コード例 #2
0
class HeatmapWidget(W.DOMWidget):
    _view_name = T.Unicode('HeatmapView', sync=True)
    heatmap_data = T.List(sync=True)
    row_labels = T.List(sync=True)
    col_labels = T.List(sync=True)
    hcrow = T.List(sync=True)
    hccol = T.List(sync=True)
    minval = T.Float(sync=True)
    maxval = T.Float(sync=True)
    html_style = T.Unicode(sync=True)
コード例 #3
0
class TD2(documents.Document):
    xxx = documents.Reference(TestDocument)
    morex = traitlets.List(documents.Reference(TestDocument), db=True)
    emblist = traitlets.List(
            documents.EmbeddedReference(EmbDoc,TestDocument,'emb'), db=True
            )
    moreembslist = traitlets.List(
            documents.EmbeddedReference(EmbDoc,
                                        __name__+'.TestDocument','moreembs'),
             db=True)
コード例 #4
0
class Question(traits.HasTraits):

    name = traits.Unicode
    parts = traits.List
    solution = traits.Unicode
    answer = traits.Unicode
    submits_allowed = traits.Int
    lockout_time = traits.Int
    seed = traits.Int(0)
    text = traits.Unicode
    max_pts = traits.List([1])
    num_answers = traits.Int
    seed = traits.Int
    type = traits.Unicode

    @property
    def num_answers(self):
        return len(self.max_pts)

    def to_JSON(self, solution=False):
        data = {"type": self.type, "text": self.text, "max_pts": self.max_pts}
        if solution:
            data['solution'] = {"text": self.solution, "answer": self.answer}
        return data

    def _seed_changed(self):
        random.seed(self.seed)
        for part in self.parts:
            part.seed = self.seed

    def check(self, responses, student_id=None):
        """
        Check answers, returning a dict of scores and comments
        """
        return None
コード例 #5
0
class VariationDataProperties(JsonTraits):
    info_text = "Variation data properties"

    num_snps = Numeric(0, desc="Number of SNPs")
    num_individuals = Integer(0, desc="Number of individuals")
    snp_effect_annotation = tls.Unicode(
        "", desc="Flag for SNP annotation: yes or no")
    individual_names = tls.List(tls.Unicode)
コード例 #6
0
class Icon(InstallerMixin, widgets.DOMWidget):
    """
    A widget which can show one or more icons
    """
    icons = traitlets.List(sync=True)
    size = traitlets.Enum(Size, sync=True)
    context = traitlets.Enum(bs.Context, sync=True)

    _view_name = traitlets.Unicode('ipbs/IconView', sync=True)

    def __init__(self, *args, **kwargs):
        kwargs["icons"] = list(args) + kwargs.pop("icons", [])
        super(Icon, self).__init__(**kwargs)
コード例 #7
0
ファイル: report.py プロジェクト: caizikun/labcore
class Report(documents.Document):
    title = traitlets.Unicode()
    results = traitlets.List(documents.Reference(Result))
    date = traitlets.Instance(datetime.datetime)

    def __init__(self, *args, **kwargs):
        super(Report, self).__init__(*args, **kwargs)
        if self.date is None:
            self.date = datetime.datetime.now()

    def __html__(self):
        template = env.get_template('report_base.html')
        return template.render(report = self)

    def make_report(self, report_folder,openbrowser = True):
        save_html_report(self.__html__(), report_folder,
                         openbrowser=openbrowser)
コード例 #8
0
class MultiPartQuestion(Question):
    """
    Question with multiple parts (which are themselves questions)
    """

    active_parts = traits.List()
    list_type = traits.Unicode("a")

    def _parts_changed(self):
        self.active_parts = []
        self.max_pts = []
        for part in self.parts:
            part.seed = self.seed
            self.active_parts.append(part)
            self.max_pts.extend(part.max_pts)

    def to_JSON(self, solution=False):
        data = {
            "type": self.type,
            "text": self.text,
            "parts": [p.to_JSON(solution) for p in self.active_parts],
            "list_type": self.list_type
        }
        if solution: data['solution'] = {}
        return data

    def check(self, responses, student_id=None):
        scores = []
        comments = []
        end = 0
        for i, part in enumerate(self.active_parts):
            # extract responses corresponding to current part
            start = end
            end = start + part.num_answers
            resp = responses[start:end]
            # call the check method for that part
            out = part.check(resp)
            scores.extend(out['scores'])
            comments.extend(out['comments'])
            # write any changes to the answer back
            responses[start:end] = resp
        return {"scores": scores, "comments": comments}
コード例 #9
0
ファイル: models.py プロジェクト: caizikun/labcore
class AbstractInstrument(documents.Document):
    """This class holds the common methods of BaseInstrument and Instrument."""


    #id = models.AutoField(primary_key=True)
    name = t.Unicode(order = -1)
#    base_instrument = models.ForeignKey('BaseInstrument',
#                                        null = True, blank = True)
    base_instrument = documents.Reference(__name__+'.BaseInstrument',
                                          choose_from=_find_bases)
    #commands = generic.GenericRelation('Command')
    commands = t.List(documents.Reference(__name__+'.Command'))

    def __init__(self, *args, **kwargs):
        super(AbstractInstrument, self).__init__(*args, **kwargs)
        for command in self.commands:
            if command.instrument is None:
                command.instrument = self
            if command.instrument != self:
                raise InstrumentError("Command defined for another instrument.")

    @property
    def _command_names(self):
        return {command.name : command for command in self.commands}

    def add_command(self, command):
        """Sets the instrument of **command** to the instrument and saves
        it."""
        command.instrument = self
        self.commands = self.commands + [command,]

        self.save()
        command.save()

    def create_command(self, *args, **kwargs):
        """High level method for adding a command to an instrument.

        ***args** and ***kwawgs** are passed to the **Command** constructor."""
        c = Command(*args, **kwargs)
        self.add_command(c)

    def load_from_base(self):
        """Pulls the commands from the base of this instrument and saves
        them."""
        #print self
        #print self.base_instrument
        if self.base_instrument:
            #print "Adding commands"
            for command in self.base_instrument.commands:
                if not command.name in self._command_names:
                   newcommand = Command(
                            name = command.name,
                            command_string = command.command_string,
                            command_type = command.command_type,
                            instrument = self)
                   self.commands = self.commands + [command,]
                   newcommand.save()


    def command_form(self, **kwargs):
        wr =  Command.AddCommandWR(Command, instrument = self,
                                   default_values = kwargs)
        wr.create_object()


    def __unicode__(self):
        return self.name
    def __str__(self):
        return self.name
    class WidgetRepresentation(documents.Document.WidgetRepresentation):
        varname_map = 'name'
コード例 #10
0
class TestDocument(documents.Document):
    mstr = traitlets.Unicode(default_value = "axx", db= True)
    number = traitlets.Float(db=True)
    emb = traitlets.Instance(EmbDoc, db=True)
    moreembs = traitlets.List(traitlets.Instance(EmbDoc), db=True)
    lst = documents.TList(traitlets.Int)