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

Loading activity from json #28

Merged
merged 8 commits into from
Oct 1, 2020
Merged

Loading activity from json #28

merged 8 commits into from
Oct 1, 2020

Conversation

gimait
Copy link
Contributor

@gimait gimait commented Sep 30, 2020

This is a first try on loading activity maps from JSON files.

I wanted to create the PR to ask for some feedback about the implementation, please let me know if I can do things in a nicer way.

Currently, no logic on the activities is done, only the mapping from JSON into different classes.

Copy link
Owner

@zayfod zayfod left a comment

Choose a reason for hiding this comment

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

Looks good overall. You've decided to start with a hard one! 🍺

def from_json(cls, data: Dict):
return cls(
choice_type=data['type'],
behaviors=data['behaviors'] if 'behaviors' in data else []
Copy link
Owner

Choose a reason for hiding this comment

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

Consider the following in such cases:

behaviors=data.get('behaviors', [])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is so much nicer, thanks a lot!

# TODO: add score based choice method
pass
else:
print(self.choice_type)
Copy link
Owner

Choose a reason for hiding this comment

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

Raise an exception of some sort.

ignore_if_locked=data['ignoreIfLocked'],
probability_to_require_objective=data['probabilityToRequireObjective'],
random_completions_needed_min=data['randomCompletionsNeededMin']
if 'randomCompletionsNeededMin' in data else None,
Copy link
Owner

Choose a reason for hiding this comment

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

If the default is 0, why pass None here?

Copy link
Owner

Choose a reason for hiding this comment

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

This is the same as `random_completions_needed_min=data.get('randomCompletionsNeededMin')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's None due to copy-paste or autocomplete most likely. I'll correct it.

activity_id=info['activityID'],
activity_type=info['activityType'],
strategy=info['activityStrategy']['type']
)
Copy link
Owner

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is one thing I wanted to ask. In this class, you added some slots. Should I include slots for the non-optional variables in the different activities?

Copy link
Owner

Choose a reason for hiding this comment

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

__slots__ is a way to restrict what fields can be used in a class. Feel free to remove them for now for activities.

def get_activity_files(resource_dir: str) -> List[str]:
activity_files = [resource_dir + '/cozmo_resources/config/engine/behaviorSystem/activities_config.json']
activity_folder = resource_dir + '/cozmo_resources/config/engine/behaviorSystem/activities/'
for root, dirs, files in os.walk(activity_folder):
Copy link
Owner

Choose a reason for hiding this comment

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

As you are not using dirs, use _ instead.

if '//' in line:
wordlist = line.split(' ')
# get all words before '//'
line = ' '.join(wordlist[:wordlist.index('//')])
Copy link
Owner

Choose a reason for hiding this comment

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

Uhh, they are using malformed JSON :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, quite annoying haha I hope they are only using this format for the comments.

Signed-off-by: Aitor Miguel Blanco <[email protected]>
@zayfod
Copy link
Owner

zayfod commented Oct 1, 2020

Looks good. Merge as is?

@gimait
Copy link
Contributor Author

gimait commented Oct 1, 2020

Can be merged, yes, I'll move to another set of files.

@zayfod zayfod merged commit 6872b39 into zayfod:dev Oct 1, 2020
@gimait gimait deleted the jsonLoads branch October 5, 2020 23:03
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.

None yet

2 participants