예제 #1
0
    def _WriteMappingsReport(self, mappings):
        pb = _m.PageBuilder(title="Node Renumbering Report")

        for tup in mappings.iteritems():
            pb.add_html("<p>%s: %s</p>" % tup)

        return pb.render()
예제 #2
0
 def _WriteErrorReport(self, errorTable):
     h = HTML()
     
     t = h.table()
     tr = t.tr()
     tr.th("Line ID")
     tr.th("Error Message")
     tr.th("Error Details")
     
     for lineId, errorMsg, errorDetail in errorTable:
         tr = t.tr()
         tr.td(lineId)
         tr.td(errorMsg)
         tr.td(str(errorDetail))
     
     pb = _m.PageBuilder(title= "Error Report")
     
     headerText = "<b>Source Emmebank:</b> %s" %self.SourceEmmebankPath +\
                 "<br><b>Source Scenario:</b> %s" %self.SourceScenarioId +\
                 "<br><b>Target Scenario:</b> %s" %self.TargetScenario
     
     pb.add_text_element(headerText)
     
     pb.wrap_html(body= str(t))
     
     _m.logbook_write("Error report", value= pb.render())
     
     pass
         
예제 #3
0
 def _WriteFailedSequencesReport(self, failedSequences):
     pb = _m.PageBuilder()
     idData = []
     branchData = []
     errorData = []
     seqData = []
     for x, item in enumerate(failedSequences):  #Not a map
         routeId, branchNum, error, seq = item
         idData.append((x, routeId))
         branchData.append((x, branchNum))
         errorData.append((x, error))
         seqData.append((x, seq))
     cds = [{
         'title': "Route ID",
         'data': idData
     }, {
         'title': "Branch #",
         'data': branchData
     }, {
         'title': "Error",
         'data': errorData
     }, {
         'title': "Stop Sequence",
         'data': seqData
     }]
     opt = {'table': True, 'graph': False}
     pb.add_chart_widget(cds,
                         options=opt,
                         title="Failed Sequences Table",
                         note="Stop sequence refers to GTFS stop ids.")
     return pb.render()
    def _Execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(
                classname=(self.__class__.__name__), version=self.version),
                              attributes=self._GetAtts()):

            if not self.Scenario.has_transit_results:
                raise Exception("Scenario %s has no transit results" %
                                self.Scenario)

            network = self.Scenario.get_network()
            stations, badNodes = self._LoadStationNodeFile(network)

            if len(badNodes) > 0:
                print "%s node IDs were not found in the network and were skipped." % len(
                    badNodes)
                pb = _m.PageBuilder("NodeIDs not in network")

                pb.add_text_element(
                    "<b>The following node IDs were not found in the network:</b>"
                )

                for id in badNodes:
                    pb.add_text_element(id)

                _m.logbook_write(
                    "Some IDs were not found in the network. Click for details.",
                    value=pb.render())

            nodeValues = self._CalcBoardingAlighting(network, stations)
            self._OutputResults(nodeValues)
예제 #5
0
 def _WriteReport(self, dataTuples):
     pb = _m.PageBuilder("Network Connectivity Report")
     
     for type, modes, fountains, sinks, orphans in dataTuples:
         self._AddReportSection(pb, type, modes, fountains, sinks, orphans)
     
     _m.logbook_write("Network connectivity report", value= pb.render())
예제 #6
0
 def _WriteReport(self, log):
     pb = _m.PageBuilder(title="Error log")
     
     doc = "<br>".join(log)
     pb.wrap_html(body=doc)
     
     _m.logbook_write("Error report", value=pb.render())
예제 #7
0
 def _WriteTableReport(self, groupings):
     pb = _m.PageBuilder()
     
     html = "<table><tr><th>Group<th>Code</tr>"
     for value, selector, description in groupings:
         html += "<tr><td>%s<td>%s</tr>" %(description, value)
     html += "</table>"
     
     pb.wrap_html(title="Grouping Table", body=html, note="Codes saved into transit line attribute %s" %self.AttributeId)
     
     _m.logbook_write("Value Table", value=pb.render())
예제 #8
0
    def _Execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(
                classname=(self.__class__.__name__), version=self.version),
                              attributes=self._GetAtts()):

            network = self.BaseScenario.get_network()
            self.TRACKER.completeTask()
            print("Loaded network")

            start = self._ParseIntTime(self.TimePeriodStart)
            end = self._ParseIntTime(self.TimePeriodEnd)

            badIdSet = self._LoadServiceTable(network, start, end).union(
                self._LoadAggTypeSelect(network))
            self.TRACKER.completeTask()
            print("Loaded service table")
            if len(badIdSet) > 0:
                print(
                    "%s transit line IDs were not found in the network and were skipped."
                    % len(badIdSet))
                pb = _m.PageBuilder("Transit line IDs not in network")

                pb.add_text_element(
                    "<b>The following line IDs were not found in the network:</b>"
                )

                for id in badIdSet:
                    pb.add_text_element(id)

                _m.logbook_write(
                    "Some IDs were not found in the network. Click for details.",
                    value=pb.render())

            if len(self.InputFiles) <= 0:
                self._ProcessTransitLines(network, start, end, None)
            else:
                if self.AlternativeDataFile:
                    altData = self._LoadAltFile(self.InputFiles)
                else:
                    altData = None
                self._ProcessTransitLines(network, start, end, altData)
                if altData:
                    self._ProcessAltLines(network, altData)
            print("Done processing transit lines")

            newScenario = _MODELLER.emmebank.copy_scenario(
                self.BaseScenario.id, self.NewScenarioNumber)
            newScenario.title = self.NewScenarioDescription

            print("Publishing network")
            network.delete_attribute('TRANSIT_LINE', 'trips')
            network.delete_attribute('TRANSIT_LINE', 'aggtype')
            newScenario.publish_network(network)
예제 #9
0
 def run_proc(self, name, arguments, log_message, capture_output=False):
     path = _join(self._path, "bin", name)
     if not os.path.exists(path):
         raise Exception("No command / batch file '%s'" % path)
     command = path + " " + " ".join([str(x) for x in arguments])
     attrs = {"command": command, "name": name, "arguments": arguments}
     with _m.logbook_trace(log_message, attributes=attrs):
         if capture_output and self._log_level != "NO_EXTERNAL_REPORTS":
             report = _m.PageBuilder(title="Process run %s" % name)
             report.add_html(
                 'Command:<br><br><div class="preformat">%s</div><br>' %
                 command)
             # temporary file to capture output error messages generated by Java
             err_file_ref, err_file_path = _tempfile.mkstemp(suffix='.log')
             err_file = os.fdopen(err_file_ref, "w")
             try:
                 output = _subprocess.check_output(command,
                                                   stderr=err_file,
                                                   cwd=self._path,
                                                   shell=True)
                 report.add_html(
                     'Output:<br><br><div class="preformat">%s</div>' %
                     output)
             except _subprocess.CalledProcessError as error:
                 report.add_html(
                     'Output:<br><br><div class="preformat">%s</div>' %
                     error.output)
                 raise
             finally:
                 err_file.close()
                 with open(err_file_path, 'r') as f:
                     error_msg = f.read()
                 os.remove(err_file_path)
                 if error_msg:
                     report.add_html(
                         'Error message(s):<br><br><div class="preformat">%s</div>'
                         % error_msg)
                 try:
                     # No raise on writing report error
                     # due to observed issue with runs generating reports which cause
                     # errors when logged
                     _m.logbook_write("Process run %s report" % name,
                                      report.render())
                 except Exception as error:
                     print _time.strftime("%Y-%M-%d %H:%m:%S")
                     print "Error writing report '%s' to logbook" % name
                     print error
                     print _traceback.format_exc(error)
                     if self._log_level == "DISABLE_ON_ERROR":
                         _m.logbook_level(_m.LogbookLevel.NONE)
         else:
             _subprocess.check_call(command, cwd=self._path, shell=True)
 def _WriteSkippedStopsReport(self, skippedStopIds):
     pb = _m.PageBuilder()
     stopData = []
     countData = []
     for x, item in enumerate(skippedStopIds.iteritems()):
         stop, count = item
         stopData.append((x, stop))
         countData.append((x, count))
     cds = [{'title': "Stop ID", 'data': stopData},
            {'title': "Count", 'data': countData}]
     opt = {'table': True, 'graph': False}
     pb.add_chart_widget(cds, options=opt, title="Skipped Stops Table", note="'Count' is the number of times skipped.")
     return pb.render()
 def _WriteLinesToCheckReport(self, linesToCheck):
     pb = _m.PageBuilder()
     idData = []
     checkData = []
     for x, item in enumerate(linesToCheck):
         id, reason = item
         idData.append((x, id))
         checkData.append((x, reason))
     cds = [{'title': "Line ID", 'data': idData},
            {'title': "Check Reason", 'data': checkData}]
     opt = {'table': True, 'graph': False}
     pb.add_chart_widget(cds, options=opt, title="Emme Lines to Check")
     return pb.render()
 def _WriteMainReport(self, reversedLines):
     h = HTML()
     t = h.table()
     tr = t.tr()
     tr.th('Original ID')
     tr.th('Reversed ID')
     
     for originalId, newId in  reversedLines:
         tr = t.tr()
         tr.td(originalId)
         tr.td(newId)
     
     pb = _m.PageBuilder(title= "Reversed Lines Report")
     pb.wrap_html(body= str(t))
     _m.logbook_write("Reversed lines report", value= pb.render())
예제 #13
0
    def _WriteErrorReport(self, linesMissingInNetwork):
        h = HTML()
        t = h.table()
        tr = t.tr()
        tr.th("Line ID")
        for id in linesMissingInNetwork:
            tr = t.tr()
            tr.td(str(id))

        pb = _m.PageBuilder(title="Lines not in network report")

        pb.wrap_html("Lines references in file but not in network",
                     body=str(t))

        _m.logbook_write("Error report", value=pb.render())
 def _WriteErrorReport(self, errorLines):
     h = HTML()
     t = h.table()
     tr = t.tr()
     tr.th('Line ID')
     tr.th('Error Type')
     tr.th('Error Message')
     
     for lineId, errorType, errorMsg in errorLines:
         tr = t.tr()
         tr.td(lineId)
         tr.td(errorType)
         tr.td(errorMsg)
     
     pb = _m.PageBuilder(title= "Error Report")
     pb.wrap_html(body= str(t))
     _m.logbook_write("Error report", value= pb.render())
예제 #15
0
    def _WriteLogbookReport(self, uncopiedConnectors):
        pb = _m.PageBuilder(title="Error Report", 
                            description="Lists connectors in the source scenario which could not be \
                                copied over to the target scenario.")
        
        html = """<table>
<tr>
    <th>Source I-Node (Zone)</th>
    <th>Source J-Node</th>
    <th>Error Message</th>
</tr>"""
        for connector, errMessage in uncopiedConnectors:
            tup = (connector.i_node, connector.j_node, errMessage)
            html += "<tr><td>%s</td><td>%s</td><td>%s</td></tr>" %tup
        html += "</table>"
        
        pb.wrap_html("", html, "")
        
        _m.logbook_write("Error report", value=pb.render())
    def _LoadPrintStopTimes(self, trips, stops2nodes):
        count = 0
        with nested(_util.CSVReader(self.GtfsFolder + "/stop_times.txt"),
                    open(self.GtfsFolder + "/stop_times_emme_nodes.txt", 'w'))\
                     as (reader, writer):

            s = reader.header[0]
            for i in range(1, len(reader.header)):
                s += "," + reader.header[i]
            writer.write(s)
            writer.write(",emme_node")

            self.TRACKER.startProcess(len(reader))
            for record in reader.readlines():
                try:
                    trip = trips[record['trip_id']]
                except KeyError:
                    continue
                index = int(record['stop_sequence'])
                stopId = record['stop_id']
                stopTime = StopTime(stopId, record['departure_time'],
                                    record['arrival_time'])
                trip.stopTimes.append((index, stopTime))

                if stopId in stops2nodes:
                    node = stops2nodes[stopId]
                else:
                    node = None
                writer.write("\n%s,%s" % (record, node))
                count += 1
                self.TRACKER.completeSubtask()
            self.TRACKER.completeTask()

        msg = "%s stop times loaded" % count
        print msg
        _m.logbook_write(msg)
        print "Stop times file updated with emme node mapping."
        pb = _m.PageBuilder(title="Link to updated stop times file")
        pb.add_link(self.GtfsFolder + "/stop_times_emme_nodes.txt")
        _m.logbook_write("Link to updated stop times file", value=pb.render())
    def _WriteReport(self, issues, errCount):

        print "Writing report to logbook"
        pb = _m.PageBuilder(
            title="Network Integrity Report for Scenario %s" %
            self.Scenario.number,
            description=
            "Tool found %s errors in the network for scenario %s. These \
                            errors are likely to cause infinite loops or division-by-zero errors \
                            when running road or transit assignments, so it is highly recommended \
                            that they are fixed before running any assignments."
            % (errCount, self.Scenario.number))

        doc = '''
        <table align="center">
            <tr>
                <th>Element Type</th>
                <th>ID</th>
                <th>Problem</th>
            </tr>
        '''

        self.TRACKER.startProcess(errCount)
        for type, id, list in issues:
            for problem in list:
                doc += '''
                <tr>
                    <td>{typ}</td>
                    <td>{id}</td>
                    <td>{prob}</td>
                </tr>
                '''.format(typ=type, id=id, prob=problem)
                self.TRACKER.completeSubtask()
        doc += '</table>'

        pb.wrap_html(body=doc)

        _m.logbook_write("%s problems found" % errCount, value=pb.render())
        print "Done."
예제 #18
0
 def _WriteReportToLogbook(self, 
                         unweightedAverage,
                         minVal,
                         maxVal,
                         unweightedStdDev,
                         unweightedMedian,
                         unweightedHistogram,
                         bins,
                         weightedAverage=None,
                         weightedStdDev=None,
                         weightedHistogram=None):
     
     #print "CURRENTLY DOES NOT WRITE REPORT TO LOGBOOK"
     #return
     
     pb = _m.PageBuilder(title="Matrix Summary Report")
     
     bodyText = "Summary for matrix: <b>{mtx1!s} - {desc1}</b> ({stamp1!s})\
     <br>Weighting Matrix: <b>{mtx2!s}".format(
                                               mtx1= self.ValueMatrix, 
                                               mtx2= self.WeightingMatrix,
                                               desc1= self.ValueMatrix.description, 
                                               stamp1= self.ValueMatrix.timestamp)
     if self.WeightingMatrix is not None: bodyText += " - %s" %self.WeightingMatrix.description
     bodyText += "</b><br>"
     
     rows = []
     rows.append("<b>Average:</b> %s" %unweightedAverage)
     rows.append("<b>Minimum:</b> %s" %minVal)
     rows.append("<b>Maximum:</b> %s" %maxVal)
     rows.append("<b>Standard Deviation:</b> %s" %unweightedStdDev)
     rows.append("<b>Median:</b> %s" %unweightedMedian)
     
     if weightedAverage is not None:
         rows.append("<br><br><b>Weighted Average:</b> %s" %weightedAverage)
         rows.append("<b>Weighted Standard Deviation:</b> %s" %weightedStdDev)
     
     bodyText += "<h3>Matrix Statistics</h3>" + "<br>".join(rows)
     pb.add_text_element(bodyText)
     
     #Build the chart data
     uwData = []
     wData = []
     for i, binEdge in enumerate(bins):
         if i == 0:
             prevEdge = binEdge
             continue #Skip the first
         
         if (i - 1) >= len(unweightedHistogram):
             uwVal = 0.0
         else:
             uwVal = unweightedHistogram[i - 1]
         uwData.append((int(prevEdge), float(uwVal)))
         
         if weightedHistogram is not None:
             if (i - 1) >= len(weightedHistogram):
                 wVal = 0.0
             else:
                 wVal = weightedHistogram[i - 1]
             wData.append((int(prevEdge), float(wVal)))
         
         prevEdge = binEdge
     
     cds = [{"title": "Unweighted frequency", 
             "data": uwData,
             "color": "red"}]
     if weightedHistogram is not None:
         cds.append({"title": "Weighted frequency",
                     "data": wData,
                     "color": "blue"})
     
     try:
         pb.add_chart_widget(chart_data_series=cds,
             options= {'table': True,
                       "plot_parameters": {
                            "series": {
                                "stack": False,
                                #"points": {"show": False},
                                #"lines": {"show": False},
                                "bars": {"show": True},
                                     }
                                 }
                       })
     except Exception as e:
         print cds
         raise
     
     _m.logbook_write("Matrix Summary Report for %s" %self.ValueMatrix,
                      value= pb.render())
예제 #19
0
                trip.stopTimes.append((index, stopTime))

                if stopId in stops2nodes:
                    node = stops2nodes[stopId]
                else:
                    node = None
                writer.write("\n%s,%s" % (record, node))
                count += 1
                self.TRACKER.completeSubtask()
            self.TRACKER.completeTask()

        msg = "%s stop times loaded" % count
        print msg
        _m.logbook_write(msg)
        print "Stop times file updated with emme node mapping."
        pb = _m.PageBuilder(title="Link to updated stop times file")
        pb.add_link(self.GtfsFolder + "/stop_times_emme_nodes.txt")
        _m.logbook_write("Link to updated stop times file", value=pb.render())

    def _GenerateLines(self, routes, stops2nodes, network, writer):
        #This is the main method
        linesToCheck = []
        failedSequences = []
        skippedStopIds = {}

        writer.write("emme_id,trip_depart,trip_arrive")

        # Setup the shortest-path algorithm
        if self.LinkPriorityAttributeId != None:

            def speed(link):