Rozdíly
Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.
| Obě strany předchozí revize Předchozí verze Následující verze | Předchozí verze | ||
|
cs:mervis-db:10-api [2017/07/12 18:07] m.chlupac |
cs:mervis-db:10-api [2024/05/08 10:42] (aktuální) |
||
|---|---|---|---|
| Řádek 2: | Řádek 2: | ||
| Mervis DB nabízí otevřené rozhraní protokolu [[https:// | Mervis DB nabízí otevřené rozhraní protokolu [[https:// | ||
| - | | + | |
| + | | ||
| Pro speciální použití existují i další rozhraní pro komunikaci s Mervis DB - pro jejich použití a popis kontaktujte prosím [[: | Pro speciální použití existují i další rozhraní pro komunikaci s Mervis DB - pro jejich použití a popis kontaktujte prosím [[: | ||
| - | |||
| ===== Seznam základních podporovaných funkcí ===== | ===== Seznam základních podporovaných funkcí ===== | ||
| - | |||
| ^Function^Description| | ^Function^Description| | ||
| Řádek 19: | Řádek 18: | ||
| ^DeleteVariables| | | ^DeleteVariables| | | ||
| ^DeleteData| | | ^DeleteData| | | ||
| + | ^ReplaceData|Delete data from time range and save one or multiple records from one or multiple variables in one API call| | ||
| ^EnsureVariables| | | ^EnsureVariables| | | ||
| - | ^GetTransformedData/ | + | ^GetTransformedData/ |
| ^GetServerVersion| | | ^GetServerVersion| | | ||
| ^GetVariableStats|Obsolete| | ^GetVariableStats|Obsolete| | ||
| ^GetVariableStatsAsync|Obsolete| | ^GetVariableStatsAsync|Obsolete| | ||
| ^CheckCredentials| | | ^CheckCredentials| | | ||
| + | |||
| + | ===== Vlastnosti objektu ===== | ||
| + | * (UTC) Časová známka - UTC časová známka záznamu | ||
| + | * Platnost do - UTC časová známka konce platnosti konkrétního záznamu | ||
| + | * Interval - doba (v sekundách), | ||
| ===== Příklady použití ===== | ===== Příklady použití ===== | ||
| - | |||
| ==== C# ==== | ==== C# ==== | ||
| - | FIXME | + | |
| + | {{ : | ||
| + | |||
| + | === Download === | ||
| + | |||
| + | |||
| + | {{ : | ||
| + | {{ : | ||
| + | |||
| + | === Kód === | ||
| + | |||
| + | |||
| + | <code csharp MervisDB_GetData_Example.cs> | ||
| + | using ESG.Core.Access.Client; | ||
| + | using ESG.Db.Server.Shared; | ||
| + | using ESG.Db.ServerAccess; | ||
| + | using System; | ||
| + | using System.Collections.Generic; | ||
| + | using System.Linq; | ||
| + | using System.Threading.Tasks; | ||
| + | |||
| + | namespace DbClientTest | ||
| + | { | ||
| + | class Program | ||
| + | { | ||
| + | static async Task Main(string[] args) | ||
| + | { | ||
| + | try | ||
| + | { | ||
| + | // | ||
| + | // Create access to the real server. | ||
| + | // Without SSL connections, | ||
| + | // The client is automatically generated from the WSDL file available here: https:// | ||
| + | // | ||
| + | using (HistoryDbAccessClient client = new HistoryDbAccessClient(HistoryDbAccessClient.EndpointConfiguration.HistoryAccess, | ||
| + | { | ||
| + | // Authentication credetials in the database. | ||
| + | Credentials credentials = new Credentials | ||
| + | { | ||
| + | Name = " | ||
| + | Password = " | ||
| + | }; | ||
| + | |||
| + | // Specification of the variables through Key-Value. | ||
| + | // Here we use 2 variables. | ||
| + | ESG.Db.Server.Shared.KeyValuePair[][] keys = new ESG.Db.Server.Shared.KeyValuePair[][] { | ||
| + | new ESG.Db.Server.Shared.KeyValuePair[] { | ||
| + | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
| + | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
| + | }, | ||
| + | new ESG.Db.Server.Shared.KeyValuePair[] { | ||
| + | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
| + | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | // From-To dates. The dates must be specified in the UTC time zone. | ||
| + | DateTime utcTo = DateTime.UtcNow; | ||
| + | DateTime utcFrom = DateTime.UtcNow.AddDays(-1); | ||
| + | |||
| + | // Retrieving the data goes through cycling of values and variables. The server returns recommended values needed for the the next cycle. | ||
| + | int variableOffset = 0; // the offset of the variable | ||
| + | int variableCount = 10; // maximal number of variables returned in one request | ||
| + | int valueOffset; | ||
| + | int valueCount = 1000; // maximal values in on request | ||
| + | |||
| + | Console.WriteLine(" | ||
| + | |||
| + | do | ||
| + | { | ||
| + | valueOffset = 0; | ||
| + | do | ||
| + | { | ||
| + | // Execute the request. | ||
| + | var result = await client.GetDataAsyncAsync(credentials, | ||
| + | |||
| + | // Check the return code. " | ||
| + | if (!result.ReturnCode.StartsWith(" | ||
| + | { | ||
| + | Console.WriteLine(" | ||
| + | } | ||
| + | |||
| + | // Cycle through the data and print it out. | ||
| + | foreach (var valRecord in result.Data) | ||
| + | { | ||
| + | Console.WriteLine(" | ||
| + | { | ||
| + | return String.Format(" | ||
| + | }))); | ||
| + | |||
| + | foreach (var value in valRecord.Values) | ||
| + | { | ||
| + | Console.WriteLine(" | ||
| + | } | ||
| + | } | ||
| + | |||
| + | valueOffset = result.NextValueOffset; | ||
| + | variableOffset = result.NextVariableOffset; | ||
| + | } | ||
| + | while (valueOffset != -1); | ||
| + | } | ||
| + | while (variableOffset != -1); | ||
| + | } | ||
| + | |||
| + | } | ||
| + | catch (Exception exc) | ||
| + | { | ||
| + | Console.WriteLine(" | ||
| + | } | ||
| + | |||
| + | Console.WriteLine(" | ||
| + | |||
| + | Console.ReadLine(); | ||
| + | } | ||
| + | |||
| + | } | ||
| + | }</ | ||
| + | |||
| + | <code csharp MervisDB_SaveData_Example.cs> | ||
| + | using System; | ||
| + | using System.Collections.Generic; | ||
| + | using System.Threading.Tasks; | ||
| + | using MervisDb_SaveData_Example.MervisDbService; | ||
| + | |||
| + | namespace MervisDb_SaveData_Example | ||
| + | { | ||
| + | class Program | ||
| + | { | ||
| + | static async Task Main(string[] args) | ||
| + | { | ||
| + | try | ||
| + | { | ||
| + | // | ||
| + | // Create access to the real server. | ||
| + | // Without SSL connections, | ||
| + | // The client is automatically generated from the WSDL file available here: https:// | ||
| + | // | ||
| + | using (HistoryDbAccessClient client = new HistoryDbAccessClient(HistoryDbAccessClient.EndpointConfiguration.HistoryAccess, | ||
| + | { | ||
| + | // Authentication credetials in the database. | ||
| + | Credentials credentials = new Credentials { Name = " | ||
| + | |||
| + | // Adding records... | ||
| + | List< | ||
| + | |||
| + | DateTime utcTimeStamp = new DateTime(2018, | ||
| + | |||
| + | // Each value is stored in a ValueRecord structure | ||
| + | ValueRecord rec = new ValueRecord(); | ||
| + | |||
| + | rec.UtcTimeStamp = utcTimeStamp; | ||
| + | rec.HistoryValueType = HistoryValueType.Double; | ||
| + | rec.DoubleValue = 23.4; // value itself | ||
| + | rec.Interval = 60.0; // sampling period in seconds. When the difference of timestamps of subsequent values if greater than 1.1 multiple of the interval, the data should be considered incomplete. | ||
| + | rec.Keys = new ESG.Db.Server.Shared.KeyValuePair[] // | ||
| + | { | ||
| + | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
| + | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
| + | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
| + | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
| + | new ESG.Db.Server.Shared.KeyValuePair(false, | ||
| + | new ESG.Db.Server.Shared.KeyValuePair(false, | ||
| + | }; | ||
| + | |||
| + | records.Add(rec); | ||
| + | |||
| + | // Save data method returns the number of stored records | ||
| + | int recordsSaved = await client.SaveDataAsync(credentials, | ||
| + | |||
| + | Console.WriteLine(" | ||
| + | } | ||
| + | |||
| + | } | ||
| + | catch (Exception exc) | ||
| + | { | ||
| + | Console.WriteLine(" | ||
| + | } | ||
| + | |||
| + | Console.WriteLine(" | ||
| + | |||
| + | Console.ReadLine(); | ||
| + | } | ||
| + | } | ||
| + | }</ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | <code csharp MervisDb_ReplaceData_Example.cs> | ||
| + | using ESG.Core.Access.Client; | ||
| + | using ESG.Db.Server.Shared; | ||
| + | using ESG.Db.ServerAccess; | ||
| + | using System; | ||
| + | using System.Collections.Generic; | ||
| + | |||
| + | namespace DbClientTest | ||
| + | { | ||
| + | class Program | ||
| + | { | ||
| + | static async Task Main(string[] args) | ||
| + | { | ||
| + | RcWareDbClient dbClient = new RcWareDbClient(false, | ||
| + | dbClient.Credentials = new ESG.Db.Server.Shared.Credentials(" | ||
| + | |||
| + | DateTime utcNow = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5)); | ||
| + | |||
| + | ESG.Db.Server.Shared.KeyValuePair[] varKeysNew = new ESG.Db.Server.Shared.KeyValuePair[] | ||
| + | { | ||
| + | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
| + | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
| + | }; | ||
| + | |||
| + | ESG.Db.Server.Shared.KeyValuePair[] varKeys1 = new ESG.Db.Server.Shared.KeyValuePair[] | ||
| + | { | ||
| + | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
| + | new ESG.Db.Server.Shared.KeyValuePair(true, | ||
| + | }; | ||
| + | |||
| + | ESG.Db.Server.Shared.KeyValuePair[] varKeys = varKeys1; | ||
| + | |||
| + | // generate some records | ||
| + | List< | ||
| + | TimeSpan recsLength = TimeSpan.FromMinutes(2); | ||
| + | int recsPerMinute = 4; | ||
| + | |||
| + | Random r = new Random((int)DateTime.UtcNow.Ticks); | ||
| + | double rBase = r.NextDouble() * 10; | ||
| + | |||
| + | for (int i = 0; i < (recsLength.TotalSeconds / 60) * recsPerMinute; | ||
| + | { | ||
| + | recsToSave.Add(new ValueRecord(utcNow - recsLength + TimeSpan.FromMinutes(i * (1.0 / recsPerMinute)), | ||
| + | recsToSave[recsToSave.Count - 1].Keys = varKeys; | ||
| + | recsToSave[recsToSave.Count - 1].Interval = 60 / recsPerMinute; | ||
| + | |||
| + | recsToSave.Add(new ValueRecord(utcNow - recsLength + TimeSpan.FromMinutes(i * (1.0 / recsPerMinute)), | ||
| + | recsToSave[recsToSave.Count - 1].Keys = varKeysNew; | ||
| + | recsToSave[recsToSave.Count - 1].Interval = 60 / recsPerMinute; | ||
| + | } | ||
| + | |||
| + | var res = await dbClient.ReplaceDataAsync(new List< | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | <code csharp MervisDb_GetTransformedData_Example.cs> | ||
| + | using System; | ||
| + | using System.Linq; | ||
| + | using System.Threading.Tasks; | ||
| + | using MervisDb_GetTransformedData_Example.MervisDbService; | ||
| + | |||
| + | namespace MervisDb_GetTransformedData_Example | ||
| + | { | ||
| + | class Program | ||
| + | { | ||
| + | static async Task Main(string[] args) | ||
| + | { | ||
| + | // | ||
| + | // Create access to the real server. | ||
| + | // Without SSL connections, | ||
| + | // The client is automatically generated from the WSDL file available here: https:// | ||
| + | // | ||
| + | try | ||
| + | { | ||
| + | using (HistoryDbAccessClient client = new HistoryDbAccessClient(HistoryDbAccessClient.EndpointConfiguration.HistoryAccess, | ||
| + | { | ||
| + | // Authentication credentials in the database. | ||
| + | Credentials credentials = new Credentials { Name = " | ||
| + | |||
| + | // Specification of the variables through Key-Value. | ||
| + | // Here we use 2 variables. | ||
| + | ESG.Db.Server.Shared.KeyValuePair[][] variableKeys = new ESG.Db.Server.Shared.KeyValuePair[][] { | ||
| + | new ESG.Db.Server.Shared.KeyValuePair[] { | ||
| + | new ESG.Db.Server.Shared.KeyValuePair (/ | ||
| + | new ESG.Db.Server.Shared.KeyValuePair (/ | ||
| + | }, | ||
| + | new ESG.Db.Server.Shared.KeyValuePair[] { | ||
| + | new ESG.Db.Server.Shared.KeyValuePair (/ | ||
| + | new ESG.Db.Server.Shared.KeyValuePair (/ | ||
| + | } | ||
| + | }; | ||
| + | |||
| + | // Aggregation request | ||
| + | var aggregation = new AggregationRequest(); | ||
| + | aggregation.Types = new AggregationType[] { AggregationType.Last }; | ||
| + | aggregation.Interpolation = InterpolationType.None; | ||
| + | // | ||
| + | aggregation.IsoPattern = new string[] { " | ||
| + | aggregation.From = new DateTime(2018, | ||
| + | aggregation.To = new DateTime(2018, | ||
| + | aggregation.TimeZone = @" | ||
| + | |||
| + | // Retrieving the data goes through cycling of intervals and variables. The server returns recommended intervals needed for the the next cycle. | ||
| + | int variableOffset = 0; // the offset of the variable | ||
| + | int variableCount = 10; // maximal number of variables returned in one request | ||
| + | int intervalOffset; | ||
| + | int intervalCount = 1000; // maximal values in on request | ||
| + | |||
| + | Console.WriteLine(" | ||
| + | |||
| + | do | ||
| + | { | ||
| + | intervalOffset = 0; | ||
| + | |||
| + | do | ||
| + | { | ||
| + | // Execute the request. | ||
| + | var result = await client.GetTransformedDataAsyncAsync(credentials, | ||
| + | |||
| + | // Check the return code. " | ||
| + | if (!result.ReturnCode.StartsWith(" | ||
| + | { | ||
| + | Console.WriteLine(" | ||
| + | } | ||
| + | |||
| + | // Cycle through the data and print it out. | ||
| + | if (result.Data != null) | ||
| + | { | ||
| + | foreach (VariableAggregate vag in result.Data) | ||
| + | { | ||
| + | Console.WriteLine(" | ||
| + | |||
| + | foreach (Interval value in vag.Data) | ||
| + | { | ||
| + | Console.Write(" | ||
| + | |||
| + | if (value.Last != null) | ||
| + | { | ||
| + | Console.Write(" | ||
| + | } | ||
| + | |||
| + | Console.WriteLine(); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | variableOffset = result.NextVariableOffset; | ||
| + | intervalOffset = result.NextIntervalOffset; | ||
| + | |||
| + | } while (intervalOffset != -1); | ||
| + | |||
| + | } while (variableOffset != -1); | ||
| + | } | ||
| + | |||
| + | Console.WriteLine(" | ||
| + | |||
| + | } | ||
| + | catch (Exception exc) | ||
| + | { | ||
| + | Console.WriteLine(" | ||
| + | } | ||
| + | |||
| + | Console.WriteLine(" | ||
| + | |||
| + | Console.ReadLine(); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| ==== Matlab ==== | ==== Matlab ==== | ||
| - | FIXME | + | |
| + | {{ : | ||
| + | |||
| + | === Podporované funkce === | ||
| + | ^Function^Description| | ||
| + | ^SaveData|Save one or multiple records from one or multiple variables| | ||
| + | ^GetData|Read one or multiple records from one or multiple variables.| | ||
| + | ^GetDataUnmerged|Read one or multiple records from one or multiple variables. Allow more setting options than GetData function| | ||
| + | ^GetDataOrigin|Read data exactly as are stored in the database.| | ||
| + | ^DeleteVariable|Delete entire variable or some certain interval.| | ||
| + | ^GetRequiredTimestamp|Get time stamp depending on input options.| | ||
| + | |||
| + | === Toolbox === | ||
| + | |||
| + | |||
| + | Pro komunikaci Matlabu s Mervis DB potřebujete nainstalovat toolbox: | ||
| + | * {{ : | ||
| + | * Zobrazení nápovědy ke každé z funkcí je možné: <code matlab> | ||
| + | |||
| + | === Kód === | ||
| + | |||
| + | <code matlab MervisDB_GetData_example.m> | ||
| + | mervisDB = MervisDatabase(' | ||
| + | |||
| + | % Time interval definition | ||
| + | from = localMatlab2utcMatlab(datenum(2017, | ||
| + | to = localMatlab2utcMatlab(datenum(2017, | ||
| + | samplePeriod = 5*60; % 5 minutes | ||
| + | outputTimeZone = ' | ||
| + | |||
| + | % Specifying varibles to download | ||
| + | varKeys1 = {' | ||
| + | ' | ||
| + | varKeys2 = {' | ||
| + | ' | ||
| + | |||
| + | variable1 = MervisDbVariable(varKeys1); | ||
| + | variable2 = MervisDbVariable(varKeys2); | ||
| + | |||
| + | arrayOfVarKeys = [variable1; variable2]; % array of MervisDbVariables objects | ||
| + | |||
| + | % help for function getData | ||
| + | help MervisDatabase.getData | ||
| + | |||
| + | % Download required data | ||
| + | [data, time] = mervisDB.getData(arrayOfVarKeys, | ||
| + | |||
| + | % Get all variables with defined keys | ||
| + | allVaribales = mervisDB.getAllVars(varKeys1);</ | ||
| ==== PHP ==== | ==== PHP ==== | ||
| - | <code php MervisDB_GetData_example.php><? | + | === Kód === |
| + | |||
| + | |||
| + | <code php MervisDB_GetData_example.php> | ||
| + | <?php | ||
| /* | /* | ||
| Mervis DB PHP example - getdata | Mervis DB PHP example - getdata | ||
| */ | */ | ||
| try { | try { | ||
| - | | + | |
| $soapClient = new SoapClient(' | $soapClient = new SoapClient(' | ||
| ' | ' | ||
| Řádek 50: | Řádek 465: | ||
| )); | )); | ||
| $soapClient-> | $soapClient-> | ||
| - | | + | |
| $credentials = array( | $credentials = array( | ||
| ' | ' | ||
| ' | ' | ||
| ); | ); | ||
| - | | + | |
| $utcTZ | $utcTZ | ||
| $utcFrom = new DateTime(' | $utcFrom = new DateTime(' | ||
| $utcTo | $utcTo | ||
| - | | + | |
| $valOffset = 0; | $valOffset = 0; | ||
| $valCount | $valCount | ||
| $varOffset = 0; | $varOffset = 0; | ||
| $varCount | $varCount | ||
| - | + | ||
| - | | + | |
| $variablesKey = array( | $variablesKey = array( | ||
| array( | array( | ||
| Řádek 92: | Řádek 506: | ||
| ) | ) | ||
| ); | ); | ||
| - | + | ||
| - | | + | |
| echo " | echo " | ||
| - | | + | |
| $counter = 0; | $counter = 0; | ||
| - | | + | |
| do { | do { | ||
| $response | $response | ||
| Řádek 114: | Řádek 527: | ||
| $valOffset = $response-> | $valOffset = $response-> | ||
| $varOffset = $response-> | $varOffset = $response-> | ||
| - | + | ||
| - | | + | |
| foreach ($response-> | foreach ($response-> | ||
| foreach ($varArray-> | foreach ($varArray-> | ||
| Řádek 124: | Řádek 536: | ||
| } | } | ||
| } | } | ||
| - | + | ||
| - | | + | |
| if (isset($varArray-> | if (isset($varArray-> | ||
| foreach ($varArray-> | foreach ($varArray-> | ||
| Řádek 133: | Řádek 544: | ||
| echo " | echo " | ||
| } | } | ||
| - | | + | |
| } | } | ||
| - | | + | |
| - | } while ($response-> | + | } while ($response-> |
| } while ($response-> | } while ($response-> | ||
| } | } | ||
| Řádek 142: | Řádek 553: | ||
| print_r($e); | print_r($e); | ||
| } | } | ||
| - | ?></ | + | ?> |
| + | </ | ||
| + | |||
| + | \\ | ||