Programmatically Position Image on RDLC using Database Values - database

I have an image that I'd like to programmatically position on an RDLC based on the X and Y values from the database. I originally thought I could just apply an expression to the Left and Top properties of the Location property, however it doesn't seem like there's an option to do that.
Is there anything I can do?
EDIT:
Fortunately the padding property allows expressions, however it seems I have another issue on my hands.
Here's my code for the "Left" property within the "Padding" property group.
=((Sum(Fields!intDessinX.Value, "dsRapport_uspReportCommandeInhumation") * 2.54) / 96) & "cm"
Essentially I'm converting the intDessinX value from the database from pixel to cm using the formula "cm = (pixel * 2.54) / 96" and finally appending "cm" to the end of the expression.
This does not work. I've done some research and can't seem to find how to take the value from a dataset and translate it into a measurement.
Does anyone know how to do this?
Thanks,
Mikael

Solved!! Since we're developing the website in French we had previously set the culture to "fr-CA" and this causes the decimal character to be replaced by a comma character.
As such, when it came time for the reporting engine to evaluate the value (with the comma), it wasn't positioning my image as it simply didn't understand that the value was in fact numeric.

Related

How to convert XML array text items into numbers in ColdFusion?

I am having problems converting XML data into the appropriate data types using a function.
I have read in an XML file using XmlParse().
Within that there is an array which I loop around. <Cfloop array=#i.Task# index="t">
My understanding is that the items in this array are XML text. I can display all the items with CFoutput no problem. One item in the array (BaseLineColor) is a colour. #t.BaseLineColor# However this colour value is a single decimal integer number of varying length. I have worked out the maths to convert this decimal number into R,G,B decimal values. All good so far.
The problem is that if I try mathematical functions on BaseLineColor, then I get:
The value ?xml version="1.0" encoding="UTF-8"? BaseLineColor 255 /BaseLineColor cannot be converted to a number.
So OK I have tried a few methods to try and convert BaseLineColor to an integer but nothing works. Val() doesn't work. In fact I can't seem to convert it into any datatype.
For example, here is me trying to make it a string - same error:
<cfscript>
Strbaselinecolor=toString(t.BaseLineColor);
rdec=floor(Strbaselinecolor / 65536);
gdec=floor((Srtbaselinecolor - rdec * 65536)/256);
bdec=floor(Strbaselinecolor - rdec * 65536 - gdec * 256);
writeOutput("#t.baselinecolor#: #Strbaselinecolor# red #rdec#, green #gdec#, blue #bdec#")
</cfscript>
What function should I be using? Am I supposed to be pre-processing the XML in some way before I can refer to some of these values as integers?
There are a lot of values in the XML data which are numbers (some integers and some floating point numbers) and so it is not just about these items that are colours but a more general problem with using any XML data that is not text. I have tried to find some reference material on this but have not found anything relevant so far. Yet I'm guessing this is a common issue when reading in XML files.
Thanks in advance for any help.
The error message is correct. The code is trying perform mathematical operations on something that is not a number, despite the fact that it may appear to be one in a browser... You're probably getting tripped up by how browsers handle tag based code like xml.
This code (incorrectly) shows the value of t.BaseLineColor as a simple number 255
<cfscript>
t = xmlParse('<?xml version="1.0" encoding="UTF-8"?><BaseLineColor>255</BaseLineColor>');
writeOutput(t.BaseLineColor);
</cfscript>
Runnable Example
However, using a browser's "Inspect Element" tool, reveals the value is actually an xml string. Since browsers treat anything enclosed in < and > as html tags, which aren't rendered, only the number 255 is visible on screen.
writeDump() is more helpful here. It shows t.BaseLineColor as an xml node, and it's value is accessible through the xmlText attribute.
That simple value can be used in mathematical operations.
<cfscript>
t = xmlParse('<?xml version="1.0" encoding="UTF-8"?><BaseLineColor>255</BaseLineColor>');
result = t.BaseLineColor.xmlText / 65536 ;
writeOutput( result );
</cfscript>
Runnable Example

pybrain image input to dataset for Neural Network

I'm trying to write a neural network that (after being properly trained) identifies certain road signs and returns a different output for each type of sign.
Before I started to train my network, I noticed on the pybrain website that their datasets are always an array of values, each entry containing an input and a target. The images I have for my NN have been converted to grayscale pixel data (a simple array of numbers). To train each set of data, do I need to somehow add a target value for each pixel? And if so, how would I go about doing that?
QUICK ANSWER
No, you don't need target for every single pixel, you treat pixels from single image as your input data and you add target to that data.
LONG ANSWER
What you trying to do is to solve classification problem. You have image represented by array of numbers and you need to classify it as some class from limited set of classes.
So lets say that you have 2 classes: prohibitions signs (I'm not native speaker, I don't know how you call signs that forbid something), and information signs. Lets say that prohibition signs is our class 1 and information signs is class 2.
Your data set should look like this:
([representation of sign in numbers], class) - single sample
After that, since it's classification problem, I recommend using _convertToOneOfMany() method of DataSet class, to convert your targets into multiple outputs.
I've answered similar question here, go check it out.

How to remove amounts in thousands in Telerik WPF RadChart?

Using RadChart is assigned at runtime to the same data through a dataset, the result of a database query.
Through code (vb.net) created the series and other settings needed in a conventional bar graph.
The problem:
When values ​​are thousands, the value is represented by a "K". Example: If the value is 1658, the bar shows 1.66 K.
question:
  How to remove the value of "K" and express the number unchanged as it gets?
Thanks
You can try following to remove it
RadChart1.DefaultView.ChartArea.LabelFormatBehavior = LabelFormatBehavior.None;
For More options please refer to this link, I hope this would help.

Programmatically determining max fit in textbox (WP7)

I'm currently writing an eBook reader for Windows Phone Seven, and I'm trying to style it like the Kindle reader. In order to do so, I need to split my books up into pages, and this is going to get a lot more complex when variable font sizes are added.
To do this at the moment, I just add a word at a time into the textblock until it becomes higher than its container. As you can imagine though, with a document of over 120,000 words, this takes an unacceptable period of time.
Is there a way I can find out when the text would exceed the bounds (logically dividing it into pages), without having to actually render it? That way I'd be able to run it in a background thread so the user can keep reading in the meantime.
So far, the only idea that has occurred to me is to find out how the textblock decides its bounds (in the measure call?), but I have no idea how to find that code, because reflector didn't show anything.
Thanks in advance!
From what I can see the Kindle app appears to use a similar algorithm to the one you suggest. Note that:
it generally shows the % position through the book - it doesn't show total number of pages.
if you change the font size, then the first word on the page remains the same (so that's where the % comes from) - so the Kindle app just does one page worth of repagination assuming the first word of the page stays the same.
if you change the font size and then scroll back to the first page, then actually there is a discontinuity - they pull content forwards again in order to fill the first page.
Based on this, I would suggest you do not index the whole book. Instead just concentrate on the current page based on a "position" of some kind (e.g. character count - displayed as a percentage). If you have to do something on a background thread, then just look at the next page (and maybe the prev page) in order that scrolling can be more responsive.
Further to optimise your experience, there are a couple of changes you could make to your current algorithm that you could try:
try a different starting point and search increment for your algorithm - no need to start at one word and to then only add one word at a time.
assuming most of your books are ASCII, try caching the width of the common characters, and then work out the width of textblocks yourself.
Beyond that, I'd also quite like to try using <Run> blocks within your TextBlock - it may be possible to get the relative position of each Run within the TextBlock - although I've not managed to do this yet.
I do something similar to adjust font size for individual textboxes (to ensure they all fit). Basically, I create a TextBlock in code, set all my properties and check the ActualWidth and ActualHeight properties. Here is some pseudo code to help with your problem:
public static String PageText(TextBlock txtPage, String BookText)
{
TextBlock t = new TextBlock();
t.FontFamily = txtPage.FontFamily;
t.FontStyle = txtPage.FontStyle;
t.FontWeight = txtPage.FontWeight;
t.FontSize = txtPage.FontSize;
t.Text = BookText;
Size Actual = new Size();
Actual.Width = t.ActualWidth;
Actual.Height = t.ActualHeight;
if(Actual.Height <= txtPage.ActualHeight)
return BookText;
Double hRatio = txtPage.ActualHeight / Actual.Height;
return s.Substring((int)((s.Length - 1) * hRatio));
}
The above is untested code, but hopefully can get you started. Basically it sees if the text can fit in the box, if so you're good to go. If not, it finds out what percentage of the text can fit and returns it. This does not take word breaks into account, and may not be a perfect match, but should get you close.
You could alter this code to return the length rather than the actual substring and use that as your page size. Creating the textblock in code (with no display) actually performs pretty well (I do it in some table views with no noticeable lag). I wouldn't send all 120,000 words to this function, but a reasonable subset of some sort.
Once you have the ideal length you can use a RegEx to split the book into pages. There are examples on this site of RegEx that break on word boundaries after a specific length.
Another option, is to calculate page size ahead of time for each potential fontsize (and hardcode it with a switch statement). This could easily get crazy if you are allowing any font and any size combinations, and would be awful if you allowed mixed fonts/sizes, but would perform very well. Most likely you have a particular range of readable sizes, and just a few fonts. Creating a test app to calculate the text length of a page for each of these combinations wouldn't be that hard and would probably make your life easier - even if it doesn't "feel" right as a programmer :)
I didn't find any reference to this example from Microsoft called: "Principles of Pagination".
It has some interesting sample code running in Windows Phone.
http://msdn.microsoft.com/en-us/magazine/hh205757.aspx
You can also look this article about Page Transitions in Windows Phone and this other about the final touches in the E-Book project.
The code is downloadable: http://archive.msdn.microsoft.com/mag201111UIFrontiers/Release/ProjectReleases.aspx?ReleaseId=5776
You can query the FormattedText class that is used AFAIK inside textBlock. since this is the class being used to format text in preparation for Rendering, this is the most lower-level class available, and should be fast.

SSRS Dynamic String Expression

I am creating a report where I need to indent a row in a table based on a value from my result set for that row. For example if the value is 0 don't indent at all. If the value is 1 indent by 5 spaces. If 2 indent by a factor 10 spaces, etc.
The way I originally tried to do this is to use something like this:
= Space(Fields!depth.Value * 5) + Fields!name.Value
This works fine when rendered in visual studio but displaying it in the browser window when rendered through reporting services causes those spaces to be removed. I got around this problem before with this tip: http://mssqltips.com/tip.asp?tip=1286.
Any suggestions on how to dynamically control this indentation? I want to be able to do this dynamically with out hard coding numerous IF statements as im trying to make this report flexible enough that I can get any number back for this value.
You could try setting the left padding on the cell in question to an expression like this:
=CStr(2 * Fields!depth.Value) + "pt"
You might have to play with the multiplier since it's points rather than spaces.

Resources