Coder Social home page Coder Social logo

Comments (9)

AnderRasoVazquez avatar AnderRasoVazquez commented on May 27, 2024 1

In Jarvis class we will have only the user_input, speak find_action methods?

Yes, that's right. I'll start implementing it.

from jarvis.

sukeesh avatar sukeesh commented on May 27, 2024

This looks cool!

from jarvis.

StefanosChaliasos avatar StefanosChaliasos commented on May 27, 2024

It looks very interesting. Do you have any idea on how we could refactor the Jarvis class because it's very big?

from jarvis.

AnderRasoVazquez avatar AnderRasoVazquez commented on May 27, 2024

Yes, at the moment it looks huge, but I have some ideas. We could start doing the easiest task, one line docstrings wherever it's possible:

def help_clock(self):
        """
        Prints help about clock command.
        """
        print("Gives information about time.")
def help_clock(self):
        """Prints help about clock command."""
        print("Gives information about time.")

This will save us two lines for every command, because those docstrings are very short.

Now, let's take a look at the biggest function, weather:

def do_weather(self, s):
        """
        Get information about today's weather.
        """

        location = MEMORY.get_data('city') #Will return None if no value
        if location is None:
            loc = str(location)
            city = mapps.getLocation()['city']
            print(Fore.RED + "It appears you are in " + city + " Is this correct? (y/n)" + Fore.RESET)

            try:
                i = raw_input()
            except:
                i = input()
            if i == 'n' or i == 'no':
                print("Enter Name of city: ")
                try:
                    i = raw_input()
                except:
                    i = input()
                city = i

            mapps.weather(str(city))

            MEMORY.update_data('city', city)
            MEMORY.save()
        else:
            loc = str(location)
            city = mapps.getLocation()['city']
            if city != loc:
                print(Fore.RED + "It appears you are in " + city + ". But you set your location to " + loc + Fore.RESET)
                print(Fore.RED + "Do you want weather for " + city + " instead? (y/n)" + Fore.RESET)
                try:
                    i = raw_input()
                except:
                    i = input()
                if i == 'y' or i == 'yes':
                    try:
                        print(Fore.RED + "Would you like to set " + city + " as your new location? (y/n)" + Fore.RESET)
                        try:
                            i = raw_input()
                        except:
                            i = input()
                        if i == 'y' or i == 'yes':
                            MEMORY.update_data('city', city)
                            MEMORY.save()

                        mapps.weather(city)
                    except:
                        print(Fore.RED + "I couldn't locate you" + Fore.RESET)
                else:
                    try:
                        mapps.weather(loc)
                    except:
                        print(Fore.RED + "I couldn't locate you" + For.RESET)
            else:
                try:
                    mapps.weather(loc)
                except:
                    print(Fore.RED + "I couldn't locate you" + Fore.RESET)

Wow, 60 lines of code. This doesn't look very clean, Jarvis shouldn't be the one to handle the weather. Do you think that it might be a good idea to make a package for every skill Jarvis has? We could end up with an implementation like this:

.
└── packages
    └── weather
        └── weather.py
from packages.weather import weather
# the command might look like this
def do_weather(self, s):
        """Get information about today's weather."""
        weather.main()  # if the skill needs input -> skill.main(s)

3 lines instead of 60. Another good thing about having the implementation of the skill separated in a package is that it allows doing isolated tests from Jarvis. We can test new skills and when we are sure that they work we can add them as new commands to Jarvis. Do you have any more ideas?

from jarvis.

StefanosChaliasos avatar StefanosChaliasos commented on May 27, 2024

Obviously we should create packages for each skill. I agree with your idea about comments too but i think we need something more efficient like having all actions in other file or files. I don't have any idea right now on how to do that.

from jarvis.

AnderRasoVazquez avatar AnderRasoVazquez commented on May 27, 2024

We can make Jarvis.py very small if we take out the command interpreter functionality to a new class.

captura de pantalla de 2017-04-08 11-50-55

This way we would have all the actions in other file. What do you think?

from jarvis.

StefanosChaliasos avatar StefanosChaliasos commented on May 27, 2024

In Jarvis class we will have only the user_input, speak find_action methods? If you can implement it do it. I made some refactoring to Jarvis class (like your proposal for weather and inline comments).

from jarvis.

AnderRasoVazquez avatar AnderRasoVazquez commented on May 27, 2024

Oh, and thanks @StefanosChaliasos for considering my proposal for weather and inline comments.

from jarvis.

AnderRasoVazquez avatar AnderRasoVazquez commented on May 27, 2024

I've finished the command line implementation. I changed find_action method code that it can recognize commands if it finds those command words in the input, let's take a look at the result:
captura de pantalla de 2017-04-09 13-51-29

Pull request

from jarvis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.