Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add multipitch support #350

Merged
merged 22 commits into from
Oct 16, 2023
Merged

Conversation

l4u532
Copy link
Contributor

@l4u532 l4u532 commented Aug 5, 2023

Problem

(See #266)

For a given multi-pitch climb, for each pitch, we want to represent multiple boltsCount and grades, e. g. grade = ["6a", "6c", "5c", "6c"], and boltsCount = [4, 6, 3, 3], and possible other data (like description).

Solution

Introduce type Pitch (with fields parentIdtypenumbergradelengthboltsCountdescription) as a child to climb, so that climb gets an optional Array Climb.pitches containing each pitch; this has the most flexibility and allows for detailed per-pitch data, plus it wouldn't break any existing implementation

Example JSON Doc Schema

type Climb {
  id: ID!
  uuid: ID!
  name: String!
  ...
  pitches: [Pitch]!  # new pitches array of type Pitch
}

The Type Pitch would contain:

type Pitch {
  uuid: ID!
  parentId: ID!
  number: Int!
  grades: GradeType!
  type: ClimbType!
  length: Int!
  boltsCount: Int
  description: String
}

@l4u532 l4u532 changed the title Add multipitch support WIP: Add multipitch support Aug 6, 2023
@l4u532 l4u532 marked this pull request as ready for review August 23, 2023 15:10
@l4u532 l4u532 marked this pull request as draft August 24, 2023 11:03
@l4u532 l4u532 changed the title WIP: Add multipitch support Add multipitch support Aug 24, 2023
@l4u532 l4u532 marked this pull request as ready for review August 24, 2023 13:55
@l4u532
Copy link
Contributor Author

l4u532 commented Aug 24, 2023

@musoke Would you kindly have a look? Thank you =)

@l4u532 l4u532 force-pushed the add-multipitch-support branch 3 times, most recently from 8ea30d3 to 4ce0c36 Compare August 25, 2023 06:51
@l4u532 l4u532 changed the title Add multipitch support feat: add multipitch support Aug 26, 2023
@vnugent vnugent self-requested a review August 26, 2023 23:09
@vnugent
Copy link
Contributor

vnugent commented Aug 29, 2023

@l4u532 I'll have a look at this issue by this weekend

Copy link
Contributor

@musoke musoke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to reread #266 to remind myself of all the nuances discussed previously. This looks good, although I haven't run it myself.

We discussed allowing a pitch to be part of multiple routes, to account for variations, etc. Does this PR allow for that to be added in future? The number and parent fields assume only one parent route.

src/db/ClimbSchema.ts Outdated Show resolved Hide resolved
default: function () { return this._id.toString() }
},
parentId: { type: String, required: true },
number: { type: Number, required: true },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is number? Is this to track the order of the pitches?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it from the rest of the changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

number is to track the sequence of pitches. It is also only required field besides id and parentId. The reasoning: the correct sequence of information is essential for multi-pitches. A user might only add the pitches' grades; but it is prime that she does so in correct order, else the value of information is almost zero.

Since this seems to be non-intuitive, should I rename this field for more clarity? E. g. pitchNumber? (Suggestions welcome)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use something else besides number to avoid conflict with number in Typescript. pitchNumber sounds good. At first I thought pitch number isn't needed since we can get them from the array index. But in some case it may not be easy to get the index. Glad you thought of it.

src/model/__tests__/MutableClimbDataSource.ts Show resolved Hide resolved
@l4u532
Copy link
Contributor Author

l4u532 commented Aug 30, 2023

I had to reread #266 to remind myself of all the nuances discussed previously. This looks good, although I haven't run it myself.

We discussed allowing a pitch to be part of multiple routes, to account for variations, etc. Does this PR allow for that to be added in future? The number and parent fields assume only one parent route.

See #350 (comment) for my reply.

Copy link
Contributor

@vnugent vnugent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@l4u532 Thank you very much for this PR, and I apologize for my delayed response. I left my feedback inline.

src/db/ClimbSchema.ts Outdated Show resolved Hide resolved
default: function () { return this._id.toString() }
},
parentId: { type: String, required: true },
number: { type: Number, required: true },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use something else besides number to avoid conflict with number in Typescript. pitchNumber sounds good. At first I thought pitch number isn't needed since we can get them from the array index. But in some case it may not be easy to get the index. Glad you thought of it.

src/db/ClimbSchema.ts Outdated Show resolved Hide resolved
boltsCount: { type: Number },
description: { type: String }
}, {
_id: true,
Copy link
Contributor

@vnugent vnugent Sep 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should remove _id: true since we will be providing our own UUID. _id: true means Mongo will auto-generate _id for us in ObjectID format (not UUID).

Copy link
Contributor Author

@l4u532 l4u532 Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vnugent I have incorporated all changes and would be happy to get your re-review, especially on lines 77-81, since I am not sure if I have interpreted your suggestions correctly: https://github.com/OpenBeta/openbeta-graphql/pull/350/files#diff-9b4028942ce1d106899ff51138cc6ee7cc75ea36110257394c51424643261967R77-R81

src/db/ClimbSchema.ts Outdated Show resolved Hide resolved
@l4u532 l4u532 force-pushed the add-multipitch-support branch 2 times, most recently from 2ca8e03 to 4fd8509 Compare September 15, 2023 16:08
@l4u532 l4u532 requested a review from vnugent September 15, 2023 16:10
src/db/ClimbTypes.ts Outdated Show resolved Hide resolved
src/graphql/resolvers.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@vnugent vnugent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updating the code. I think we're very close now. I left some comments inline.

@l4u532
Copy link
Contributor Author

l4u532 commented Sep 24, 2023

Thanks for the updating the code. I think we're very close now. I left some comments inline.

Incorporated the requested changes.

FYI, there is a phenomenon which I do not yet quite understand. I assume its harmless. When updating pitches, "id" is added - additionally to "_id":

    pitches: [
        {
            id: 'a011077d-58bd-4edd-9d9c-e5f3a4520add', # <-- duplicate, when updating the pitch
            parentId: UUID("97737f2ddac94ecda7645490ec1c40a0"),
            pitchNumber: 1,
            grades: {
                ewbank: '19'
            },
            type: {
                sport: false,
                alpine: true
            },
            length: 20,
            boltsCount: 6,
            description: 'Updated first pitch description',
            _id: UUID("a011077d58bd4edd9d9ce5f3a4520add") # <-- original
        },

@l4u532 l4u532 requested a review from vnugent September 24, 2023 13:26
src/model/MutableClimbDataSource.ts Outdated Show resolved Hide resolved
@vnugent
Copy link
Contributor

vnugent commented Sep 25, 2023

FYI, there is a phenomenon which I do not yet quite understand. I assume its harmless. When updating pitches, "id" is added - additionally to "_id"

As mentioned the spread operator ...pitch in the db update code introduces the id field.

Once you fix that, we're good to merge. I think we may need to create an additional create/update/delete pitch API to make it easier to work with pitch data.

@l4u532
Copy link
Contributor Author

l4u532 commented Oct 3, 2023

FYI, there is a phenomenon which I do not yet quite understand. I assume its harmless. When updating pitches, "id" is added - additionally to "_id"

As mentioned the spread operator ...pitch in the db update code introduces the id field.

Once you fix that, we're good to merge. I think we may need to create an additional create/update/delete pitch API to make it easier to work with pitch data.

Sorry for the belated fix, I was on vacation. I am kindly asking you to review this hopefully final fix :) @vnugent

@vnugent
Copy link
Contributor

vnugent commented Oct 4, 2023

I'm traveling at the moment. Will get back to you by next week.

@vnugent vnugent merged commit 9a08eec into OpenBeta:develop Oct 16, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants