Example #1
0
def generateData(tracks):
    trackway_number = tracks.iloc[0]["trackwayNumber"]
    metadata = {"key": "/trackway/tw_{}".format(trackway_number), "count": len(tracks)}

    df = tracks.sort_values(["number", "pes", "left"], ascending=[1, 0, 0])
    df = df.copy()
    df["number"] = df["number"].str.lstrip("0")

    fields = []
    for entry in CONVERSIONS:
        fields.append((get_key(entry.src), entry.label))

    csv = CsvWriter(path=FileUtils.makeFilePath(DATA_DIR, "BEB-500 S-{}.csv".format(trackway_number)), fields=fields)

    for index, track in df.iterrows():
        csv.addRow(create_export_entry(index, track, tracks))

    csv.save()
    df.to_hdf(OUT_PATH, key=metadata["key"], mode="a")

    return metadata
Example #2
0
 def _preAnalyze(self):
     self._csv = CsvWriter(
         path=self.getPath('Local_Rotations.csv'),
         autoIndexFieldName='index',
         fields=[
             ('uid', 'UID'),
             ('fingerprint', 'Fingerprint'),
             ('localRotation', 'Local Rotation'),
             ('measuredRotation', 'Measured Rotation'),
             ('difference', 'Difference'),
             ('deviation', 'Deviation')
         ]
     )
Example #3
0
class LocalRotationsStage(CurveOrderedAnalysisStage):
    """A class for..."""

    #___________________________________________________________________________
    def __init__(self, key, owner, **kwargs):
        """Creates a new instance of LocalRotationsStage."""
        super(LocalRotationsStage, self).__init__(
            key, owner, label='Local Rotation', **kwargs)

        self._csv = None


    #___________________________________________________________________________
    def _preAnalyze(self):
        self._csv = CsvWriter(
            path=self.getPath('Local_Rotations.csv'),
            autoIndexFieldName='index',
            fields=[
                ('uid', 'UID'),
                ('fingerprint', 'Fingerprint'),
                ('localRotation', 'Local Rotation'),
                ('measuredRotation', 'Measured Rotation'),
                ('difference', 'Difference'),
                ('deviation', 'Deviation')
            ]
        )

    #___________________________________________________________________________
    def _analyzeTrackSeries(self, series, trackway, sitemap):
        if len(series.tracks) < 2:
            return

        prev_track = series.tracks[0]
        for track in series.tracks[1:]:
            stride_line = LineSegment2D(
                start=prev_track.positionValue,
                end=track.positionValue)

            stride_angle = stride_line.angle
            abs_angle = Angle(degrees=prev_track.rotation)


            if not prev_track.left:
                local_angle = stride_angle.differenceBetween(abs_angle)
            else:
                local_angle = abs_angle.differenceBetween(stride_angle)

            has_field_measurements = not prev_track.hasImportFlag(
                ImportFlagsEnum.NO_FIELD_MEASUREMENTS
            )

            if has_field_measurements:
                measuredRotation = prev_track.rotationMeasured
                difference = round(abs(measuredRotation - local_angle.degrees))
                deviation = NumericUtils.roundToOrder(
                    value=difference/prev_track.rotationUncertainty,
                    orderOfMagnitude=-2)
            else:
                measuredRotation = ''
                difference = ''
                deviation = ''

            self._csv.createRow(
                uid=prev_track.uid,
                fingerprint=prev_track.fingerprint,
                difference=difference,
                deviation=deviation,
                localRotation=round(local_angle.degrees),
                measuredRotation=measuredRotation)
            prev_track = track

    #___________________________________________________________________________
    def _postAnalyze(self):
        self._csv.save()
        self._csv = None