# Document and test your REST API using OpenAPI/Swagger support in TMS XData

Bookmarks:#### Tuesday, October 10, 2017

TMS XData 2.7 has been just release with lots of new features. The most interesting one, in my opinion, is OpenAPI/Swagger support.TMS XData server can now optionally provide a JSON file containing the OpenAPI Specification (OAS, formerly Swagger) for your whole server API. This opens up a lot of possibilities, usage of several tools of the OpenAPI ecosystem is now possible. Main one would be the Swagger UI, a web front-end to describe and test your API.

**Enabling support for OpenAPI**

To enable OpenAPI support in your server, just use the unit XData.OpenAPI.Service and call the method RegisterOpenAPIService anywhere in your application:

uses {...}, XData.OpenAPI.Service; {...} RegisterOpenAPIService;

**Retrieving the OpenAPI Specification (OAS) file**

The OAS file is available through a GET request to the URL "/openapi/swagger.json" relative to your server root URL. For example, if your server root is http://myserver/tms/xdata/, then you will be able to access the file from this URL:

GET http://myserver/tms/xdata/openapi/swagger.json

**Using Swagger UI**

One of the main use cases is to be able to use the Swagger UI. It's a web-based front-end to dynamically document and test your API. From their website: "Swagger UI allows anyone - be it your development team or your end consumers - to visualize and interact with the API's resources without having any of the implementation logic in place. It's automatically generated from your Swagger specification, with the visual documentation making it easy for back end implementation and client side consumption.".

You can visit their site for more information, but here are quick steps to see it in action from your own server:

**1.**Create your XData Server and enable OpenAPI support as described above.

**2.**Enable CORS in your TXDataServerModule:

Module.AccessControlAllowOrigin := '*';

**3.**Open the existing live demo of the Swagger UI at https://petstore.swagger.io.

**4.**In the edit box that appears at the top of the page, just type the URL that returns the OpenAPI Specification. For example, "http://myserver/tms/xdata/openapi/swagger.json", and click "Explore". That would be enough to list your API.

If you want an even faster way to see it in action with XData:

**1. Run the demo named SQLiteConsoleServer**. It's located in folder demossimple_sqlite. That demo is available when you install TMS XData trial or licensed version.

**2. Open web site https://petstore.swagger.io.**

**3. In the edit box, enter the OAS file address:**"http://localhost:2001/tms/music/openapi/swagger.json":

**4. Click Explore to browse the API and test.**

And that's it!

This new XData release doesn't stop there, there are lots of new features including several new types supported in method parameters, entity properties, PODO properties, and more!

Wagner R. Landgraf

Bookmarks:

#### This blog post has not received any comments yet. Add a comment.

# TMS Analytics for nonlinear multiparametric approximation of surface data

Bookmarks:#### Thursday, October 05, 2017

The new version 2.2 of TMS Analytics and Physics pack contains the nonlinear least squares approximation tools. The nonlinear approximation tasks are widely used in statistics to fit experimental data with some random distribution function.Let us consider the example of surface data fitting with the 2D Gaussian function. The Gaussian distribution of 2 variables x and y (https://en.wikipedia.org/wiki/Gaussian_function) has the following math expression:

Except the amplitude A, the distribution nonlinearly depends on four parameters: center coordinates x0, y0 and deviations sx, sy. The task of fitting data with the Gaussian function is to find optimal values of the four parameters, those minimize the error of the distribution and the experimental data zi(xi,yi), i=1..N.

The approximation task can be solved by the numerical tool with the following code:

var variables, coefficients: TArray; f: string; basis: TNonlinearBasis; cValues: TArray ; appr: TNonlinearApproximator; opt: TSolverOptions; eValues: TArray ; eValue: TFloat; begin variables:= TArray .Create('x', 'y'); // 1 coefficients:= TArray .Create('x0', 'Sx', 'y0', 'Sy'); // 2 f:= 'e^-((x-x0)^2/(2*Sx^2)+(y-y0)^2/(2*Sy^2))'; // 3 basis:= TNonlinearScalarBasis.Create(variables, coefficients, nil, f); // 4 appr:= TGaussNewtonLeastSquares.Create; // 5 appr.C0:= TArray .Create(0.1, 0.1, 0.1, 0.1); // 6 opt:= TSolverOptions.Create(true); opt.MaxIterationCount:= 100; opt.Precision:= 0.2; appr.Options:= opt; // 7 cValues:= appr.Approximate(basis, xyData, zData); // 8 // use basis with optimal coefficients end;

Line 1: Create array of variable names.

Line 2: Create array of four distribution coefficient names.

Line 3: Set up the approximation function expression.

Line 4: Create the nonlinear basis instance with specified data.

Line 5: Create the appropriate nonlinear approximator instance.

Line 6: Set up initial guess of coefficient values for nonlinear solution.

Line 7: Set up appropriate nonlinear solution options.

Line 8: Solve the problem (finding optimal values).

When optimal values of the Gauss distribution parameters found, they can be used with the basis instance to calculate the distribution function in any specified point (x,y) or for other analysis methods, like derivative calculations and so on.

On the pictures below there are results of the approximation made with some generated noisy data. The result presented as 1D section of the 2D function for two different x values: x=0.0 and x=0.6.

In this sample, we used the TMS FNC Chart to display the values and the approximated function. The advantage of using the TMS FNC Chart is that it can be used both for VCL and FMX applications and we can use the same code to create a VCL Windows application or a FireMonkey cross platform application.

The source code of the example application can be downloaded here.

The TMS Analytics and Physics pack version 2.2 includes also many other useful numerical tools: linear least squares approximation, 1D and 2D integration, ordinary differential equation solution, function analysis. Due to the addition of array and matrix support in version 2.2, many numerical calculations can be implemented in vector form with small and compact formulae. The version can be downloaded from the product page.

Bruno Fierens

Bookmarks:

#### This blog post has not received any comments yet. Add a comment.

# TMS Component Pack v8.8 is here

Bookmarks:#### Wednesday, October 04, 2017

What initially started in 1999 as a small bundle of about 15 VCL user interface controls for Delphi, has grown in about 18 years to a set of over 400 powerful and feature-rich components for development of VCL Windows applications with Delphi and C++Builder.Thousands and thousands of hours work went into this VCL component set that found its way to thousands of Delphi & C++Builder developers world-wide and this way, also to thousands of Windows applications used in so many places day-in, day-out to help and improve the life and work of so many people. As a small example, we learned that our VCL Planner is being used to track maintenance schedules of the French trains all over France, all in real-time.

And yet, every day our team continues to improve, extend the TMS Component Pack, assist the users in getting the most out of it and listen carefully to your needs and wishes. Also with the newest v8.8 release, we focused on user needs and added no less than 11 new features in existing components and 3 new components that were requested. We have our feature request logging & voting system for this where customers can add new feature requests and up-vote feature requests from other users so we can set the right priorities in our development.

As a result of this, these 3 new controls were added to TMS Component Pack v8.8:

New : TAdvHighLightLabel v1.0.0.0 : Label that allows to highlight specific words in the label text in different colors.

New : TAdvTouchSpinEdit v1.0.0.0 : Spin edit control with spin buttons left and right from the edit control to allow easy up/down button access from touch screens.

New : TAdvDBListBox v1.0.0.0 : Listbox control with embedded filter + insert data capability that can be bound to a dataset field.

In addition, 11 new features were added to existing components:

- New : Automatic button column type when setting Columns[x].Editor := edButton in TAdvColumnGrid
- New : Hover background, text & border color capability in TAdvResponsiveList
- New : Name property added to TInspectorItem in TMS InspectorBars
- New : InspectorPanel.Items.Item[Name] added to access items by name in TMS InspectorBars
- New : Planner.GridControl.BorderColor: TColor property added in T(DB)Planner
- New : Enabled property added at item level in TTodoList
- New : Property EnableWheel added in TAdvComboBox
- New : ListLeft.Caption, ListRight.Caption properties added in TAdvDualListBox
- New : Lookup, resizable and save function in design time editor in TPictureContainer
- New : Label added in TAdvMultiButtonEdit
- New : Automatic button column type when setting Columns[x].Editor := edButton in TDBAdvGrid

Whether you are using the newest Delphi 10.2.1, C++Builder 10.2.1 or still using an older version of Delphi, our TMS Component Pack installer detects the versions of Delphi or C++Builder installed on your system and will install for any version (from Delphi 7 onwards) it finds.

If you haven't used the TMS Component Pack yet, check out all the feature-rich components you have been missing all this time. If you have used an older verison of the TMS Component Pack, check out all latest additions & improvements and if you have just downloaded & installed the latest version 8.8, check out the new components and features that were added.

Now that TMS Component Pack v8.8 is released, we are already laying out plans for the next version and eagerly awaiting your favorite feature requests or feedback that you can send by email, in our forum or add to our feature request system.

Bruno Fierens

Bookmarks:

#### This blog post has not received any comments yet. Add a comment.

# TMS Data Modeler 3 is out!

Bookmarks:#### Tuesday, October 03, 2017

We are happy to announce that TMS Data Modeler 3 has been released today. TMS Data Modeler is our tool to design databases models, ER diagrams, import existing database schema and, among others, generate source code with TMS Aurelius mapped classes based on the database schema. Below is a list of the new features in this release.**Updated User Interface**

To start with, we have improved user interface, by using a more modern look-and-feel. A new cleaner color theme is used, logo, file menu, splash screen have been updated.

**Customization Script for TMS Aurelius Export**

When generating TMS Aurelius classes from database, you can now fully customize the output source code. Users don’t need to manually tweak the source code anymore, or wait for us to explicitly implement an option that changes how source code is created.

You can simply write a script that is based on event handlers. You can for write the following script to add the [Version] attribute to any field named “FVersion” in all of your classes:

procedure OnColumnGenerated(Args: TColumnGeneratedArgs); begin if Args.Field.Name = 'FVersion' then Args.Field.AddAttribute('Version'); end;

In case you script gets complex, you can also use a full-feature debugger to check what’s wrong with your code.

For the scripting system and debugger, TMS Data Modeler internally uses our scripting frameworks TMS Scripter.

You can refer to documentation for more info on how you can use customization scripts in TMS Data Modeler.

**Export TMS Aurelius classes to multiple units**

In previous versions all TMS Aurelius classes would be exported to a single unit. Now you can choose the name of unit where a specific class will be exported to. TMS Data Modeler will even warn you if there are cyclical references between classes declared in different units.

**Source code preview**

You can now preview the output source code in the TMS Aurelius Export Dialog itself, without needing to generate the source code files to view them. Just click the Preview tab and you will see the final source code generated.

**Separate classes into models**

You can also define to which models each class belongs to. One or more TMS Aurelius Model attributes will be added to each class. If you already have multiple ER diagrams in your Data Modeler project, then you can optionally ask for each diagram to be considered a different model and have your classes be marked automatically with one Model attribute for each diagram it belongs to.

It’s also worth saying that we have updated a lot of internal processes, frameworks and tools. It took a lot of effort. While it’s not directly perceived by the end-user, it doesn’t reflect directly on user experience, we’re sure that it will make release of newer versions easier and faster.

I hope you are excited with these new features as much as we are, and enjoy the new TMS Data Modeler!

Wagner R. Landgraf

Bookmarks:

#### This blog post has not received any comments yet. Add a comment.

# Array and Matrix operations with Analytics 2.2

Bookmarks:#### Tuesday, September 26, 2017

New version 2.2 of TMS Analytics and Physics pack includes total support of operations with N-element arrays and MxN matrices. The operations realized in the Linear Algebra extension package. Array and matrix operations allow advanced calculations with small, compact formulae.Let us consider the examples of using the array/matrix operations for solving some common math/statistics problems. First of all we need to add special variables to the translator instance:

var av: TArray<TFloat>; mv: TArray<TArray<TFloat>>; begin translator:= TTranslator.Create; translator.Add('µ', 0.0); av:=TArray<TFloat>.Create(0.2, -0.1, -0.25, 0.4); translator.Add('A', av); av:=TArray<TFloat>.Create(-0.2, 0.2, -0.1, 0.25, 0.35, 0.15, -0.04, 0.01, -0.12, 0.1); translator.Add('B', av); SetLength(mv, 4, 3); mv[0,0]:= 0.5; mv[0,1]:=-0.4; mv[0,2]:= 0.33; mv[1,0]:=-0.3; mv[1,1]:= 0.1; mv[1,2]:= 0.28; mv[2,0]:=-0.4; mv[2,1]:=-0.2; mv[2,2]:=-0.75; mv[3,0]:=0.44; mv[3,1]:=0.25; mv[3,2]:= 1.00; translator.Add('M', mv); end;

The first problem to solve is calculation of statistics square deviation from the mean value for the ‘B’ array. Math formula for the deviation of discrete random variable is (https://en.wikipedia.org/wiki/Standard_deviation):

where µ is the mean value N is the number of elements.

This formula can be evaluated with using array operations by the following code:

var m, d: TValue; begin m:= translator.Calculate('∑B/#B'); translator.Variables['µ'].Value:= m; d:= translator.Calculate('∑((B-µ)^2)/#B'); // print the ‘d’ value end;

µ = ∑B/#B = 0.06

D = ∑((B-µ)^2)/#B = 0.02876

Next problem is solving an over-determined linear equation system with the least squares approach (https://en.wikipedia.org/wiki/Linear_least_squares_(mathematics)). Let the system is set up by the ‘M’ matrix and the ‘A’ vector. Then the solution ‘X’ is defined by the formula:

where M

^{T}– is the transposed matrix,

^{1}means the inversed matrix.

This formula can be evaluated with the Analytics library as the following

**‘M'*A/(M'*M)’**. Here the apostrophe ‘'’ operator is for transposition operation and the division is equivalent to the multiplication by the inversed matrix. Evaluating the formula we get the following output:

X = M'*A/(M'*M) = TArray<TFloat>[3]=

(0.459953357586789 0.163947437790482 0.113927221302585 )

Here the ‘X’ array is the solution vector that minimizes the square error for the over-determined system.

As can be seen from the examples above, the realized array/matrix operations allow easily solve complicated problems with small, compact formulae. The complicated code for the array/matrix operations implemented inside the Analytics library and totally integrated with analytical evaluations. For an example, linear algebra operations allow solving so called ‘matrix’ ordinary differential equations (https://en.wikipedia.org/wiki/Matrix_differential_equation).

The TMS Analytics and Physics pack version 2.2 can be downloaded here. Total source code of the example application can be downloaded here .

Nancy Lescouhier

Bookmarks:

#### This blog post has received 1 comment. Add a comment.

Previous | Next | Index