def _make_search(start, end, dataframe): '''Return part of the dataframe''' end = end or now() start = start or 0 validate_timestamp(start, end) start = iso_format_validation(start) end = iso_format_validation(end) iso = '%Y-%m-%dT%H:%M:%SZ' search = dataframe.Timestamp.dt.strftime(iso) search = search.between(start, end) return search
def get(self, namespace, start=None, end=None, method=None, fill=None, group=None): """Make a query to retrieve something in the database.""" if _validate_namespace(namespace): namespace, field = _extract_field(namespace) if not self._namespace_exists(namespace): error = (f'Error to get values because namespace \'{namespace}\'' 'does not exist.') raise NamespaceError(error) if start is None and end is None: error = 'Start and end value should not be \'None\'.' raise ValueError(error) if iso_format_validation(start) is False and start is not None: start = convert_to_iso(start) if iso_format_validation(end) is False and end is not None: end = convert_to_iso(end) if validate_timestamp(start, end) is False: error = 'Error to get values due end value is smaller than start.' raise ValueError(error) points = self._get_points(namespace, start, end, field, method, fill, group) return points
def _make_search(start, end, fname): """Return the result of the search in csv file.""" end = end or now() start = start or 0 validate_timestamp(start, end) start = iso_format_validation(start) end = iso_format_validation(end) search = [] with open(fname, 'r', newline='') as csvfile: csvreader = csv.reader(csvfile, delimiter=',') for row in csvreader: if start <= row[1] <= end: search.append(row) return search
def test_validate_timestamp_success(self): """Test success in method validate_timestamp_.""" start = "1970-01-01T00:00:00Z" end = "1970-01-01T00:00:01Z" return_value = validate_timestamp(start, end) self.assertEqual(return_value, True)
def test_validate_timestamp_fail(self): """Test fail in method validate_timestamp.""" # start in this case is bigger than end. start = "1971-01-01T00:00:00Z" end = "1970-01-01T00:00:01Z" return_value = validate_timestamp(start, end) self.assertEqual(return_value, False)
def get(self, namespace, start=None, end=None, method=None, fill=None, group=None): """Make a query to retrieve something in the database.""" start = iso_format_validation(start) end = iso_format_validation(end) namespace, field = _verify_namespace(namespace) if not self._namespace_exists(namespace): return 400 if validate_timestamp(start, end) == 400: return 400 points = self._get_points(namespace, start, end, field, method, fill, group) return _parse_result_set(points, field)
def delete(self, namespace, start=None, end=None): """Delete data in influxdb. Start and end must be a timestamp.""" if iso_format_validation(start) is False and start is not None: start = convert_to_iso(start) if iso_format_validation(end) is False and end is not None: end = convert_to_iso(end) if _validate_namespace(namespace): namespace, _ = _extract_field(namespace) if not self._namespace_exists(namespace): error = (f'Error deleting because namespace \'{namespace}\' does' 'not exist.') raise NamespaceError(error) if validate_timestamp(start, end) is False: error = 'Error to get values due end value is smaller than start.' raise ValueError(error) return self._delete_points(namespace, start, end)
def delete(self, namespace, start=None, end=None): """Delete the entire database. start and end most be a timestamp """ start = iso_format_validation(start) end = iso_format_validation(end) namespace = _verify_namespace(namespace) if isinstance(namespace, tuple): namespace = namespace[0] if namespace in (400, 404): return namespace if not self._namespace_exists(namespace): log.error("Namespace {} does not exist".format(namespace)) return 400 if validate_timestamp(start, end) == 400: return 400 self._delete_points(namespace, start, end) return 200