public ObservableCollection<Record> GetTransformedData(ObservableCollection<Row> rows)
        {
            ObservableCollection<Record> records = new ObservableCollection<Record>();

            int index = 0;
            while (index < rows.Count)
            {
                Row row = rows[index];
                DateTime oldestRegistrationDate = Convert.ToDateTime(row.FieldStartDate);

                // zvláštní to věc, kompilátor porovnává typy navzájem
                DateTime? newestLeavingDate = row.FieldEndDate == "" ? null : (DateTime?)Convert.ToDateTime(row.FieldEndDate);
                string birthNumber = row.FieldBirthNumber;

                int oldestRecordIndex = index;
                int newestRecordIndex = index;

                while (index + 1 < rows.Count && rows[index + 1].FieldBirthNumber == birthNumber)
                {
                    index++;
                    row = rows[index];
                    DateTime registrationDateNext = Convert.ToDateTime(row.FieldStartDate);

                    // zvláštní to věc, kompilátor porovnává typy navzájem
                    DateTime? leavingDateNext = row.FieldEndDate == "" ? null : (DateTime?)Convert.ToDateTime(row.FieldEndDate);

                    if (registrationDateNext < oldestRegistrationDate)
                    {
                        oldestRecordIndex = index;
                        oldestRegistrationDate = registrationDateNext;

                    }

                    if (newestLeavingDate != null && (leavingDateNext == null || leavingDateNext > newestLeavingDate))
                    {
                        newestRecordIndex = index;
                        newestLeavingDate = leavingDateNext;
                    }
                }

                row = rows[newestRecordIndex];

                string[] nameArray = GetNameParts(row.FieldName);
                string name = nameArray[NAME_PART_FIRST_NAME];
                string nick = nameArray[NAME_PART_NICK];
                Gender gender = GetGender(row.FieldBirthNumber);
                DateTime birthDate = Convert.ToDateTime(row.FieldBirthDate);
                MemberType membership = GetMembership(row.FieldMemberType);
                Category category = GetCategory(row.FieldCategory);

                Record record = new Record(name, nick, gender, birthDate, oldestRegistrationDate, newestLeavingDate,
                    membership, category);
                records.Add(record);

                index++;
            }

            return records;
        }
Example #2
0
 private bool isOutlier(Record record, double startAge, double leavingAge)
 {
     if (startAge > MAX_START_AGE)
     {
         return true;
     }
     //Debug.Print(record.RegistrationDate.Date.ToString());
     //Debug.Print(FIRST_REGISTRATION_DATE.Date.ToString());
     if (EXCLUDE_UNCOMPLETE_RECORDS && record.RegistrationDate.Date.Equals(FIRST_REGISTRATION_DATE.Date))
     {
         //Debug.Print("fff");
         return true;
     }
     else
     {
         return false;
     }
 }
Example #3
0
 private double getStartAge(Record record)
 {
     double startDaysTotal = record.RegistrationDate.Subtract(record.DateOfBirth).TotalDays;
     double startAge = Math.Round(startDaysTotal / 365, DECIMAL_DIGITS);
     return startAge;
 }
Example #4
0
 private double getLeavingAge(Record record)
 {
     DateTime endDate = record.LeavingDate == null ? DateTime.Now : (DateTime) record.LeavingDate;
     double leavingDaysTotal = endDate.Subtract(record.DateOfBirth).TotalDays;
     double leavingAge = Math.Round(leavingDaysTotal / 365, DECIMAL_DIGITS);
     return leavingAge;
 }