I am using http://antaris.github.io/RazorEngine/ to generate strings from a template and am having trouble calling functions within the template. The documentation on the site is a bit lacking with examples, but I am trying to call the double ToString function with a format. The format string is:
"The value of sensor #Model.Measurement.Sensor.Description is out of spec with a value of ((double)#Model.AdjustedValue).ToString(\"#.##\")"
The last part of the string I would like the output to be rounded to the nearest hundredth, but instead of I am getting the following string:
"The value of sensor Test_sensor_1 is out of spec with a value of ((double)78.14215625).ToString("#.##")"
Could someone point out the correct syntax for what I am trying to achieve.
Your # is in the wrong place, I think:
"The value of sensor #Model.Measurement.Sensor.Description is out of spec with a value of #(((double)Model.AdjustedValue).ToString(\"#.##\"))"
Related
I'm currently working withing C# to put images in my api database (school project) and I want to store ISO, Aperture and Shutterspeed as well. Now those are stored in the metadata as APEX or EXIF and not the 'normal' values. I've already did some research and found a way to calculate the Aperture: var value = Math.Round(Math.Pow(2,apexValue/2),1); but it makes rounding fault for some (5.7 instead of 5.6, 22.6 instead of 22, ...) and so I was wondering if there is an easy way to convert those to the values know by people (aperture to f-stops, shutterspeed to seconds, iso to iso values)?
At this point, I'm looking into Property Item Descriptions but I'm a bit confused by them because if we take Aperture for example: the property is called: PropertyTagExifAperture and so you would think that it is an Efix value but the description states: Lens aperture. The unit is the APEX value. So what is it then, Efix or APEX?
Thanks for your time!
I'm trying to use ISpannable in a Monodroid project but am having problems with GetSpans. What I'm ultimately after is a Rich Text editor such as at:
https://code.google.com/p/android-richtexteditor/source/browse/?r=4#svn/trunk/src/net/sgoliver
However, the Xamarin documentation for GetSpans isn't particularly helpful. The line I'm trying to convert from Java to C# is:
StyleSpan[] ss = s.getSpans(styleStart, position, StyleSpan.class);
However, I don't know what to pass for the last parameter as writing StyleSpan.class in C# gives a compile error of "} expected". What can I pass in to the last parameter to get all spans, or all spans of a particular type?
The C# equivalent should be Java.Lang.Class.FromType(typeof(StyleSpan)).
I need to do a "fuzzy" image comparison in c# - I have used ImageMagick.NET for stuff in the past and know it's good for the job.
There is a compare command in Image Magick: http://www.imagemagick.org/script/compare.php
And there is a Compare(Image reference) method in ImageMagick.NET however it seems that it's be hugely simplified so there is no way of getting at the verbose output.
I need to be able to get at that so I can match the images using a threshold. Am I missing something - is there a way to get this stuff into ImageMagick.NET if there isn't already? (I'm no C++ dev by a long shot) or am I barking up the wrong tree?
Pardon me if I don't get your question, but won't IsImagesEqual or SimilarityImage work?
IsImagesEqual returns "The normalized maximum quantization error for any single pixel in the image. This distance measure is normalized to a range between 0 and 1. It is independent of the range of red, green, and blue values in your image.
A small normalized mean square error, accessed as image->normalized_mean_error, suggests the images are very similar in spatial layout and color."
The corresponding method in the .NET bindings is Image.Compare which takes an image and returns a bool. However, if the result is false - the mean error (according to the metric above) is set on the current instance's meanErrorPerPixel, normalizedMaxError, and normalizedMeanError.
Aren't these three metrics enough to give you the result of your "fuzzy" compare?
I'm trying to build a "simple" web app that calculates either a male or females body fat % based on the U.S. Navy's circumference formula. I have the majority of the app completed at this point. However, I cannot figure out why the way I've setup the formula below won't work. Two of the values are underlined in red in my .cs file.
My Formula:
TBBodyFat.Text = Convert.ToString(495 / (1.0324-.19077(Math.Log(Convert.ToDouble(TBWaist.Text)-Convert.ToDouble(TBNeck.Text)))+.15456(Math.Log(Convert.ToDouble(TBHeight.Text)))));
Original Example:
%Fat=495/(1.0324-.19077(log(abdomen-neck))+.15456(log(height)))-450
Pop-Up for the two underlined values (.19077 and .15456):
struct System.Double
Represents a double-precision floating-point number.
Error:
Method name expected
TBBodyFat.Text = Convert.ToString(495 / (1.0324-.19077*
(Math.Log(Convert.ToDouble(TBWaist.Text)-Convert.ToDouble(TBNeck.Text)))+.15456*
(Math.Log(Convert.ToDouble(TBHeight.Text)))));
C# (not any programming language I've yet encountered) does not take adjacency of numbers to mean multiplication!
Well you need to use "*" for multiplication. Plus I'm not sure whether C# allows ".123" style numeric literals without leading 0.
Try:
TBBodyFat.Text =
Convert.ToString(495/
(1.0324-0.19077*(Math.Log(Convert.ToDouble(TBWaist.Text)-Convert.ToDouble(TBNeck.Text)))+0.15456*(Math.Log(Convert.ToDouble(TBHeight.Text)))));
Put * while multiplying like .8*(b-200) .If you will put directly .8(b-200) it will show error that method name expected.
In an application, I have to use a valid identity string as a value of a property. I mean the string should be a valid identity name in C#.
For I want to use the string as a formula without change the source code of the component, I have to convert ANY formula, a string, to a valid identity string and convert it back when needed.Of course, when a formula is a valid identity name, the converting function should return it directly.
For example, the formula is Price*Quantity, and the converted value is Price__char_99__Quantity.
For example, the formula is Price, and the converted value is Price.
Maybe there is such a function already there, but I took hours and failed to find it out. I guess in XML functions or string codes convertion, there must be some similar one.
Please give me a hand.
Thank you in advance.
Ying
I would be easier if you create a new class, Formula, rather than attempt to use a string for your forumla property. The Formula class would hold the original text of the formula as a property, so you would not need to convert. You can then create a List to hold any number of Forumula objects. This would be much easier to do than your current solution.