Community
Showing results for 
Search instead for 
Do you mean 
Reply

Counting Time - Histories List

Copper Super Contributor
Posts: 478
Country: Australia

Counting Time - Histories List

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++;
                    }

 


Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Nickel Contributor
Posts: 175
Country: USA

Re: Counting Time - Histories List

What exactly are you trying to achieve? Are you trying to get an average duration per type? If so, I'd suggest making two lists of Longs, one for each type. Then inside the If's, add the difference of endT and actualEnd (in ticks) to the list. Then you should be able to just run list.Average() to get the average. This is assuming that you are using .NET 4.0, as I don't recall when the Average method was added to the generics. Hopefully this helps.
Copper Super Contributor
Posts: 478
Country: Australia

Re: Counting Time - Histories List

Thanks for your comment back

I am basically trying to expand my "time card" code so that it sums up the time spent on a client file for each activity type

At the moment i have a field in which you put the year, from there the code goes and counts 7 different types for that year eg: Type A is Emails, faxes and Letters, Type B is ToDos

As its sorting through the list could it also add together the duration for the matching types??

Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Nickel Contributor
Posts: 175
Country: USA

Re: Counting Time - Histories List

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.

Copper Super Contributor
Posts: 478
Country: Australia

Re: Counting Time - Histories List

Thanks for the message back

As you may have guessed my coding ability is rather new and takes me a while to muddle my way through it.. to start with i did not even think of using the two times I was focused on the duration field

My work is all contact focused so at the moment once it counts all the types the code puts them into fields in the contact view so i can see them when i open the contact

For this to work i will also need to modify the "timeless" activities

Ok let me muddle my way through this

again thanks for the points, will let you know how i go

Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Copper Super Contributor
Posts: 478
Country: Australia

Re: Counting Time - Histories List

I managed to workout the C# code to create the list and add to it from the Type A section, but the summary is causing me problems

Specifically it does not like the .Sum() part claiming that there is no such option

Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Nickel Contributor
Posts: 175
Country: USA

Re: Counting Time - Histories List

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;
        }

 

Copper Super Contributor
Posts: 478
Country: Australia

Re: Counting Time - Histories List

4.5 if i remember correctly from way back when i started this

Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Copper Super Contributor
Posts: 478
Country: Australia

Re: Counting Time - Histories List

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

 


Jason Dawson Financial Planning
Brisbane | Australia - JDFP Home Page

Act Ver - Act! Premium Version 17.1.169.0, Hot Fix 3
OS - Windows 7 (stand alone machine)
MS Office - Enterprise 2007
Phone - Samsung Galaxy s6
Nickel Contributor
Posts: 175
Country: USA

Re: Counting Time - Histories List

Well, I'm not sure what is going on there, as I just tried out using a List<long> in a test app targeting 3.5 and it was there too. My guess is that you are targeting .NET 2.0. If that's the case, you should be able to just grab the Sum function I posted previously and use that instead.