Beispiel #1
0
    def match_temporal_coverage(cls, start: str = None, end: str = None) -> str:
        """Generate query body for query by temporal_coverage.

        Args:
            start: dataset should cover date time earlier than the start date.
            end: dataset should cover date time later than the end date.

        Returns:
            string of query body
        """
        start = Utils.date_validate(date_text=start)
        end = Utils.date_validate(date_text=end)
        if not start and not end:
            warnings.warn("Start and end are None, match all")
            return cls.match_all()

        body = {
            "query": {
                "nested": {
                    "path": "variables",
                    "inner_hits": {
                        "_source": [
                            "temporal_coverage"
                        ]
                    },
                    "query": {
                        "bool": {
                            "must": [
                            ]
                        }
                    }
                }
            }
        }

        if start:
            body["query"]["nested"]["query"]["bool"]["must"].append(
                {
                    "range": {
                        "variables.temporal_coverage.start": {
                            "lte": start,
                            "format": "yyyy-MM-dd'T'HH:mm:ss"
                        }
                    }
                }
            )

        if end:
            body["query"]["nested"]["query"]["bool"]["must"].append(
                {
                    "range": {
                        "variables.temporal_coverage.end": {
                            "gte": end,
                            "format": "yyyy-MM-dd'T'HH:mm:ss"
                        }
                    }
                }
            )

        return json.dumps(body)
Beispiel #2
0
    def __init__(self, description: dict, datamart_id: int):
        """Init method of GlobalMetadata.

        Args:
            description: description dict.
            datamart_id: unique datamart_id.

        Returns:

        """

        super().__init__()

        self._metadata["datamart_id"] = datamart_id
        if "title" in description:
            self._metadata["title"] = description["title"]

        if "description" in description:
            self._metadata["description"] = description["description"]

        if "url" in description:
            self._metadata["url"] = description["url"]

        if "keywords" in description:
            self._metadata["keywords"] = description["keywords"]

        if "date_published" in description:
            self._metadata["date_published"] = description["date_published"]
        if self.date_published:
            self.date_published = Utils.date_validate(self.date_published)

        if "date_updated" in description:
            self._metadata["date_updated"] = description["date_updated"]
        if self.date_updated:
            self.date_updated = Utils.date_validate(self.date_updated)

        if "provenance" in description:
            self._metadata["provenance"] = description["provenance"]

        if "original_identifier" in description:
            self._metadata["original_identifier"] = description[
                "original_identifier"]

        try:
            self._metadata["materialization"] = description["materialization"]
        except:
            raise ValueError("No materialization found")

        if "python_path" not in self.materialization:
            raise ValueError("No python path found in materialization")

        if "arguments" not in self.materialization:
            self._metadata["materialization"]["arguments"] = None

        self._metadata["variables"] = list()
        self._variables = list()

        if "license" in description:
            self._metadata["license"] = description["license"]
Beispiel #3
0
 def test_date_validate(self):
     print("[Test]{}/test_date_validate".format(self.__class__.__name__))
     self.assertEqual(Utils.date_validate("2018-10-10"),
                      "2018-10-10T00:00:00")
     print(colored('.Done', 'red'))
Beispiel #4
0
 def test_date_validate(self):
     self.assertEqual(Utils.date_validate("2018-10-10"),
                      "2018-10-10T00:00:00")