Ejemplo n.º 1
0
        private static string CustomFields(IActivity activity, ActivityInfo activityInfoInstance, string field)
        {
            string fieldValue = "";

            ICustomDataFieldObjectType type = CustomDataFieldDefinitions.StandardObjectType(typeof(IActivity));

            foreach (ICustomDataFieldDefinition definition in
                CalculatedFields.GetLogBook().CustomDataFieldDefinitions)
            {
                if (definition.Name.ToUpper() == field && definition.ObjectType == type)
                {
                    if (activity.GetCustomDataValue(definition) == null)
                    {
                        fieldValue = "null";
                    }
                    else
                    {
                        if (definition.DataType.Id == CustomDataFieldDefinitions.StandardDataTypes.NumberDataTypeId)
                        {
                            fieldValue = Double.Parse(activity.GetCustomDataValue(definition).ToString()).ToString(CultureInfo.InvariantCulture.NumberFormat);
                        }
                        else if (definition.DataType.Id == CustomDataFieldDefinitions.StandardDataTypes.TextDataTypeId)
                        {
                            fieldValue = activity.GetCustomDataValue(definition).ToString().Escape();
                        }
                        else if (definition.DataType.Id == CustomDataFieldDefinitions.StandardDataTypes.TimeSpanDataTypeId)
                        {
                            fieldValue = TimeSpan.Parse(activity.GetCustomDataValue(definition).ToString()).TotalSeconds.ToString(CultureInfo.InvariantCulture.NumberFormat);
                        }
                    }
                }
            }

            return fieldValue;
        }
Ejemplo n.º 2
0
        public bool boGetExported(IActivity activity)
        {
            if (activity != null)
            {
            #if !ST_2_1
                int? ExportedCustData = (int?)(activity.GetCustomDataValue(FunbeatExportedField) as double?);
            #else
                int? ExportedCustData = null;
            #endif

                // Upgrade from old to new method of marking an activity to be exported
                if (ExportedCustData == null)
                {
                    // Check if metadata string exists and update the cust data field
                    bool boExported = (activity.Metadata.Source.IndexOf("Funbeated") >= 0);
            #if !ST_2_1
                    if (boExported)
                        activity.SetCustomDataValue(FunbeatExportedField, (double?)1.0);
                    else
                        activity.SetCustomDataValue(FunbeatExportedField, (double?)0.0);
            #endif
                    return boExported;
                }
                else
                {
                    return (ExportedCustData != 0);
                }
            }
            else
                return false;
        }
Ejemplo n.º 3
0
        private static string AthleteFields(IActivity activity, ActivityInfo activityInfoInstance, string field)
        {
            string fieldValue = "";

            var athleteEntry = CalculatedFields.GetLogBook().Athlete.InfoEntries.LastEntryAsOfDate(activity.StartTime);

            switch (field)
            {
                case "ATHLETEBMI":
                    fieldValue = athleteEntry.BMI.ToString(CultureInfo.InvariantCulture.NumberFormat);
                    break;
                case "ATHLETEBODYFATPERCENTAGE":
                    fieldValue = athleteEntry.BodyFatPercentage.ToString(CultureInfo.InvariantCulture.NumberFormat);
                    break;
                case "ATHLETECALORIES":
                    fieldValue = athleteEntry.CaloriesConsumed.ToString(CultureInfo.InvariantCulture.NumberFormat);
                    break;
                case "ATHLETEDATE":
                    fieldValue = "\"" + athleteEntry.Date.ToShortDateString() + "\"";
                    break;
                case "ATHLETEDIARY":
                    fieldValue = "\"" + athleteEntry.DiaryText.Escape() + "\"";
                    break;
                case "ATHLETEDIASTOLICBLOODPRESSURE":
                    fieldValue = athleteEntry.DiastolicBloodPressure.ToString(CultureInfo.InvariantCulture.NumberFormat);
                    break;
                case "ATHLETESYSTOLICBLOODPRESSURE":
                    fieldValue = athleteEntry.SystolicBloodPressure.ToString(CultureInfo.InvariantCulture.NumberFormat);
                    break;
                case "ATHLETEINJURED":
                    fieldValue = athleteEntry.Injured.ToString();
                    break;
                case "ATHLETEINJUREDTEXT":
                    fieldValue = "\"" + athleteEntry.InjuredText + "\"";
                    break;
                case "ATHLETEMAXHR":
                    fieldValue = athleteEntry.MaximumHeartRatePerMinute.ToString(CultureInfo.InvariantCulture.NumberFormat);
                    break;
                case "ATHLETEMISSEDWORKOUT":
                    fieldValue = athleteEntry.MissedWorkout.ToString();
                    break;
                case "ATHLETEMISSEDWORKOUTTEXT":
                    fieldValue = "\"" + athleteEntry.MissedWorkoutText + "\"";
                    break;
                case "ATHLETEMOOD":
                    fieldValue = athleteEntry.Mood.ToString(CultureInfo.InvariantCulture.NumberFormat);
                    break;
                case "ATHLETERESTHR":
                    fieldValue = athleteEntry.RestingHeartRatePerMinute.ToString(CultureInfo.InvariantCulture.NumberFormat);
                    break;
                case "ATHLETESICK":
                    fieldValue = athleteEntry.Sick.ToString();
                    break;
                case "ATHLETESICKTEXT":
                    fieldValue = "\"" + athleteEntry.SickText.Escape() + "\"";
                    break;
                case "ATHLETESKINFOLD":
                    fieldValue = athleteEntry.Skinfold.ToString(CultureInfo.InvariantCulture.NumberFormat);
                    break;
                case "ATHLETESLEEPHOURS":
                    fieldValue = athleteEntry.SleepHours.ToString(CultureInfo.InvariantCulture.NumberFormat);
                    break;
                case "ATHLETESLEEPQUALITY":
                    fieldValue = "\"" + athleteEntry.SleepQuality.ToString(CultureInfo.InvariantCulture.NumberFormat) + "\"";
                    break;
                case "ATHLETEWEIGHT":
                    fieldValue = athleteEntry.WeightKilograms.ToString(CultureInfo.InvariantCulture.NumberFormat);
                    break;

                case "ATHLETEHEIGHT":
                    fieldValue = CalculatedFields.GetLogBook().Athlete.HeightCentimeters.ToString(CultureInfo.InvariantCulture.NumberFormat);
                    break;
                case "ATHLETESEX":
                    fieldValue = "\"" + CalculatedFields.GetLogBook().Athlete.Sex.ToString() + "\"";
                    break;
                case "ATHLETEBIRTHDATE":
                    fieldValue = "\"" + CalculatedFields.GetLogBook().Athlete.DateOfBirth.ToShortDateString() + "\"";
                    break;
                case "ATHLETEAGE":
                    DateTime now = activity.StartTime.ToUniversalTime() + activity.TimeZoneUtcOffset;
                    DateTime birth = CalculatedFields.GetLogBook().Athlete.DateOfBirth;

                    int years = now.Year - birth.Year;

                    if (now.Month < birth.Month || (now.Month == birth.Month && now.Day < birth.Day))
                    {
                        --years;
                    }

                    fieldValue = years.ToString(CultureInfo.InvariantCulture.NumberFormat);
                    break;
            }

            ICustomDataFieldObjectType type = CustomDataFieldDefinitions.StandardObjectType(typeof(IAthleteInfoEntry));

            foreach (ICustomDataFieldDefinition definition in
                CalculatedFields.GetLogBook().CustomDataFieldDefinitions)
            {
                if (definition.Name.ToUpper() == field && definition.ObjectType == type)
                {
                    if (athleteEntry.GetCustomDataValue(definition) != null)
                    {
                        if (athleteEntry.GetCustomDataValue(definition) == null)
                        {
                            fieldValue = "null";
                        }
                        else
                        {
                            if (definition.DataType.Id == CustomDataFieldDefinitions.StandardDataTypes.NumberDataTypeId)
                            {
                                fieldValue = Double.Parse(athleteEntry.GetCustomDataValue(definition).ToString()).ToString(CultureInfo.InvariantCulture.NumberFormat);
                            }
                            else if (definition.DataType.Id == CustomDataFieldDefinitions.StandardDataTypes.TextDataTypeId)
                            {
                                fieldValue = athleteEntry.GetCustomDataValue(definition).ToString().Escape();
                            }
                            else if (definition.DataType.Id == CustomDataFieldDefinitions.StandardDataTypes.TimeSpanDataTypeId)
                            {
                                fieldValue = TimeSpan.Parse(activity.GetCustomDataValue(definition).ToString()).TotalSeconds.ToString(CultureInfo.InvariantCulture.NumberFormat);
                            }
                        }
                    }
                }
            }

            return fieldValue;
        }
Ejemplo n.º 4
0
 public void GetCustomFieldsData(IActivity activity, 
     out int? RPE,
     out double? TE,
     out int? Repetitions,
     out int? Sets)
 {
     if (activity != null)
     {
         RPE = (int?)(activity.GetCustomDataValue(RPEField) as double?);
         TE = activity.GetCustomDataValue(TEField) as double?;
         Repetitions = (int?)(activity.GetCustomDataValue(RepetitionsField) as double?);
         Sets = (int?)(activity.GetCustomDataValue(SetsField) as double?);
     }
     else
     {
         RPE = null;
         TE = null;
         Repetitions = null;
         Sets = null;
     }
 }