Measurement conversion on the fly - measurement

I'd like to ask re: measurement conversion on the fly, here's the detail :
Requirement: To display unit measurement with consider setting.
Concerns:
- Only basic (neutral) unit measurement is going to be stored in database, and it is decided one time.
The grid control has direct binding to our business object therefore it has complexity to do conversion value.
Problem:
How to display different unit measurement (follow a setting), consider that controls are bind to business object?
Your kind assistance will be appreciated. Thank you
ikadewi

If I've understood your question correctly (you are a little vague...) you want to store measurement data in one way, but give the users the option to display it in different ways (using different units). You don't specify which technology/language environment you're using, but there is (at least) one pretty straightforward way to do this: create a converter class.
Here's some pseudo-C# skeleton code if your measurement data is lengths, stored in millimeters. You can probably figure out how to use the same approach for whatever you're measuring, and however you want to display it:
class LenghtConverter {
double ToCentimeters(double millimeters) {
// 1 centimeter = 10 millimeters
return millimeters / 10;
}
double ToInches(double millimeters) {
// 1 inch = 25.4 millimeters
return millimeters / 25.4
}
// You get the drift. Add whatever conversions you need. If you wish,
// you can return strings instead of numbers, and append the unit
// signature as well.
}
Now, in your grid you display your data with some kind of presentation syntax. I'm making something up to give you an idea, and since I'm into ASP.NET the syntax is pretty similar to that. Hope you'll excuse me for that =)
Instead of just
<%= MyMeasurement.Data %>
to display the measurement data in the way it was stored, you output with
<%= LenghtConverter.ToInches(MyMeasurement.Data) %>
which will display the result in inches.
If you're actually using C# (or VB.NET, I suppose) there is a nice feature available in .NET 3.5 called Extension Methods that you might want to use instead. That would let you output with the somewhat cooler and more streamlined syntax
<%= MyMeasurement.Data.ToInches() %>

I have a QML Qt C++ UI. It interfaces with a back-end application.
UI supports both Imperial & Metric modes. User can make this selection from UI at runtime.
User can view and edit data values via the UI.
Back-end application works only in Imperial mode.
A C++ utility object is exposed to QML as a context property. This utility object has methods to:
Set and Get the System of measurement.
Convert unit string from Imperial to Metric. Example: °F to °C.
Convert data value from Imperial to Metric and Metric to Imperial. Example: Fahrenheit to Celsius -> 50 to 10, Celsius to Fahrenheit -> 0 to 32.
C++ data object has these 2 properties:
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY(QString unitString READ unitString NOTIFY unitStringChanged)
// value - In Imperial mode, you get Imperial value. In Metric mode, you get Metric value.
// unitString - In Imperial mode, you get Imperial units. In Metric mode, you get Metric units.
QVariant data::value()
{
// fetch Imperial data value from back-end application
// get current System of measurement
// if current System of measurement is Metric, convert data value from Imperial to Metric
// return data value
}
QString data::unitString()
{
// fetch Imperial unit from back-end application
// get current System of measurement
// if current System of measurement is Metric, convert unit from Imperial to Metric
// return unit
}
void data::setValue(QVariant value)
{
// get current System of measurement
// if current System of measurement is Metric, convert value from Metric to Imperial
// write value to back-end Controller application
}

Related

Dynamic results from query builder

I am working on a search filter atm where people can specify things like (example) size, color, fabric and so on.
Obviously I have models for each i.e. size, color and fabric. But since this "search" should return every result i.e. size + color + fabric and not just one of the three I would need to make a new struct which contains all the (size, color and fabric) to be able to consume the result that Gorm would return.
Since we have a LOT of filters, this could get very messy. Does anyone know if there is a better way to do it? or what would be a best practice to do this?
type Result struct {
ID int
Name string
Age int
}
var result Result
db.Raw("SELECT id, name, age FROM users WHERE name = ?", 3).Scan(&result)
The above example illustrates how I think it should be done, but as you can expect with the amount of data I need to return this struct would become huge.
The results are quite large in terms of data. I mean what I would want in return in the final version for example (this is about sales):
What products were bought, the amount, color and size. Payment data i.e. price, tax, payment method. Customer information, et cetera.
So in total there is a lot of information to store.
All this information should be returned as a JSON format so we can call it through an API call.
Each call should give back 100 up to 15.000 results, to give you an idea of the side of the data.
Hope someone can explain a bit about a best practice method and -or how I should solve this problem as I am unsure on how to code this effectively.

How to pass an Image from GUI1 to GUI2 in MATLAB

This must be easy but for some reasons I can't get this to work.
What I have is 2 GUIs namely GUI1 and GUI2.
In GUI1 I read and stored an Image in say A. It also has a PushButton. Now when I click this Button it should show that image in GUI2's axes1.
I tried setappdata and getappdata but it ends up giving error. I can't understand the syntax. I'm all new to MATLAB. Any help is appreciated.
setappdata / getappdata are discussed in more detail below.
As mentioned in the comments, you can use setappdata(0, ... / getappdata(0, ... to assign/read data to/from the root object.
Excerpted from MATLAB User Interfaces - Passing Data Around User Interface. The original authors were Suever and Hoki. Attribution details can be found on the contributor page. The source is licenced under CC BY-SA 3.0 and may be found in the Documentation archive. Reference topic ID: 2883 and example ID: 9775.
Passing Data Around User Interface
Most advanced user interfaces require the user to be able to pass information between the various functions which make up a user interface. MATLAB has a number of different methods to do so.
guidata
MATLAB's own GUI Development Environment (GUIDE) prefers to use a struct named handles to pass data between callbacks. This struct contains all of the graphics handles to the various UI components as well as user-specified data. If you aren't using a GUIDE-created callback which automatically passes handles, you can retrieve the current value using guidata
% hObject is a graphics handle to any UI component in your GUI
handles = guidata(hObject);
If you want to modify a value stored in this data structure, you can modify but then you must store it back within the hObject for the changes to be visible by other callbacks. You can store it by specifying a second input argument to guidata.
% Update the value
handles.myValue = 2;
% Save changes
guidata(hObject, handles)
The value of hObject doesn't matter as long as it is a UI component within the same figure because ultimately the data is stored within the figure containing hObject.
Best for:
Storing the handles structure, in which you can store all the
handles of your GUI components.
Storing "small" other variables which need to be accessed by most callbacks.
Not recommended for:
Storing large variables which do not have to be accessed by all
callbacks and sub-functions (use setappdata/getappdata for
these).
setappdata/getappdata
Similar to the guidata approach, you can use setappdata and getappdata to store and retrieve values from within a graphics handle. The advantage of using these methods is that you can retrieve only the value you want rather than an entire struct containing all stored data. It is similar to a key/value store.
To store data within a graphics object
% Create some data you would like to store
myvalue = 2
% Store it using the key 'mykey'
setappdata(hObject, 'mykey', myvalue)
And to retrieve that same value from within a different callback
value = getappdata(hObject, 'mykey');
Note: If no value was stored prior to calling getappdata, it will return an empty array ([]).
Similar to guidata, the data is stored in the figure that contains hObject.
Best for:
Storing large variables which do not have to be accessed by all
callbacks and sub-functions.
UserData
Every graphics handle has a special property, UserData which can contain any data you wish. It could contain a cell array, a struct, or even a scalar. You can take advantage of this property and store any data you wish to be associated with a given graphics handle in this field. You can save and retrieve the value using the standard get/set methods for graphics objects or dot notation if you're using R2014b or newer.
% Create some data to store
mydata = {1, 2, 3};
% Store it within the UserData property
set(hObject, 'UserData', mydata)
% Of if you're using R2014b or newer:
% hObject.UserData = mydata;
Then from within another callback, you can retrieve this data:
their_data = get(hObject, 'UserData');
% Or if you're using R2014b or newer:
% their_data = hObject.UserData;
Best for:
Storing variables with a limited scope (variables which are likely to be used only by the object in which they are stored, or objects having a direct relationship to it).
Nested Functions
In MATLAB, a nested function can read and modify any variable defined in the parent function. In this way, if you specify a callback to be a nested function, it can retrieve and modify any data stored in the main function.
function mygui()
hButton = uicontrol('String', 'Click Me', 'Callback', #callback);
% Create a counter to keep track of the number of times the button is clicked
nClicks = 0;
% Callback function is nested and can therefore read and modify nClicks
function callback(source, event)
% Increment the number of clicks
nClicks = nClicks + 1;
% Print the number of clicks so far
fprintf('Number of clicks: %d\n', nClicks);
end
end
Best for:
Small, simple GUIs. (for quick prototyping, to not have to implement the guidata and/or set/getappdata methods).
Not recommended for:
Medium, large or complex GUIs.
GUI created with GUIDE.
Explicit input arguments
If you need to send data to a callback function and don't need to modify the data within the callback, you can always consider passing the data to the callback using a carefully crafted callback definition.
You could use an anonymous function which adds inputs
% Create some data to send to mycallback
data = [1, 2, 3];
% Pass data as a third input to mycallback
set(hObject, 'Callback', #(source, event)mycallback(source, event, data))
Or you could use the cell array syntax to specify a callback, again specifying additional inputs.
set(hObject, 'Callback', {#mycallback, data})
Best for:
- When the callback needs data to perform some operations but the data variable does not need to be modified and saved in a new state.

Bing Maps V8 - How can I rotate map in Bird's Eye view?

I am upgrading from Bing Maps V7 to V8 and rotating the map from JS doesn't work anymore. I have been trying with this piece of code:
map.setView( { heading:90 } );
This works if I change the source URL for the map library to V7. And I see that the "setView" function and the "heading" option still exist in V8.
Here's an article about how to do it in V7:
https://alastaira.wordpress.com/2012/03/28/rotating-bing-maps/
Bing Maps V8 currently doesn't have Birdseye. A new birdseye experience is being introduced to V8 within the next few months. This new experience has a lot of new imagery which uses a different format from the old birdseye experience. Given that the imagery that is in V7 is very old and is a major point of DSAT, it was decided to hold off on adding birdseye to V8 until the next experience and data is available.
I did some more research and two undocumented things have changed.
map.setView() does not respond to a full options object anymore.
Example:
var options = this.map.getOptions();
options.heading = 90;
map.setView(options);
It now needs the heading and other changed fields manually specified to reflect any changes.
map.setView({heading: 90});
map.setView({heading: xx}) no longer accepts negative values as valid so you must manually submit heading values for any clockwise rotations so that it corresponds to the positive heading value.
Thus, map.setView({heading: -90}) was previously smart enough to know that is equivalent to map.setView({heading: 270}), but now must be submitted to the API as a positive value.
Similar to the first example, I have some legacy code for resetting the map back to original lat/lon and heading that now needs a second setView() call in order to update.
var options = this.map.getOptions();
options.zoom = this.initialZoom;
options.center = new Microsoft.Maps.Location(this.lat, this.lon);
options.heading = this.heading = 0;
this.map.setView(options);
this.map.setView({heading: this.heading});
Must call setView another time so that the new heading is actually applied.

In Local Datastore chapter, fromPin and fromlocaldatastore

Just like as title, I want to ask what difference between
fromPin()
and
fromLocalDatastore()
By the way, Pin and datastore two terminologies. What difference between two of them ?
Thanks.
There is a slight difference and you can see it from the docs and from the decompiled code of the Parse library (okay, this last one is more complicated...).
The docs says:
fromLocalDatastore(): Change the source of this query to all pinned objects.
fromPin(): Change the source of this query to the default group of pinned objects.
Here you can see that, interally on Parse, there is a way to get all the objects from the entire set of pinned data, without filters, but also from a so-called "default group". This group is defined in the Parse code with the following string: _default (o'rly?).
When you pin something using pinInBackground, you can do it in different ways:
pinInBackground() [without arguments]: Stores the object and every object it points to in the local datastore.
This is what the docs say, but if you look at the code you'll discover that the pin will be actually performed to the... _default group!
public Task<Void> pinInBackground() {
return pinAllInBackground("_default", Arrays.asList(new ParseObject[] { this }));
}
On the other hand, you can always call pinInBackground(String group) to specify a precise group.
Conclusion: every time you pin an object, it's guaranteed to be pinned to a certain group. The group is "_default" if you don't specify anything in the parameters. If you pin an object to your custom group "G", then a query using fromPin() will not find it! Because you didn't put it on "_default", but "G".
Instead, using fromLocalDatastore(), the query is guaranteed to find your object because it will search into "_default", "G" and so on.

Palm rotation in LeapJS

I wonder how could I get the correct palm rotation angle (along Y-axis) from Leap Motion (I'm using the latest LeapJS API)?
I have tried both rotationAngle(sinceFrame) method and the frame._rotation. However, the rotationAngle() returns a very small value close to 0, which seems to be the rotation angle calculated based on the current frame (how to define the sinceFrame in Leap.loop(function(frame)){}, as it seems only records data from current frame).
And the frame._rotation returns a 3*3 matrix (which I've no idea about what is it, as it's not included in the API documentation). Therefore, I wonder if there's any way to get the correct rotation angle of Y-axis from these methods?
The latest version of the leap.js library includes a roll() function as a member of the Hand object. (It also has pitch() and yaw(), if roll() isn't all you want.) The roll() function is defined as:
Hand.prototype.roll = function() {
return Math.atan2(this.palmNormal[0], -this.palmNormal[1]);
}
As an aside, since you don't need to use rotationAngle() to get the current palm angles, the rotationAngle() function gives you the rotation that has occurred between two frames. For sinceFrame, you can either store a reference to the starting frame or get a past frame from the history buffer maintained by the Controller object. Although the Leap.loop() function doesn't give you access to its Controller object directly, you should be able to create your own. Note that frame._rotation is an internal variable that is used in the calculation of the transformations between two frames. It isn't much use on its own.

Resources