def get_queryset(self):
        queryset = CalendarEvent.objects.filter()
        from_date = self.request.GET.get('from', False)
        to_date = self.request.GET.get('to', False)

        if from_date:
            queryset = queryset.filter(
                start__gte=timestamp_to_datetime(from_date)
            )
        if to_date:
            queryset = queryset.filter(
                end__lte=timestamp_to_datetime(to_date)
            )

        return event_serializer(queryset)
    def get_queryset(self):
        queryset = CalendarEvent.objects.filter()
        from_date = self.request.GET.get("from", False)
        to_date = self.request.GET.get("to", False)

        if from_date and to_date:
            queryset = queryset.filter(
                start__range=(
                    timestamp_to_datetime(from_date) + datetime.timedelta(-30),
                    timestamp_to_datetime(to_date),
                )
            )
        elif from_date:
            queryset = queryset.filter(start__gte=timestamp_to_datetime(from_date))
        elif to_date:
            queryset = queryset.filter(end__lte=timestamp_to_datetime(to_date))

        return event_serializer(queryset)
    def get_queryset(self):
        queryset = CalendarEvent.objects.filter()
        person = self.request.user
        from_date = self.request.GET.get('from', False)
        to_date = self.request.GET.get('to', False)

        year = timestamp_to_datetime(from_date).year
        month = timestamp_to_datetime(from_date).month

        if from_date and to_date and person:
            queryset = queryset.filter(
                start__range=(
                    timestamp_to_datetime(from_date) + datetime.timedelta(-30),
                    timestamp_to_datetime(to_date)
                    ),
                person=person
            )
        elif from_date:
            queryset = queryset.filter(
                start__gte=timestamp_to_datetime(from_date)
            )
        elif to_date:
            queryset = queryset.filter(
                end__lte=timestamp_to_datetime(to_date)
            )

        return event_serializer(queryset)
Beispiel #4
0
	def transform_timestamp(self):
		self.transformed_timestamp = utils.timestamp_to_datetime(self.record[indices.UNIX_TIMESTAMP_OF_REQUEST])
		return self.transformed_timestamp
Beispiel #5
0
 def format_ts(value, format='%a, %b %d %Y %H:%M:%S'):
     value = utils.timestamp_to_datetime(value)
     return time.strftime(format, value)
 def test_raise_timestamp_to_datetime(self):
     self.assertRaises(TypeError, timestamp_to_datetime(self.timestamp),
                       type(self.timestamp) != float(), self.now)
 def test_timestamp_to_datetime(self):
     self.assertEqual(self.now, timestamp_to_datetime(self.timestamp))
daily_expected = {
    'Water': {
        'val': 3.0,  # 3 quarts
        'high': 5.0,  # 1.8 times val
        'low': 1.5  # 0.8 times val
    }
}

name = input("Tracker name to show results for: ")
val_sum = 0
day_vals = {}
for i in events:
    try:
        if TRACKER_ID_TO_NAME[i['tracker_id']] == name:
            log_time = i['time']
            date = utils.timestamp_to_datetime(log_time, True)
            day_id = utils.day_to_id(date)
            val = float(i['value'])
            try:
                if val == 0:
                    day_vals[day_id] += 1
                else:
                    day_vals[day_id] += val
            except:
                if val == 0:
                    day_vals[day_id] = 1
                else:
                    day_vals[day_id] = val
    except KeyError:
        pass
Beispiel #9
0
def copy_and_format_names(origin, destination, selection=None):
    """
    Remove duplicate images.
    :param origin: str, path to original data.
    :param destination: str, directory to copy and format files.
    :param selection: array, coordinates to crop images
    """
    # From products with the same date-time keep only one.
    product_paths = []
    dates = set()
    for product in os.listdir(origin):
        info_file = os.path.join(origin, product, 'info.json')
        if os.path.exists(info_file) is False:
            continue
        info = json.load(open(info_file, 'r'))
        date = timestamp_to_datetime(info['Sensing start'])
        if date in dates:
            continue
        dates.add(date)
        product_paths.append(os.path.join(origin, product))

    os.makedirs(destination, exist_ok=True)
    for path in product_paths:
        info = json.load(open(os.path.join(path, 'info.json'), 'r'))
        if info['Satellite'] != 'Sentinel-2':
            continue
        date_str = 'product ' + '{:%Y-%m-%d %H:%M}'.format(
            timestamp_to_datetime(info['Sensing start']))
        tail = None
        for name in os.listdir(path):
            if name.startswith('tail.'):
                tail = os.path.join(path, name)
                break
        if tail is None:
            continue
        # useful bands
        bands = [
            Bands.RED, Bands.GREEN, Bands.BLUE, Bands.NIR, Bands.B05,
            Bands.B06, Bands.B07, Bands.B01, Bands.B11, Bands.B12, Bands.B10
        ]
        os.makedirs(os.path.join(destination, date_str), exist_ok=True)
        for band in bands:
            if selection is None:
                shutil.copy(
                    band_name(tail, band),
                    os.path.join(destination, date_str, band.value + '.tiff'))
            else:
                crop(selection, band_name(tail, band),
                     os.path.join(destination, date_str, band.value + '.tiff'))
        # create colored image
        save_color_image(os.path.join(destination, date_str),
                         Bands.RED,
                         Bands.GREEN,
                         Bands.BLUE,
                         output_file=os.path.join(destination, date_str,
                                                  Bands.TCI.value + '.tiff'))

        # copy info files
        shutil.copy(os.path.join(path, 'info.json'),
                    os.path.join(destination, date_str))
        shutil.copy(os.path.join(path, 'info.txt'),
                    os.path.join(destination, date_str))