|
I am trying to set the datasources for comboboxes.
There is a datasource in the first, but not in the second. If I flip them around, I get the opposite effect.
|
|
|
|
|
Sorry for the confusion, there are errors.
Exception thrown: 'System.FormatException' in mscorlib.dll
Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe
Exception thrown: 'System.InvalidCastException' in mscorlib.dll
Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe
Exception thrown: 'System.FormatException' in mscorlib.dll
Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe
Exception thrown: 'System.NullReferenceException' in ResourcePlanningC2.exe
Exception thrown: 'System.FormatException' in mscorlib.dll
The program '[12772] ResourcePlanningC2.exe' has exited with code -1 (0xffffffff).
It must be hanging on some null values. Is there an easy way to handle this?
|
|
|
|
|
I think I got it, Thanks for the help!
var q =
from a1 in dt_Jobs.AsEnumerable()
orderby a1.Field<String>("City")
where (a1.Field<String>("City") != null)
select a1.Field<String>("City");
var lstCity = q.Distinct().ToList();
cboCity.DataSource = lstCity;
|
|
|
|
|
Hi.
Just a quick question, what way do you prefer in connecting database to your web application? Is it through class or config file?
What are the advantages and drawbacks?
Thank you for answering.
|
|
|
|
|
That isn't a question: the two are not comparable.
A config file is where you store your connections string so you don't have to change your application code at all for different environments: you just edit the config file and insert the correct connection string.
A class is an code element, which in C# you have no choice at all to use or not use as the whole language is class based.
So how do you suggest that it could be "one or the other"?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thank you for the clarification. So there is really no effect at all when it comes to what is more reliable in connecting to the database server.
|
|
|
|
|
We cannot answer your question properly because you haven't made clear what your question really is. You might know what you're asking us but your question makes so little sense that it's impossible to answer properly. To reiterate what Griff said, you cannot do anything with a database from configuration as that's all it is, configuration. In order to connect to a database, you need to have code that actually handles things such as getting records out of the database, updating it and so on - even if you were to map your entire database in configuration, there still has to be some code somewhere that actually handles the "talking to the database part".
Now, what I think you're actually asking is, is it better to store the connection information in the configuration, or in a class? Is that the question?
This space for rent
|
|
|
|
|
|
Dear coder/Mathematician folk,
I have a question on how to best peak search a series of noise like points. The points are stored as doubles in a double array. The points represent voltage levels in dBuV.
I'm not a mathematician and I have limited knowledge regarding the elegancie's of how C# can be put to handle complex problems. Or maybe not so complex to some
I would like 'n' points returning that have a delta from there neighbours of >= 6dB and within a specified window of 'm' points.
The window allows us to reject all peaks regardless of delta bar the point with the highest peak.
As we go through the data points we look at each point [DP] with respect to its neighbour. If the delta to left neighbour [P1] is >= 6dB and delta to right neighbour [P2] is >= 6dB we have a peak.
if either neighbours delta is less than 6dB we may have a slope condition. We must there for ride the slope with respect to [P2] goint up and down the troughs until we hit a transition and the delta from [P2] is >= 6dB. This would be our next point.
We repeat the process though all points returning just the peaks that are separated by the window width and have clear >= 6dB margin from there neighbours.
The following data represents a typical trace. Only points 9,11, and 24 are real points that should be returnd.
double[] trace = new double[] {47.92370605,44,49,46.31715393,44.98129654,46.17653275,78,73,82,63,69,41.72979736,41.13000488,41.49586487,37,40,30,40.79894257,40.65593719,41.37298584,39.13498688,55,51,60,39.3440094,38.51491547,42,35.12589264};
I hope I explained things clearly. Please feel free to ask for any clarifications
Many thanks for your time and effort
Nigel
|
|
|
|
|
So, what code do you have so far? What is the problem that you are trying to solve (e.g., is your logic too slow)?
This space for rent
|
|
|
|
|
Hi Pete,
Thanks for getting back to me,
I have a modified peak search function that returns peak/troughs.
public static IEnumerable<Tuple<int, double>> LocalPeakMinMax(IEnumerable<double> source, int windowSize)
{
if (windowSize < 2) windowSize = 2;
windowSize = windowSize - windowSize % 2 + 1;
int halfWindow = windowSize / 2;
int index = 0;
var before = new Queue<double>(Enumerable.Repeat(double.NegativeInfinity, halfWindow));
var after = new Queue<double>(source.Take(halfWindow + 1));
foreach (double d in source.Skip(halfWindow + 1).Concat(Enumerable.Repeat(double.NegativeInfinity, halfWindow + 1)))
{
double curVal = after.Dequeue();
if (before.All(x => curVal > x ) && after.All(x => curVal >= x ))
{
yield return Tuple.Create(index, curVal);
}
else
if (before.All(x => curVal <= x) && after.All(x => curVal < x))
{
yield return Tuple.Create(index, curVal);
}
before.Dequeue();
before.Enqueue(curVal);
after.Enqueue(d);
index++;
}
}
The problem is I cannot figure out how best to filter out all the chaff and return the peaks that align with the prescribed logic explained in my original post.
I was going to take the output from this and play with it but it was getting messy. I was hoping the community may be able to come up with a more elegant solution. The code isn't slow at all, quite the opposite. At least with the 625 points i'm currently playing with.
Br
Nigel
modified 1-Feb-18 5:22am.
|
|
|
|
|
Searching for peaks, and using your example here, the following code gives you the results you expect:
double[] trace =
{
47.92370605, 44, 49, 46.31715393, 44.98129654, 46.17653275, 78, 73, 82, 63, 69, 41.72979736, 41.13000488,
41.49586487, 37, 40, 30, 40.79894257, 40.65593719, 41.37298584, 39.13498688, 55, 51, 60, 39.3440094,
38.51491547, 42, 35.12589264
};
for (int i = 1; i < trace.Length - 1; i++)
{
double deltaLeft = trace[i - 1];
double deltaRight = trace[i + 1];
if (trace[i] - deltaLeft >= 6 && trace[i] - deltaRight >= 6)
{
Console.WriteLine($"Peak at {i + 1}");
}
} You may notice that I don't start at 0 and I don't finish at the last element in the array; as it's assumed that you will always have a left and right value, this is sufficient.
This space for rent
|
|
|
|
|
Hi Pete,
Many thanks for looking into this for me.
This is a great attempt but its using a sliding window observing the points immediately adjacent the current point.
If you change data point p8. from 73 to 77, you would observe that the peak at p9. level 82 is no longer detected. p9. is still a legitimate peak as it is 6dB above p6 and p10. The peak would have changed from being 3 points wide to 5 points wide. Think of a peak as an noisy parabola which could be represented with >= 3 points. If the peak to troughs are less than 6dB then they all form part of the same emissions. The seperation points being when the emissions lobes descend to >= -6dB.
Hope this helps and thanks again for your help.!
Br
Nigel
|
|
|
|
|
Please don't repost if your message does not appear immediately: both of these went to moderation and required a human being to review them for publication. In order to prevent you being kicked off as a spammer, both had to be accepted, and then I have to clean up the spares. Have a little patience, please!
I've deleted one version.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Sorry, I had no idea I had double posted. Possible lag at my end.
Thanks for the head up.
|
|
|
|
|
Ah, I see. That wasn't quite what your initial post described. So, effectively, you're pinning a value and as long as the next value continues the trend of moving upwards (as an example), we keep going until we hit the maximum. As soon as the value moves in the opposite direction, we repin the value we're comparing against. Does that sound right to you?
This space for rent
|
|
|
|
|
Hi Pete,
That is almost correct. If the value changes direction from say north to south but the distance south is < 6 from the pinned max then the trend should remain northerly until the change south from the pinned value is >= 6.
E.g. south 5 north 3 south 5 constitutes a southerly trend and north 5 south 3 north 5 constitutes a positive trend even though the direction is changing. The trend only shifts in the opposite direction once we get to pinned <=6.
Hope that's clearer
Best Regards
Nigel
|
|
|
|
|
Sounds like you just need to loop through the array, doing a single check for each item?
Member 12616185 wrote: The following data represents a typical trace. Only points 9,11, and 24 are real points that should be returnd. Hehe, so you are requesting code?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi Eddy,
I have code that returns the peaks and troughs but not the window/peak excursion implementation. I was hoping there would be an elegant way to do this in maybe linq.
I posted my current code in a previous reply. It returns the peaks and troughs.
I could post process this in a bunch of loops but it was getting messy so I decided to request help from the Brain, AKA codeproject c# forum
Kind Regards
Nigel
|
|
|
|
|
Converting things to LINQ does not always make them more "elegant". Keep it readable and simple
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Your spot on with that assessment LINQ isn't everything, and by elegant I meant not done with a 100 for/if loops etc. If it can be done in LINQ then great . I'm just blowing my brain trying to conceptualise the best way of doing this in code.
Br
Nigel
|
|
|
|
|
Nigel_Davison wrote: LINQ isn't everything, and by elegant I meant not done with a 100 for/if loops etc. LINQ will do the same, just in another form of notation.
If you need to inspect a list of values, a loop will be somewhere. Also doesn't look like you have that much loops/branches yet. If it works, it works
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hey Eddy
>> "Also doesn't look like you have that much loops/branches yet"
Yes, but the code I posted only retrieves the peak maxima/minima. It doesn't respect the 6dB peak excursion requirement.
>> "If it works, it works"
Couldn't have put it better myself
Br
Nigel
|
|
|
|
|
Krellon wrote: It doesn't respect the 6dB peak excursion requirement. Did you mean "exclusion"?
Given the list you return, which (simple) steps should I do on paper to satisfy your requirement? I was assuming you'd just check the previous and following values and add them to a list of the delta is bigger than 6 doorbells.
The simpeler the explanation, the simpeler the code (usually)
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi Eddy,
If you stick the following data into Excel and plot it. Then place markers on the 9th 11th and 24th point you would see what I was after.
double[] trace = new double[] { 47.92370605, 44, 49, 46.31715393, 44.98129654, 46.17653275, 78, 73, 82, 63, 69, 41.72979736, 41.13000488, 41.49586487, 37, 40, 30, 40.79894257, 40.65593719, 41.37298584, 39.13498688, 55, 51, 60, 39.3440094, 38.51491547, 42, 35.12589264 };
If I could embed an image into my comment I would show you.
Your essentially looping through an array of points looking for the biggest and smallest peaks and waiting for the delta either side them to go >= 6dB. When it does you grab the biggest peak between the -6dB points. Rinse and repeat.
So,
1,6,3,7,1 would yield a peak at p[4] = 7 with a window size of 5.
1,7,1 would yield a peak at p[2] = 7 with a window size of 3.
1,-3,-2,7,5,1 would yield a peak at p[4] = 7 with a window size of 4.
1,-7,1,-6 would yield 2 peaks. One at p[1] = 1 with a window size if 2 and one at p[3] with a window size of 3.
stick them all together and you get
1,6,3,7,1,1,7,1,1,-3,-2,7,5,1,1,-7,1,-6
Peaks at p[4], p[7], p[12] and p[17]
Respective window sizes in points would be, 5, 3, 4 and 3
Hope that's helps
Br
Nigel
|
|
|
|
|