def test_set_mark_with_no_mark_string_field_event(self):
     entry_lj = Entry(mde=self.mde_longjump, athlete=self.athlete)
     db.session.add(entry_lj)
     db.session.commit()
     entry_lj.set_mark()
     self.assertEqual(entry_lj.mark, 0)
     self.assertEqual(entry_lj.mark_type, "inches")
     self.assertEqual(entry_lj.mark_to_string(), "")
    def test_set_mark_with_no_mark_string_track_event(self):
        entry_1600m = Entry(mde=self.mde_1600m, athlete=self.athlete)
        db.session.add(entry_1600m)
        db.session.commit()
        entry_1600m.set_mark()

        # Test when no mark is provided for the event
        self.assertEqual(entry_1600m.mark, INFINITY_SECONDS)
        self.assertEqual(entry_1600m.mark_type, "seconds")
        self.assertEqual(entry_1600m.mark_to_string(), "")
Example #3
0
def parse_entry(tokens, meet):
    """
    Parses a "D-Line" in a Hytek entry file that corresponds to an athlete's
    entry into a particular event within a meet.

    D-Line format
    <Token#> <Data> <MaxChar>  <Description>
    0   D           1   Individual Entry Record
    1   Last Name   20  (Required)
    2   First Name  20  (Required)
    3   Initial     1   (Optional)
    4   Gender      1   M = Male, F = Female (Required)
    5   Birth Date  10  MM/DD/YYYY (Optional)
    6   Team Code   4   4 characters max; use UNA if unknown (Required)
    7   Team Name   30  Use Unattached if unknown (Required)
    8   Age         3   Age is optional if birth date provided
    9  School Year  2   (Optional for HyTek, but not for TMS)
    10  Event Code  10  Examples: 100, 5000S, 10000W, SP, HJ, DEC
    11  Entry Mark  11  Time: hh:mm:ss.tt (1:23.44.55, 1:19.14, 58.83, 13.4h)
                        Field Metric: 12.33, 1233;
                        Field English: 12-10.25", 12', 121025, 12' 10
                        Combined-event: 3020 (points)
    12  Mark measure 1  M for Metric, E for English (Required if Entry Mark
                        provided)
    """

    if len(tokens) < 11:
        error(f"HyTek D-Line requires at least 11 fields. <{tokens}>")

    (_junk1, last_name, first_name, middle, gender, _junk2, team_code,
     team_name, _junk3, grade, ht_event_code) = tokens[0:11]

    athlete = Athlete.add_athlete_to_db(first_name, middle, last_name, gender,
                                        grade, team_code, team_name)

    # If the athlete's record in file was bad, add_athlete_to_db returns None.
    if athlete is None:
        warning(f"Skipping athlete {first_name} {last_name}")
        return

    # translate the HyTek event names into TMS event codes
    event_code = ht_event_translator.get(ht_event_code, ht_event_code)

    q = MeetDivisionEvent.query
    try:
        mde = q.filter_by(meet_id=meet.id,
                          event_code=event_code,
                          div_id=athlete.division.id).one()
    except NoResultFound:
        raise TmsError("MDE doesn't exist: meet #{}, event {}, div {}".format(
            meet.id, event_code, athlete.division.code))

    entry = Entry(athlete=athlete, mde=mde)
    # we need to commit here, or else we can't see the event in the below call
    # of entry.set_mark method.
    db.session.add(entry)
    db.session.commit()
    info(f"Added entry: {entry}")

    # If the athlete's entry includes a seed mark for this event, set it
    if len(tokens[11:13]) == 2:
        entry.set_mark(mark_string=tokens[11], mark_measure_type=tokens[12])

    # I don't understand why, but at this point the entry thinks its "event"
    # attribute is "None", even after I setup the relationship with the mde,
    # which should also get me the event. I believe this shoudl be possible
    # without adding the entry to the session and commiting.
    db.session.commit()
    info("Set entry's mark. Entry: {}. Mark:{}".format(entry.event.code,
                                                       entry.mark_to_string()))