API Documentation
Welcome to the documentation for communicating with Tiseda. In this documentation you'll find how to create and manage the configuration, all the methods to add data into Tiseda and of course how to retrieve the raw or aggregated data.
Choose your flavour
Using the following libraries you can communicate with Tiseda directly from your application. The fully featured libraries offer all the functionality while the other libraries are still in development. The syntax and function calls of all libraries are built to be very similar to each other while also incorporating the native objects of the programming language.
Language | Features | Package Manager/Url | Download/Url | |
---|---|---|---|---|
.NET | Fully featured | NuGet | TisedaConnection.dll | |
JavaScript | Fully featured | - | Tiseda.min.js | |
Rest API | Fully featured | Swagger/OpenAPI | - | |
Python | Some data features | - | Coming soon | |
PHP | Some data features | - | Coming soon |
Configuration
Structure
The configuration in Tiseda is defined in tree of data points. Each data point is a container under which time series data values are stored (Moment, Value). These data points have properties to describe the data and the aggregation which needs to be done on the data.
Data point structure:
- Id: This is an automatic generated number (UInt32) which can be used to reference to this datapoint
-
DataType
- Consumption (0): This is used for any data which says something about an amount in a period of time (like Energy consumption data). The automatic retrieval will return the total amount of consumption in the period requested, and will linear interpolate if the from/till retrieval is not exactly at the start/end of data.
- Point (1): Used for samples at exact moments. Use this for data which cannot be interpolated.
- Status (2): This can be used for temperatures or anything else which cannot be summed together when having multiple values. By default the automatic retrieval will return with averages for a data point with this data type.
-
AggregationOperationType
- None (0): This is the data point where you would store your raw data.
- Math (1): Use this to reference one or more other datapoints in a formula. This can be used to aggregate multiple data points (For example: #1+(ABS(#2)*#3) ).
- CounterToConsumption (2): This aggregation converts counter values (like electricity meter readings) to consumption values.
- Gaps (3): This aggregation will create values based on the availability of data in the referenced source data points.
- Summary (4): Combines multiple datapoints with a single aggregation. This aggregation is used to create a summary data point about a large group of other data points (For example: Average temperature across all weather stations).
- Validation (5): Checks the values of the source data point and saves a flagged value for each check triggered.
-
ValuesPeriod:
- More than 1 or less than -1: The amount of time for a value in this datapoint to be active in seconds. This can also be a negative number if the value says something about the time before the moment.
- The values -1 and 1: The amount of time for a value to be active will be extended till it reaches the moment of the previous (-1) or next (1) value.
- The value 0 at a Raw data point means it is a sample, at other data points (Like Math, Counter) it will automatically decide based on the referenced datapoints.
-
StreamingAggregationType: When data is streamed (like from an IoT device), it will collect the data for [ValuesPeriod] time and then write the aggregated value using the selected aggregation.
- Sum (0)
- Min (1)
- Max (2)
- Avg (3)
- Tags[]: Used for filters or any meta data. If the tag starts with Name= it will be displayed as name on the web interface.
- Links[]: Contains any settings for the aggregation. Helper functions are available to populate these links (ApplyFormula, ApplyCounterToConsumption, ApplyGaps, ApplySummary) .
Retrieve
Retrieve all data points matching the filter. The filter searches on tags and supports the wildcard ? (Match any character) and * (Match everything following). The filter also has support for And operators && and Or operators ||. Optionally the parameters limit and skip can be used to control the amount of results.
var dataPoints = tiseda.Select("Filter").Retrieve();
tiseda.Select("Filter").Retrieve(0, 0, function(dataPoints) { // dataPoints contains a list of the data points });
GET https://api.tiseda.com/Configuration/Retrieve?filter=Filter
CreateOrUpdate
Pass a data point configuration to Tiseda. If the Id is 0, a new data point will be created in Tiseda. Otherwise the existing data point will be updated with the new configuration.
var dataPoint = new TisedaDataPoint() { Id = 0, DataType = DataType.Consumption, AggregationOperationType = OperationType.None, StreamingAggregationType = AggregationType.Sum, ValuesPeriod = 3600, Links = new List<TisedaLink>(), Tags = new List<string>() { "Tag 1", "Tag 2" } }; // Setting the second parameter to true will update the dataPoint object with the new Id after saving tiseda.CreateOrUpdate(dataPoint, true);
var dataPoint = new Tiseda.TisedaDataPoint(); dataPoint.Id = 0; dataPoint.DataType = Tiseda.DataType.Consumption; dataPoint.AggregationOperationType = Tiseda.OperationType.None; dataPoint.StreamingAggregationType = Tiseda.AggregationType.Sum; dataPoint.ValuesPeriod = 3600; dataPoint.Links = []; dataPoint.Tags = ["Tag 1","Tag 2"]; // Setting the second parameter to true will update the dataPoint object with the new Id after saving tiseda.CreateOrUpdate(dataPoint, true, function() { // Created or updated });
POST https://api.tiseda.com/Configuration/CreateOrUpdate { "Id": 0, "DataType": 0, "AggregationOperationType": 0, "StreamingAggregationType": 0, "ValuesPeriod": 3600, "Links": [], "Tags": ["Tag 1", "Tag 2"] }
CreateOrSelectExisting
Select a data point using the tag as a filter, if it doesn't exist, create one with the given configuration added and return it. If the parameter updateChanges is true, it will overwrite the configuration if a data point is found.
var dataPoint = new TisedaDataPoint() { Id = 0, DataType = DataType.Consumption, AggregationOperationType = OperationType.None, StreamingAggregationType = AggregationType.Sum, ValuesPeriod = 3600, Links = new List<TisedaLink>(), Tags = new List<string>() { "Tag 1", "Tag 2" } }; // Setting the third to true will update an existing datapoint with the new settings tiseda.CreateOrSelectExisting(dataPoint, "Tag 3", false);
var dataPoint = new Tiseda.TisedaDataPoint(); dataPoint.Id = 0; dataPoint.DataType = Tiseda.DataType.Consumption; dataPoint.AggregationOperationType = Tiseda.OperationType.None; dataPoint.StreamingAggregationType = Tiseda.AggregationType.Sum; dataPoint.ValuesPeriod = 3600; dataPoint.Links = []; dataPoint.Tags = ["Tag 1","Tag 2"]; // Setting the third to true will update an existing datapoint with the new settings tiseda.CreateOrSelectExisting(dataPoint, "Tag 3", false, function() { });
POST https://api.tiseda.com/Configuration/CreateOrSelectExisting { "DataPoint": { "Id": 0, "DataType": 0, "AggregationOperationType": 0, "StreamingAggregationType": 0, "ValuesPeriod": 3600, "Links": [], "Tags": ["Tag 1", "Tag 2"] }, "Tag": "Tag 3", "UpdateChanges": false }
ApplyFormula
Apply a math formula to the data point. Multiple formulas can be applied using the optional From/Till parameters. When overlapping, the last applied formula will be used in the overlapping period. The formula will be executed for each unique value moment in the referenced data points.
Syntax help:
Use a hash tag followed by a number to reference a data point.
Round brackets are supported as well as the math functions SIN, TAN, LOG, SQRT, ACOS, ASIN, ATAN, COSH, SINH, TANH, EXP, LOG10, CEIL, FLOOR, ABS.
Using :Seconds after a data point will apply a time shift to the retrieved data. Example to use data from an hour earlier: #123:-3600
Using :Seconds after another number will turn this number into a consumption per [Seconds] time. For example, when you want to add 25 consumption per minute to data point #123, use #123 + 25:60
Inline if's are possible using the syntax (ValueOrDataPointA Comparison ValueOrDatapointB ? ValueWhenTrue : ValueWhenFalse), For example to turn all values higher than 5 into 5: (#123 > 5 ? 5 : #123)
Using #DataPointA||#DataPointB an alternative can be defined for when the first data point does not have data.
By using ! anywhere in the formula, the formula will stop and return Missing if there was no value at that point during execution. Use this to mark required variables, for example: (#123!) / (#456!) will make sure this formula only returns values if there is data for both #123 and #456.
Note: The order of executing is always from left to right. The standard mathematic precedence rules do not apply here! Groups are executed first and can be used to force precedence.
var dataPoint = tiseda.Select(789).Retrieve().First(); dataPoint.ApplyFormula("#123 * (15 + #456)", new DateTime(2010,01,01), new DateTime(2030,01,01)); tiseda.CreateOrUpdate(dataPoint, false);
tiseda.Select(789).Retrieve(0,0,function(dps) { var dataPoint = dps[0]; dataPoint.ApplyFormula("#123 * (15 + #456)", new Date("2010-01-01").getTime(), new Date("2030-01-01").getTime()); tiseda.CreateOrUpdate(dataPoint, false, function() { }); });
POST https://api.tiseda.com/Configuration/ApplyFormula { "DataPointId": 789, "Formula": "#123 * (15 + #456)", "From": "2010-01-01T00:00:00Z", "Till": "2030-01-01T00:00:00Z" }
ApplyCounterToConsumption
This aggregation converts counter values (like electricity meter readings) to consumption values. The following parameters are optionally available to support working with the raw data:
- maxReversable: 0 any negative consumption is seen as a counter reset. 1 allows any negative consumption. Any negative number is used to set a limit of how much negative consumption is allowed without it being seen as a counter reset
- counterMax: Max possible value for a counter. This is used to define the upper limit of the counter and will be used to calculate consumption at a counter reset.
- counterMin: Min possible value for a counter. This is used to define the lower limit of the counter and will be used to calculate consumption at a counter reset.
- maxConsumption: If the calculated consumption is higher than this value, it will be set to 0. This can be used in case a counter sometimes jumps around.
- factor: Apply a factor to the consumption
var dataPoint = tiseda.Select(456).Retrieve().First(); dataPoint.ApplyCounterToConsumption(123, counterMax: 10000); tiseda.CreateOrUpdate(dataPoint, false);
tiseda.Select(456).Retrieve(0,0,function(dps) { var dataPoint = dps[0]; // Parameters: sourceDataPointId, maxReversable?, counterMax?, counterMin?, maxConsumption?, factor? dataPoint.ApplyCounterToConsumption(123, null, 10000); tiseda.CreateOrUpdate(dataPoint, false, function() { }); });
POST https://api.tiseda.com/Configuration/ApplyCounterToConsumption { "DataPointId": 456, "SourceDataPointId": 123, "CounterMax": 10000 }
ApplyGaps
Reports about the source datapoints and store a value on the exact moment when there is data in the source or no data. This aggregation will first check the first source data point, if this one has no data, it will continue with the next ones using the same method. This will change the ValuesPeriod of this data point to 1. The optional parameter resultValues can be used to define what value needs to be stored at the moment when data is detected. By default it will use the index (starting with 1) of the data point in the source data point array.
var dataPoint = tiseda.Select(456).Retrieve().First(); dataPoint.ApplyGaps(new uint[] { 123 }, new double[] { 100 }); tiseda.CreateOrUpdate(dataPoint, false);
tiseda.Select(456).Retrieve(0,0,function(dps) { var dataPoint = dps[0]; // Parameters: sourceDataPointIds[], resultValues[]? dataPoint.ApplyGaps([123], [100]); tiseda.CreateOrUpdate(dataPoint, false, function() { }); });
POST https://api.tiseda.com/Configuration/ApplyGaps { "DataPointId": 456, "SourceDataPointId": [123], "ResultValues": [100] }
ApplySummary
Combine multiple data points and apply an aggregation. Note that the ValuesPeriod for this data point needs to be lower than -1 or higher than 1. The parameter 'aggregationType' is used to decide what aggregation to do (Sum/Min/Max/Average).
var dataPoint = tiseda.Select(456).Retrieve().First(); dataPoint.ApplySummary(new uint[] { 123 }, AggregationType.Avg); tiseda.CreateOrUpdate(dataPoint, false);
tiseda.Select(456).Retrieve(0,0,function(dps) { var dataPoint = dps[0]; // Parameters: sourceDataPointIds[], aggregationType? dataPoint.ApplySummary([123], Tiseda.AggregationType.Avg); tiseda.CreateOrUpdate(dataPoint, false, function() { }); });
POST https://api.tiseda.com/Configuration/ApplySummary { "DataPointId": 456, "SourceDataPointId": [123], "AggregationType": 3 }
Delete
Delete specific data points. By default this call will do nothing if the data point is used in aggregations by other data points. Use the parameter 'force' to override this check and always delete this datapoint.
var dataPoint = tiseda.Select(456).Delete(true);
tiseda.Select(456).Delete(true,function() { // Finished deleting });
POST https://api.tiseda.com/Configuration/Delete { "DataPointId": 456, "Force": true }
Insert Data
Using code
Insert one or multiple values to data points using their Id or Tag. When committing the values are send to Tiseda using the specified InsertMethod. The following InsertMethods are available:
- DontDeleteExistingValues (0): Just add the values directly to the data point without checking for any existing values. Use this when you are certain your data is new. (Fastest!)
- DeleteValuesInCompletePeriod (1): Takes the first and last moment of the added data for a specific data point and delete all existing values in this period (Fast).
- DeleteValuesOnExactMoments (2): Adds the data and reorders the underlying data file to remove all duplicated values (keeping the last values).
- BulkInsert (3): Waits till all data for the data points is added. Then reorders all underlying data point files and after that do the calculations (Use this when adding a large set of data).
- DeleteAllValues (4): Delete all existing values for a data point. Then insert the new values (Fast).
- InsertOnlyNewerValues (5): Checks when the last value is stored for a data point and then only add the newer values to this data point (Fast).
- BulkInsertDirect (6): Similar to BulkInsert, but directly reorder the underlying files when data is added. This is slower than BulkInsert, but makes sure data retrieval methods while inserting data are giving correct results.
tiseda.AddValue(new DateTime(2020,01,01), 1234, "Tag 1"); tiseda.AddValue(new DateTime(2020,01,02), 5678, "Tag 1"); tiseda.CommitValues(InsertMethod.InsertOnlyNewerValues);
tiseda.AddValue(new Date("2020-01-01").getTime(), 1234, "Tag 1"); tiseda.AddValue(new Date("2020-01-02").getTime(), 5678, "Tag 1"); tiseda.CommitValues(Tiseda.InsertMethod.InsertOnlyNewerValues);
POST https://api.tiseda.com/Value/Add { "Filter": "Tag 1", "Values": [ { "Moment": "2020-01-01T00:00:00Z", "Value": 1234 }, { "Moment": "2020-01-02T00:00:00Z", "Value": 5678 }, ], "InsertMethod": 5 }
Streaming
Stream data into a buffer in Tiseda. The StreamingAggregationType and ValuesPeriod will be used to calculate the actual value to be saved.
Retrieve Data
RetrieveValues
Used to retrieve aggregated data. Use the From/Till parameters to select what period to retrieve. The parameter 'interval' is used to decide how to divide the period (None 0, Seconds 1, Minutes 2, FifteenMinutes 3, Hour 4, Day 5, Month 6, Year 8).
Alternatively an array of Moments can be passed to exactly decide what period needs to be retrieved with what exact divide moments. [Start Moment, Divide moment, Divide moment, .., End moment].
The following aggregation types are available:
- Sum (0)
- Min (1): Finds the lowest single value
- Max (2): Finds the highest single value
- Average (3): Calculates the average based on values
- Count (4): Count number of values
- Status (5): Retrieve the last/next value at the divide moments, based on the value period of the data point.
- Next (7): Retrieve the next value at the divide moments.
- Next (9): Retrieve the last value at the divide moments.
- StatusAvg (10): Retrieve an average for a status data point. This looks at the amount of time a value is active.
- Flags (11): Bitwise operation, retrieves all flags set within this period
- Median (20)
- Percentile50 (21)
- Percentile75 (22)
- Percentile95 (23)
- Percentile59 (24)
- Percentile99_9 (25)
- ConsumptionMinPerSecond (41): Used for consumption data points to find out what the lowest interpolated consumption is per second.
- ConsumptionMaxPerSecond (42): Used for consumption data points to find out what the highest interpolated consumption is per second.
- ConsumptionAvgPerSecond (43): Used for consumption data points to find out what the average interpolated consumption is per second.
- Sum (50): Sum based on the interpolated consumption
- Automatic (60): Automatic select what aggregation to use based on the data type of the data point.
var values = tiseda.Select("Filter") .RetrieveValues(new DateTime(2010,01,01), new DateTime(2020,01,01), IntervalType.Year, AggregationType.Automatic);
tiseda.Select("Filter") .RetrieveValues([new Date("2010-01-01").getTime(), new Date("2020-01-01").getTime()], "Year", Tiseda.AggregationType.Automatic, function(values) { // values contains a dictionary with data point Id as key, and an array of { Moment: Epoch, Value: Number } as value. });
GET https://api.tiseda.com/Value/Retrieve?filter=Filter&from=2010-01-01T00:00:00Z&till=2020-01-01T00:00:00Z&interval=8&aggregation=60
RetrieveRawValues
The underlying raw data for a data point can be received using this method. If the parameter 'expand' is set to true, the From and Till moments will be automatically expanded till it finds a value before and value after the period given.
var values = tiseda.Select("Filter") .RetrieveRawValues(new DateTime(2010,01,01), new DateTime(2020,01,01), true);
tiseda.Select("Filter") .RetrieveRawValues(new Date("2010-01-01").getTime(), new Date("2020-01-01").getTime(), function(values) { // values contains a dictionary with data point Id as key, and an array of { Moment: Epoch, Value: Number } as value. });
GET https://api.tiseda.com/Value/RetrieveRaw?filter=Filter&from=2010-01-01T00:00:00Z&till=2020-01-01T00:00:00Z&expand=true
Changes
Tiseda keeps track of the exact moment when data points are changed and what period is changed (Default these changes are only stored a week). Use this method to retrieve those changes. Store and use the 'position' parameter to only retrieve changes since the previous call to this method.
ulong position = 0; var changes = tiseda.RetrieveChanges(ref position, "Filter*"); // position is now updated with a high number
tiseda.RetrieveChanges(0, "Filter*", true, function(journalLines, newPosition) { });
GET https://api.tiseda.com/Value/RetrieveChanges?filter=Filter*&position=0