Calculate Average Date

  • Thread starter Thread starter Steve
  • Start date Start date
Hi Jon,

I did not test this last part, and you are right with this one, but I hope
you saw that it had to be.
Did you test this? It doesn't seem to make much sense to me, as you're
no longer adding anything - effectively you end up with the total span
being *exactly* the last span.

About readability, that is a matter of taster and that can be a discussion
from here to the moon.

The sort was very easy and without the disadvantage I tell you now very
usefull, however you cannot get with this methode the index from the
original array and therefore you should build your own Ilist collection.
That I find a much more disadvantage than what you said, but I do not
mention that in a discussion of course.

Cor
 
Cor said:
I did not test this last part, and you are right with this one, but I hope
you saw that it had to be.

Yup - but possibly if the code had been more readable in the first
place you wouldn't have made the error? Maybe if you'd been more
concerned with correctness than brevity?
About readability, that is a matter of taster and that can be a discussion
from here to the moon.

Yes, but I hope you would at least agree that my 6 line version was
less readable than the longer version, and that your idea that shorter
is necessarily better (as exhibited in your challenge to find a shorter
piece of code than yours as a sort of oneupmanship test) is therefore
just plain silly.
The sort was very easy and without the disadvantage I tell you now very
usefull, however you cannot get with this methode the index from the
original array and therefore you should build your own Ilist collection.
That I find a much more disadvantage than what you said, but I do not
mention that in a discussion of course.

So you would advocate copying all the data and then performing a sort,
which is expensive in both time *and* space, rather than the more
obvious (to my mind) method of just going through all the data and
finding the min/max? What possible advantage makes up for the
performance disadvantages?
 
Hi Everyone

I really appreciate all the help that I am receiving with regards to ths
issue, as far as I am concerned the issue is resolved with the example that
I posted based on advice from Jon. The method I use may not be the desired
choice by others, but I understand it and it completes processsing approx
6000 records in my DataGrid in under a second. It won't be run that often
and if it is then it will be only once at a time, but it was important that
I accomplished it.

Thanks again for your help.

Regards,
Steve.
 
Jon,

Do you know what is very annoying that you did not make C# code from Steve
his sample but from my Sample.

This is from Steve

Start/End Dates
myTimeSpan = EndDate.Subtract(StartDate)
myTicks += myTimeSpan.Ticks
Next

You did translate it to this in the same way as in my sample from that time

{TimeSpan diff = (DateTime)ends - (DateTime)starts;
sum += diff;}

span(i) = CDate(enddates(i)).Subtract(CDate(startdates(i)))
totalspan = totalspan.Add(span(i))

And not in the way Steve did.
And that was exactly why I told Steve that there was a better way.

Cor
 
Cor said:
Do you know what is very annoying that you did not make C# code from Steve
his sample but from my Sample.

Sorry, could you rephrase that? I didn't understand it.
This is from Steve

Start/End Dates
myTimeSpan = EndDate.Subtract(StartDate)
myTicks += myTimeSpan.Ticks
Next

You did translate it to this in the same way as in my sample from that time

I didn't "translate" it at all - I wrote what I'd have written in my
own code.
{TimeSpan diff = (DateTime)ends - (DateTime)starts;
sum += diff;}

span(i) = CDate(enddates(i)).Subtract(CDate(startdates(i)))
totalspan = totalspan.Add(span(i))

And not in the way Steve did.
And that was exactly why I told Steve that there was a better way.


.... except you confused things by adding a nasty (IMO) way of finding
the min and the max. If you'd just said "You could actually just add
the timespans together rather than the ticks" then I wouldn't have
disagreed with you at all - indeed I even agreed with that back in an
earlier post:

<quote>
The one benefit your way has (which is indeed a benefit) is that
there's no need to actually take the ticks each time - just sum the
timespans and get the ticks at the end.
</quote>
 
Cor said:
But succeeded in what you always are doing,

What exactly do you mean by that? If you wish to make this a personal
slanging match, I suggest you email me instead.
an OP has taken your wrong advice again.

It's not wrong. It'll work perfectly well. We've improved the code
since then, yes - and the OP may take note of that - but there was
nothing actually *wrong* with the original code.
 
Hi Jon,

You always give me the idea that when I become in a tread with you, you see
me as someone who knows nothing about it.

I had a little bit sorrow when I saw that mail from Steve in the same time
that you agreed that there was a better way, but the difference is not that
important, that I agree.

So forget it,

Cor
 
Back
Top