02-08-2015 02:47 PM
Hi everyone
I have some code that counts the different history types and records them in the contact screen, all works good, but now i am trying to add the ability to count the duration of the history records at the same time
Frankly i am at a loss as to how to handle dates and time for this
Any one able to provide assistance???
// Create a list of Histories
HistoryList h1 = oApp.ActFramework.Histories.GetHistories(null, c, false);
//Cycle through Histories List for each type
foreach (History h in h1)
{
DateTime actualEnd = h.EndTime;
// Type A
if ((actualEnd.Date >= startT.Date) && (actualEnd.Date <= endT.Date) && (h.HistoryType.Name == typeA1 || h.HistoryType.Name == typeA2 || h.HistoryType.Name == typeA3))
{
hisCountA++;
}
// Type B
if ((actualEnd.Date >= startT.Date) && (actualEnd.Date <= endT.Date) && (h.HistoryType.Name == typeB1 || h.HistoryType.Name == typeB2))
{
hisCountB++;
}
02-09-2015 05:38 AM
02-09-2015 12:55 PM
02-09-2015 01:21 PM
I don't see any problems with what you are trying to do. The code you posted initially would be the hard part in my opinion (e.g. differentiating the types). Once you have that done, it's just a matter of how you want to store the values. When dealing with differences in time, I like to use Long variables, as that's how the values are stored internally. This also makes it very easy to get differences (i.e. durations in your case) since it's just a math operation on two values.
Here's how I'm thinking it over (warning: pseudo VB "code"):
Dim typeADurations, typeBDurations, typeCDurations as new List(of Long) 'your code for types '. '. '. 'Inside type A logic Dim duration as Long duration = ActivityEnd.Ticks-ActivityStart.Ticks 'ActivityEnd/Start are your datetime variables for the given activity or history typeADurations.Add(duration) 'the rest of your code for types 'Summary code Dim typeATotal as TimeSpan typeATotal = New TimeSpan(typeADurations.Sum()) Messagebox.show("Total time spent on type A: " & typeATotal.ToString()) 'display in messagebox the total time spent on type A tasks
I could easily see this being used per contact to create a data table of each contact with the time spent for each type of task. Then you could total the time per type over all of the contacts and do other aggregate functions on the data for a pretty quick analysis too (such as in a spread sheet).
You could do all of this in your own, in-code DataTable as well. It's really up to you how you want to store the values for your summary processing.
02-09-2015 01:33 PM
02-09-2015 09:41 PM
02-10-2015 05:35 AM
What .NET Framework are you targeting? I believe those LINQ extensions were added in 4.0. That's not a huge deal, as you can always write your own.
private long Sum(List<long> numbers) { long total = 0; foreach (long l in numbers) { total += l; } return total; }
02-10-2015 12:14 PM
02-10-2015 12:34 PM
Ok this is the code so far
List<long> typeADuration = new List<long>(); . . . //History List code . . . // Type A if ((actualEnd.Date >= startT.Date) && (actualEnd.Date <= endT.Date) && (h.HistoryType.Name == typeA1 || h.HistoryType.Name == typeA2 || h.HistoryType.Name == typeA3)) { long duration; duration = h.EndTime.Ticks - h.StartTime.Ticks; typeADuration.Add(duration); hisCountA++; } . . //Each history type Code . . //Type A summary TimeSpan typeATotal; typeATotal = new TimeSpan(typeADuration.Sum()); int Total1 = hisCountA + hisCountB; string hisCount1 = Total1.ToString(); c.Fields["CUST_ContactTable1_090144.CUST_EmailSent_072620355", true] = hisCount1;
It really does not like the .Sum()
I added that second bit of code but it still does not recognise it, I googled last night and found lots of references to there being no .Sum, tried several other soluation from online but they just became worse.
Its got to be something really simple i am missing here
02-10-2015 01:07 PM