Exemple #1
0
    def runTest(self):
        """Check for correct range and empty db."""
        stations = self.stations_multiple[:100]
        for station in stations:
            timestamp = RealTimeProcessing.getDateTimeFromTimeStampMS(
                station['last_update'])
            RealTimeProcessing.update_stations([station], timestamp)
        range2 = HistoricAnalysis.getBikesTimeRange()
        times = [HistoricAnalysis.floorTime(
            RealTimeProcessing.getDateTimeFromTimeStampMS(s["last_update"]),
            60).replace(tzinfo=datetime.timezone.utc)
                 for s in stations]
        range1 = (min(times), max(times))
        self.assertEqual(range1, range2)

        DublinBikesStationRealTimeUpdate.objects.all().delete()
        start, end = HistoricAnalysis.getBikesTimeRange()
        self.assertIsNone(start)
        self.assertIsNone(end)
Exemple #2
0
 def setUp(self):
     """Fill db with test data."""
     self.stations = json.load(open(os.path.join(
         os.path.dirname(os.path.abspath(__file__)),
         "test_data.json")))
     self.last_timestamp = max([
         RealTimeProcessing.getDateTimeFromTimeStampMS(s["last_update"])
         for s in self.stations])
     self.stations_multiple = json.load(open(os.path.join(
         os.path.dirname(os.path.abspath(__file__)),
         "test_data_multiple.json")))
Exemple #3
0
    def runTest(self):
        """Correctly check and not update values."""
        s1 = self.stations[0]
        timestamp = max(
            [RealTimeProcessing.getDateTimeFromTimeStampMS(
                station['last_update'])
                for station in self.stations])
        timestamp = HistoricAnalysis.floorTime(timestamp, 60)
        RealTimeProcessing.update_stations(self.stations[:10], timestamp)
        s1['status'] = 'Test'
        RealTimeProcessing.update_stations([s1], timestamp)
        dublin_static_object = DublinBikesStation.objects.get(
            station_number=s1["number"])
        s2 = DublinBikesStationRealTimeUpdate.objects.filter(
            parent_station=dublin_static_object,
            station_last_update=datetime.datetime.utcfromtimestamp
            (s1['last_update']/1000).replace(
                tzinfo=datetime.timezone.utc)).order_by('timestamp')[0]

        self.assertNotEqual(s2.status, 'Test')
Exemple #4
0
    def runTest(self):
        """Check for correct range and empty db."""
        stations = self.stations_multiple[:100]
        for station in stations:
            timestamp = RealTimeProcessing.getDateTimeFromTimeStampMS(
                station['last_update'])
            RealTimeProcessing.update_stations([station], timestamp)
        result = [datetime.datetime(2018, 2, 20, 15, 46) +
                  datetime.timedelta(minutes=i)
                  for i in range(11)]
        self.assertEqual(result, HistoricAnalysis.getBikesDistinctTimes())

        result = [datetime.datetime(2018, 2, 20, 15, 46) +
                  datetime.timedelta(minutes=i)
                  for i in range(0, 11, 2)]
        self.assertEqual(result, HistoricAnalysis.getBikesDistinctTimes(120))

        DublinBikesStationRealTimeUpdate.objects.all().delete()
        start, end = HistoricAnalysis.getBikesTimeRange()
        result = []
        self.assertEqual(result, HistoricAnalysis.getBikesDistinctTimes())