Calculated Fields

by camel

Downloads: 23,628 (9) • Reviews: 4

Version:

1.2.9.4

Updated:

Apr 11, 2011

Complex formula (activity type, month, distance, elevation)

Complex formula (activity type, month, distance, elevation)

Postby Tisztul_A_Visztula » Mon May 28, 2012 12:10 pm

Is it possible to code the following logics to a formula using Calculated fields? I wish to calculate 2 scores (Score_Gross and Score_Filtered) of each activity using the method defined by our national association of nature friends.

1. Let us check the month of the activity. If it is December, January, February, then the Score1 is 3, else Score1 is 0.

2. If the activity type is hiking OR running, Score2=Distance_in_km*1.5+Total_Ascents_in_m*0.02
if the activity type is cycling, Score2=Distance_in_km*0.5+Total_Ascents_in_m*0.01

3. I plan to manually record two fields called Cycling_distance_on_unpaved_roads_in_km and Cycling_ascent_on_unpaved_roads_in_m.
Score3=Cycling_distance_on_unpaved_roads_in_km*0.5+Cycling_ascent_on_unpaved_roads_in_m*0.01

4/a. Score_Gross=Score1+Score2+Score3
4/b if (Sum of Score_Gross's of all the activities on the same day >=20) then Score_Filtered=Score_Gross else Score_Filtered=0

So that is it. My first fear is linked to whether there is any formula to use the month of the Activity Date, my second concern is that how I can have a conditional Score_Filtered depending on the Sum of Score_Gross's on the same day.

What do you think, experts of this plugin? Should I give it up or is it possible to code my formula
Cheers,
Zoltan
Tisztul_A_Visztula
 
Posts: 524
Joined: Thu Jul 15, 2010 8:38 am
Location: Hungary

Re: Complex formula (activity type, month, distance, elevati

Postby camel » Sun Jun 03, 2012 3:45 am

Hi here is an formula to get a month as a number from activity:
DateTime.Parse({Date}).Month

Other things are probably possible if you calculate something earlier than other calculations that need that calculated field?

Just get me know what else you have a problem with.
If you want to calculate something for actual day with x activities you can probably use Aggregate functions. Just right click on expressions or see some examples
camel
Donated!
Donated!
 
Posts: 363
Joined: Tue May 18, 2010 7:14 am
Location: Slovakia

Re: Complex formula (activity type, month, distance, elevati

Postby Tisztul_A_Visztula » Sun Jun 03, 2012 12:34 pm

OK, I started with "1. Let us check the month of the activity. If it is December, January, February, then the Score1 is 3, else Score1 is 0."

I just have read some posts in this plugin forum, checked some websites about C# and created a formula hoping that it exactly does what I wished

It is
(((DateTime.Parse({Date}).Month) = 1) || ((DateTime.Parse({Date}).Month) = 2) || ((DateTime.Parse({Date}).Month) = 12)) ? 3 : 0

but it doesnt work.


EDIT: OK I got it, "=" must be like ":=" in freepascal and "==" is what I looked for.
Last edited by Tisztul_A_Visztula on Sun Jun 03, 2012 3:53 pm, edited 1 time in total.
Cheers,
Zoltan
Tisztul_A_Visztula
 
Posts: 524
Joined: Thu Jul 15, 2010 8:38 am
Location: Hungary

Re: Complex formula (activity type, month, distance, elevati

Postby Tisztul_A_Visztula » Sun Jun 03, 2012 1:12 pm

Two new questions:

1. Which is the order of the calculation of the fields? Is it based on alphabetical order of the custom fields or the order of the custom fields in logbook properties?

2. Is there a way to refer to the data of the neighbouring previous activity?
Cheers,
Zoltan
Tisztul_A_Visztula
 
Posts: 524
Joined: Thu Jul 15, 2010 8:38 am
Location: Hungary

Re: Complex formula (activity type, month, distance, elevati

Postby Tisztul_A_Visztula » Tue Jul 03, 2012 3:22 am

Tisztul_A_Visztula wrote:Two new questions:

1. Which is the order of the calculation of the fields? Is it based on alphabetical order of the custom fields or the order of the custom fields in logbook properties?

2. Is there a way to refer to the data of the neighbouring previous activity?



After a month I would answer to my questions based on my experience.

1. Still dunno it.

2. I think there is not
Cheers,
Zoltan
Tisztul_A_Visztula
 
Posts: 524
Joined: Thu Jul 15, 2010 8:38 am
Location: Hungary


Return to Calculated Fields

Who is online

Users browsing this forum: No registered users and 1 guest