Exemple #1
0
def valid_id(s):
    check_isinstance(s, str)

    if re.match(VALID_ID_REGEXP, s) is None:
        msg = "The given string %r does not match the spec %r." % (
            s, VALID_ID_REGEXP)
        raise ValueError(msg)
Exemple #2
0
 def section(self, nid=None, caption=None):
     """ Creates a subsection of the report. Returns a reference. """
     if nid is None:
         nid = self.get_first_available_name(prefix="section")
     else:
         check_isinstance(nid, str)
     node = self.node(nid)
     # TODO: unify treatment of caption
     if caption:
         node.text("caption", caption)
     return node
Exemple #3
0
    def text(self, nid: str, text: str, mime: MimeType = MIME_PLAIN):
        """
            Adds a text node with the given id.

            This is a very thin wrapper around data() that
            provides a default mime type (MIME_PLAIN).

            For now, only restructured text is converted to HTML,
            the rest is displayed as plain text.
        """
        check_isinstance(text, str)
        return self.data(nid=nid, data=text, mime=mime)
def write_report_single(report: Report,
                        report_nid,
                        report_html,
                        static_dir,
                        write_pickle=False):
    from quickapp.report_manager import write_report

    check_isinstance(report, Report)
    report.nid = report_nid
    write_report(report,
                 report_html,
                 static_dir=static_dir,
                 write_pickle=write_pickle)
Exemple #5
0
 def set_metric(
     self,
     name: Tuple[str, ...],
     total: Union[float, int],
     title: Optional[str] = None,
     description: Optional[str] = None,
     incremental: Optional[SampledSequence] = None,
     cumulative: Optional[SampledSequence] = None,
 ):
     check_isinstance(name, tuple)
     self.metrics[name] = EvaluatedMetric(
         total=total, incremental=incremental, title=title, description=description, cumulative=cumulative,
     )
Exemple #6
0
def htmlfy(s: str):
    check_isinstance(s, str)
    # XXX to write
    html_escape_table = {
        "&": "&",
        '"': """,
        "'": "'",
        ">": ">",
        "<": "&lt;",
    }

    def html_escape(text):
        """Produce entities within text."""
        return "".join(html_escape_table.get(c, c) for c in text)

    return html_escape(s)
Exemple #7
0
    def __getitem__(self, item: Union[str, FQN]) -> "PlacedObject":
        """

        Either url-like:

            child1/sub
            .

        or tuple like:

            ('child1', 'sub')
            ()

        :param item:
        :return:
        """
        if isinstance(item, str):
            item = fqn_from_url(item)
        check_isinstance(item, tuple)
        return self.get_object_from_fqn(item)
    def __init__(self, width: float, control_points: List[SE2Transform], *args,
                 **kwargs):
        # noinspection PyArgumentList
        PlacedObject.__init__(self, *args, **kwargs)
        self.width = float(width)
        assert len(control_points) >= 2, control_points
        self.control_points = control_points

        for p in control_points:
            check_isinstance(p, SE2Transform)

        for i in range(len(control_points) - 1):
            a = control_points[i]
            b = control_points[i + 1]
            ta, _ = geo.translation_angle_from_SE2(a.as_SE2())
            tb, _ = geo.translation_angle_from_SE2(b.as_SE2())
            d = np.linalg.norm(ta - tb)
            if d < 0.001:
                msg = "Two points are two close: \n%s\n%s" % (a, b)
                raise ValueError(msg)
Exemple #9
0
    def __init__(self, cc: Context, qapp, parent, job_prefix,
                 output_dir, extra_dep: List = None, resource_manager=None,
                 extra_report_keys=None,
                 report_manager=None):
        check_isinstance(cc, Context)
        check_isinstance(parent, (CompmakeContext, type(None)))
        if extra_dep is None:
            extra_dep = []
        self.cc = cc
        # can be removed once subtask() is removed
        self._qapp = qapp
        # only used for count invocation
        self._parent = parent
        self._job_prefix = job_prefix

        if resource_manager is None:
            resource_manager = ResourceManager(self)

        if report_manager is None:
            self.private_report_manager = True  # only create indexe if this is true
            reports = os.path.join(output_dir, 'report')
            reports_index = os.path.join(output_dir, 'report.html')
            report_manager = ReportManager(self, reports, reports_index)
        else:
            self.private_report_manager = False

        self._report_manager = report_manager
        self._resource_manager = resource_manager
        self._output_dir = output_dir
        self.n_comp_invocations = 0
        self._extra_dep = extra_dep
        self._jobs = {}
        if extra_report_keys is None:
            extra_report_keys = {}
        self.extra_report_keys = extra_report_keys

        self._promise = None

        self.branched_contexts = []
        self.branched_children = []
Exemple #10
0
def create_links_html(this_report, other_reports_same_type, index_filename,
                      most_similar_other_type):
    check_isinstance(other_reports_same_type, 'StoreResults')
    '''
    :param this_report: dictionary with the keys describing the report
    :param other_reports_same_type: StoreResults -> filename
    :returns: html string describing the link
    '''
    def rel_link(f):  # (this is FROM f0 to f) --- trust me, it's ok
        f0 = other_reports_same_type[this_report]
        rl = os.path.relpath(f, os.path.dirname(f0))
        return rl

    s = ""

    # create table by cols
    table = create_links_html_table(this_report, other_reports_same_type)

    s += "<p><a href='%s'>All report</a></p>" % rel_link(index_filename)

    s += "<table class='variations'>"
    s += "<thead><tr>"
    for field, _ in table:
        s += "<th>%s</th>" % field
    s += "</tr></thead>"

    s += "<tr>"

    add_invalid_links = True

    for field, variations in table:
        s += "<td>"

        MAX_VARIATIONS_EXPLICIT = 10

        # hide the n/a
        # variations = [v for v in variations if v[1] is not None]

        all_vars = dict(variations)
        sorted_variations = natsorted([v[0] for v in variations])
        # print('sorted: %s' % sorted_variations)
        variations = [(v, all_vars[v]) for v in sorted_variations]

        if len(variations) > MAX_VARIATIONS_EXPLICIT:
            id_select = 'select-%s' % (field)
            onchange = 'onchange_%s' % (field)
            s += "<select id='%s' onChange='%s()'>\n" % (id_select, onchange)

            for text, link in variations:
                if link is not None:
                    s += "<option value='%s'>%s</a> \n" % (link, text)
                else:
                    if add_invalid_links:
                        s += "<option value=''>%s</a> \n" % (text)
                s += '<br/>'

            s += '</select>\n'

            s += """         
<script>
    $(function(){
      // bind change event to select
      $('#%s').bind('change', function () {
          var url = $(this).val(); // get selected value
          if (url) { // require a URL
              window.location = url; // redirect
          }
          return false;
      });
    });
</script>
""" % id_select

        else:
            for text, link in variations:
                if link is not None:
                    s += "<a href='%s'> %s</a> " % (link, text)
                else:
                    if add_invalid_links:
                        s += "%s " % (text)
                s += '<br/>\n'

        s += "</td>"

    s += "</tr>"
    s += "</table>"

    #     s += '<dl>'
    #     for other_type, most_similar, filename in most_similar_other_type:
    #         s += '<dt><a href="%s">%s</a></dt><dd>%s</dd>' % (rel_link(filename),
    #                                                           other_type, most_similar)
    #     s += '</dl>'

    if most_similar_other_type:
        s += '<p>Other report: '
        for other_type, _, filename in most_similar_other_type:
            s += '<a href="%s">%s</a> ' % (rel_link(filename), other_type)
        s += '</p>'

    s = '<div style="margin-left: 1em;">' + s + '</div>'
    return s
Exemple #11
0
    def child(self, name:str, qapp=None,
              add_job_prefix=None,
              add_outdir=None,
              extra_dep: list=None,
              extra_report_keys=None,
              separate_resource_manager=False,
              separate_report_manager=False) -> "QuickAppContext":
        if extra_dep is None:
            extra_dep = []
        """
            Returns child context

            add_job_prefix =
                None (default) => use "name"
                 '' => do not add to the prefix

            add_outdir:
                None (default) => use "name"
                 '' => do not add outdir

            separate_resource_manager: If True, create a child of the ResourceManager,
            otherwise we just use the current one and its context.
        """
        check_isinstance(name, six.string_types)
        if qapp is None:
            qapp = self._qapp

        name_friendly = name.replace('-', '_')

        if add_job_prefix is None:
            add_job_prefix = name_friendly

        if add_outdir is None:
            add_outdir = name_friendly

        if add_job_prefix != '':
            if self._job_prefix is None:
                job_prefix = add_job_prefix
            else:
                job_prefix = self._job_prefix + '-' + add_job_prefix
        else:
            job_prefix = self._job_prefix

        if add_outdir != '':
            output_dir = os.path.join(self._output_dir, name)
        else:
            output_dir = self._output_dir

        if separate_report_manager:
            if add_outdir == '':
                msg = ('Asked for separate report manager, but without changing output dir. '
                       'This will make the report overwrite each other.')
                raise ValueError(msg)

            report_manager = None
        else:
            report_manager = self._report_manager

        if separate_resource_manager:
            resource_manager = None  # CompmakeContext will create its own
        else:
            resource_manager = self._resource_manager

        _extra_dep = self._extra_dep + extra_dep

        extra_report_keys_ = {}
        extra_report_keys_.update(self.extra_report_keys)
        if extra_report_keys is not None:
            extra_report_keys_.update(extra_report_keys)

        c1 = CompmakeContext(cc=self.cc,
                             qapp=qapp, parent=self,
                             job_prefix=job_prefix,
                             report_manager=report_manager,
                             resource_manager=resource_manager,
                             extra_report_keys=extra_report_keys_,
                             output_dir=output_dir,
                             extra_dep=_extra_dep)
        self.branched_children.append(c1)
        return c1
Exemple #12
0
def odometry_right(x: DynamicModel) -> float:
    check_isinstance(x, PlatformDynamics)
    return x.axis_right_obs_rad
Exemple #13
0
def odometry_left(x: DynamicModel) -> float:
    check_isinstance(x, DynamicModel)
    return x.axis_left_obs_rad
Exemple #14
0
def get_pose(x: PlatformDynamics) -> geo.SE2value:
    check_isinstance(x, PlatformDynamics)
    q, v = x.TSE2_from_state()
    return q
Exemple #15
0
def get_SE2transform(x: PlatformDynamics) -> SE2Transform:
    check_isinstance(x, PlatformDynamics)
    q, v = x.TSE2_from_state()
    return SE2Transform.from_SE2(q)