|
I am developing an internet cafe software and i want to know how can i get the total minutes from datetime1 to datetime2
for example:
14 Jun 2008 19:20:15 to 15 Jun 2008 21:53:45
|
|
|
|
|
This will work:
TimeSpan span = t2 - t1;
double minutes = span.TotalMinutes;
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
(datetime2 - datetime1).MinutesTotalMinutes like Greeeg said
Sorry for the mistake
Eslam Afifi
modified on Sunday, June 15, 2008 2:51 PM
|
|
|
|
|
|
in my country, our currency is (Dinar) and we have small units called fils (three decimals)
we have coins 50fils and 100fils
1 Dinar (BD) is 1,000 fils (10 coins)
I want to round to the nearest 50 or 100 fils based on user's setting.. for example:
if the amount is 0.513 and round is 50 then it will be 0.550 but if round to 100 it will be 0.600
if the amount is 1.148 and round is 50 then it will be 1.150 but if round to 100 it will be 1.200
how can i do that?
|
|
|
|
|
This is not rounding; you're taking the ceiling to 0.05 or 0.1 (in case it's not an integer amount of money)
A hint,
0.513 ceiling to 0.05 = 0.5 + 0.05 = 0.55
1.148 ceiling to 0.1 = 1.1 + 0.1 = 1.2
But you want 1.000 to return 1.000 not 1.05 or 1.1 so you'll take that into account. And use decimal not float or double.
Eslam Afifi
|
|
|
|
|
there is a class, say
class a
{
int i,j,k;
}
then, another class is derived as,
class b:a
{
int a,b,c;
}
now how many locations in the memory the object of class b will occupy, i mean wat will be the size of object of class b.
3 or 6 ???
i have tried to use sizeof operator.
But the compiler is giving error !
|
|
|
|
|
|
|
You're welcome.
Eslam Afifi
|
|
|
|
|
Well
I have a problem with converting.
I would like to convert 96.78 to int. I used Convert.ToInt32(total) and it turned out 97. I want my result is 96. I also used String.format but it has the same result.
|
|
|
|
|
Do you always want the value rounded down? Then use Math.Floor :
Convert.ToInt32(Math.Floor(total)
modified 12-Sep-18 21:01pm.
|
|
|
|
|
(Int32)96.78 will return 96, as desired.
|
|
|
|
|
I'm looking for an implementation or example or even just the logic for what must be an extremely common scenario:
Suppose we have N objects (where N is large). These objects are being accessed over time, but the pattern of access changes. Some are more popular at one time of the day, another i more popular at another time.
I would like to have a list of the top M (M << N) most requested objects for the last T minutes.
Keeping a log of all requests for all objects for the last T minutes is inpractical. Even keeping a list M items long in memory is stretching the friendship. It needs to be fast and efficient.
It doesn't need to be 100% accurate. Just close.
I've got something close based on rolling averages but it's not quite right. I know as soon as the answer is given I'll go 'Why didn't I think of that' but my brain is stuck, possibly because of the Adam Sandler movie I watched last night.
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
Sounds like you need a Priority Queue[^] (Wikipedia Link[^]), as used in many scheduling algorithms (process creation and much more). Each access to an object in the queue should increase the object's priority (could be a property, like a time stamp).
Or did I misunderstand your problem?
regards
modified on Sunday, June 15, 2008 11:50 AM
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I don't have much experience and this is primitive and slow and it’s certainly not what you’re looking for but here are my thoughts anyway. You have N objects and you want to get the top M of N each T period. I think you would associate an integer with each object and keep them in a list or something. Each time an object is accessed you increase the integer. Each T period you sort them and get the top M instead of maintaining them in a sorted structure.
About the rolling averages, this is the first time I hear about this and I don’t understand it. Doesn’t it depend on storing the last average and calculating a new average based on the current one? It’d be great if you explain it a little. Thank you.
Eslam Afifi
|
|
|
|
|
A moving average (or rolling average) is used when you are accumulating data and you take an average of the short-term data rather than averaging all the data you accumulated. It's a way of "smoothing out" data that can fluctuate wildly when all you really want to know is the short-term trend of the data. There are various ways to approximate and weight the average of the data as it comes in rather than actually re-calculating all the data as it changes.
I've done this a lot when writing stock analysis software. Here[^] is a graph of the last six months of eBay stock values (in blue) with a "10-day moving average" (in red). See how it smooths out the data to show the short term trends?
For the original poster's application, I guess you could use a rolling average if you don't want a particular entry shooting right to the top if you suddenly start using a bunch of times but rather have it slowly drift towards the top if you continue to use it over a period of time.
If you don't like the results your rolling average is giving you, maybe you can try one of the variations like a weighted moving average or an exponential moving average. Try Wikipedia[^]for some of the theory/math.
|
|
|
|
|
Thank you for the reply. The chart of eBay is about days (the set of object) and a value for each day (the blue line) and the 10-day MA (the red line); despite I don't know how it's calculated, I can't see the relation between the average and getting the top M number of days N according to the values
Or do I get it wrong?
Eslam Afifi
|
|
|
|
|
Eslam Afifi wrote: I think you would associate an integer with each object
This requires an entry for every object. What if I have, say, 4 billion objects?
Eslam Afifi wrote: Each T period you sort them and get the top M instead of maintaining them in a sorted structure
Unfortunately this means that your list is, by definition, always out of date (by anything between 0 and T minutes)
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
Chris Maunder wrote: This requires an entry for every object. What if I have, say, 4 billion objects?
I didn't realize that N is that big. But like I said, I don't have much experience, but I think you will keep track of how many times an object has been accessed in the past T period. I don't know about rolling average and it'd be great if you point out the relation between it and what you're trying to accomplish.
Chris Maunder wrote: Unfortunately this means that your list is, by definition, always out of date (by anything between 0 and T minutes)
Then I guess you'll keep them in a SortedList or something.
Eslam Afifi
|
|
|
|
|
Chris - there is a way that you can do this, but it's going to rely on using some technology hacks. Let's assume that each object has a unique identifier. Now, every time the object is accessed, write the id and date/time that the object has been accessed to a message queue. Next, read from the message queue and update a database server based on these values.
Periodically, prune and summarise the values in the database - so, every N minutes, you'll pick the top M objects and write a summary of this information to a table - then delete the old entries. The beauty of this approach is that you can spread the load of this processing.
|
|
|
|
|
I thought about this but I want it in-memory. The load on the database will be way too high.
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
It really depends how many objects you are talking about - if it's the billions mentioned above, then you've no chance. You would have to track every one to see if there are multiple accesses - even if 99.99999999% are only accessed once, you still have to track them.
BTW - the reason for using the messagequeue is that you can control/throttle how much throughput you want in there, so you could load data in bursts.
|
|
|
|
|
Never mind - I need to get my brain back into gear here. Basically, what you have is an optimisation problem - effectively you've got a matrix MxN, where M represents the number of objects and N represents the accesses. What you could do is create a sparse matrix, whereby you would put the value in and the time you last access time for each accessed object. Now, every so often you will want to iterate over this list and remove those objects that haven't been accessed since the last collection. At this point, you have a sparse matrix.
|
|
|
|
|
Bingo
[Except I just thought of a way, way faster way of doing it using some stats we keep elsewhere. I know - unfair posing a problem and not telling you about the ace up my sleeve ]
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|