Skip to content

Create timeseries

Create empty time series dataset

New dataset can be created without the need to provide the data. POST/api/ts/dataset allows creating a new dataset. Time series schema, metadata and properties can be defined. After this endpoint is called, an event is propagated to the Metadata service, and a corresponding dataset is created there as well (read about more about events here). SAS token with a projectId has to be provided for this endpoint - the new dataset will be created in this project. The user needs to have Create privilege for that project.

Click to show example shell script
projectid="<replacewithprojectid>"
openapikey="<replacewithopenapikey>"
datasetid="<replacewithdatasetid>"

curl -L -X POST "https://api.mike-cloud-test.com/api/ts/dataset" \
  -H 'Content-Type: application/json' \
  -H "dhi-open-api-key: $openapikey" \
  -H "dhi-service-id: timeseries" \
  -H "dhi-project-id: $projectid" \
  -H "dhi-dataset-id: $datasetid" \
--data-raw "{
  \"timeSeriesSchema\": {
    \"properties\": [
      {
        \"name\": \"string\",
        \"dataType\": \"DateTime\"
      }
    ]
  },
  \"datasetProperties\": {
    \"name\": \"string\",
    \"description\": \"string\",
    \"metadata\": {},
    \"properties\": {}
  }
}"

Create new time series within the dataset

Within a dataset, clients can create a new time series using POST/api/ts/dataset/{id}/timeseries

Click to show example shell script
projectid="<replacewithprojectid>"
openapikey="<replacewithopenapikey>"
datasetid="<replacewithdatasetid>"

curl -L -X POST "https://api.mike-cloud-test.com/api/ts/dataset/9f86c0ee-2823-407e-950a-6903eaaa3ff5/timeseries" \
  -H 'Content-Type: application/json' \
  -H "dhi-open-api-key: $openapikey" \
  -H "dhi-service-id: timeseries" \
  -H "dhi-project-id: $projectid" \
  -H "dhi-dataset-id: $datasetid" \
--data-raw "{
  \"id\": \"05f8141e-5a6f-4b89-aee6-774431f90970\",
  \"item\": {
    \"name\": \"TestItem\",
    \"unit\": \"eumUUnitUndefined\",
    \"item\": \"eumIItemUndefined\",
    \"dataType\": \"Single\",
    \"timeSeriesType\": \"Instantaneous\"
  },
  \"dataFields\": [
    {
      \"name\": \"DfSingle\", \"dataType\": \"Single\"
    },
    {
      \"name\": \"Quality\",
      \"dataType\": \"Flag\",
      \"flags\": [
        { \"id\": 0, \"name\": \"Bad\", \"level\": 0 }, { \"id\": 1, \"name\": \"Ok\", \"level\": 0 }, { \"id\": 2, \"name\": \"Semi\", \"level\": 0 }
      ]
    }
  ]
}"

Upload new time series from csv file

Adding new time series, especially when loading large volumes of data during an initial load, is best performed using the platform import pipeline and the generic POST/api/conversion/upload-convert

{
  "uploadUrl": "<url with sas token obtained by calling GET /api/conversion/transfer/upload-url>",
  "outputDatasetData": {
    "name": "Esbjerg small",
    "description": "Upload of small time series in csv"
  },
  "projectId": "<projectId>",
  "readerParameters": [],
  "writerParameters": [],
  "readerName": "CSVReader",
  "writerName": "TSWriter"
}

Upload new time series from zipped csv file - GHM format

Adding new time series from zipped csv file in GHM format is done using the platform import pipeline and the generic POST/api/conversion/upload-convert

{
  "uploadUrl": "<url with sas token obtained by calling GET /api/conversion/transfer/upload-url>",
  "outputDatasetData": {
    "name": "Computed data 12345678-12345888",
    "description": "Upload block of time series"
  },
  "projectId": "<projectId>",
  "readerParameters": [],
  "writerParameters": [],
  "readerName": "GHMReader",
  "writerName": "TSWriter"
}

The writerParameters may include definition of time series properties like this:

{
   "name": "TimeSeriesProperties",
   "value": [
     { "name": "CX", "dataType": "Double" },
     { "name": "CY", "dataType": "Double" }
   ]
}

All time series values are stored together in one blob. This storage format is better for smaller time series. It speeds up the import of csv files with higher amounts of time series. Time series stored in this format can't be modified. Adding time series in combined format is not possible. Appending values into time series in combined format is supported using conversion with time series append writer ("TSAppender").