Esempio n. 1
0
def find(table, id):
    cnx = connect_to_database()
    cursor = create_cursor(cnx)

    query = find_query(table, id)
    cursor.execute(query)
    result = cursor.fetchall()

    entity = None
    if cursor.rowcount == 1:
        if table == "movies":
            entity = Movie(title=result[0].title,
                           duration=result[0].duration,
                           original_title=result[0].original_title,
                           release_date=result[0].release_date,
                           rating=result[0].rating)

        if table == "people":
            entity = Person(firstname=result[0].firstname,
                            lastname=result[0].lastname)

        entity.id = result[0].id

    disconnect_to_database(cnx, cursor)
    return entity
Esempio n. 2
0
def findall(table):
    cnx = connect_to_database()
    cursor = create_cursor(cnx)
    cursor.execute(f"SELECT * FROM {table}")
    results = cursor.fetchall()
    disconnect_to_database(cnx, cursor)

    entities = None
    if table == "movies":
        entities = []
        for result in results:
            entity = Movie(title=result.title,
                           duration=result.duration,
                           original_title=result.original_title,
                           release_date=result.release_date,
                           rating=result.rating)
            entity.id = result.id
            entities += [entity]

    if table == "people":
        entities = []
        for result in results:
            entity = Person(firstname=result.firstname,
                            lastname=result.lastname)
            entity.id = result.id
            entities += [entity]

    return entities
def find(table, id):
    cnx = connect_to_database()
    cursor = create_cursor(cnx)

    query = find_query(table, id)
    cursor.execute(query)
    result = cursor.fetchall()

    entity = None
    if cursor.rowcount == 1:
        if table == "movies":
            entity = Movie(
                    imdb_id=result[0].imdb_id,
                    original_title=result[0].original_title,
                    title=result[0].title,
                    duration=result[0].duration,
                    release_date=result[0].release_date,
                    rating=result[0].rating,
                    production_budget=result[0].production_budget,
                    marketing_budget=result[0].marketing_budget,
                    is3d=result[0].is3d,
                    synopsis=result[0].synopsis,
                    review=result[0].review
                )

        if table == "people":
            entity = Person(
                firstname=result[0].firstname, lastname=result[0].lastname
                )

        entity.id = result[0].id

    disconnect_to_database(cnx, cursor)
    return entity
Esempio n. 4
0
 def __iter__(self, file_path):
     with open(file_path) as txt_file:
         for line in txt_file:
             line_words = line.split(" ")
             person_ = Person(line_words[0], eval(
                 line_words[1]), eval(line_words[2]))
             yield person_
Esempio n. 5
0
 def read(self, people_list):
     for read_line in self.read_lines:
         read_word = read_line.split(',')
         if read_word != ['']:
             person_info = Person(read_word[0], eval(read_word[1]),
                                  eval(read_word[2]))
             people_list.append(person_info)
     return people_list
Esempio n. 6
0
 def read(cls, file_path, people_list):
     with open(file_path) as txt_file:
         for line in txt_file:
             line_words = line.split(" ")
             person_ = Person(line_words[0], eval(
                 line_words[1]), eval(line_words[2]))
             people_list.append(person_)
     return people_list
Esempio n. 7
0
    def create_person(self) -> Person:
        '''
        Asks the user for input in order to create a new person.
        '''
        self.__ui.prompt_user("Adding a new person")
        first_name = self.__ui.ask_user(
            "What's the first name of this person?")
        last_name = self.__ui.ask_user("What's the last name of this person?")

        person = Person()
        person.set_first_name(first_name)
        person.set_last_name(last_name)

        return person
def findall(table):
    cnx = connect_to_database()
    cursor = create_cursor(cnx)
    cursor.execute(f"SELECT * FROM {table}")
    results = cursor.fetchall()
    disconnect_to_database(cnx, cursor)

    entities = None
    if table == "movies":
        entities = []
        for result in results:
            entity = Movie(
                imdb_id=result.imdb_id,
                original_title=result.original_title,
                title=result.title,
                duration=result.duration,
                release_date=result.release_date,
                rating=result.rating,
                production_budget=result.production_budget,
                marketing_budget=result.marketing_budget,
                is3d=result.is3d,
                synopsis=result.synopsis,
                review=result.review
            )
            entity.id = result.id
            entities += [entity]

    if table == "people":
        entities = []
        for result in results:
            entity = Person(
                firstname=result.firstname, lastname=result.lastname
                )
            entity.id = result.id
            entities += [entity]

    return entities
Esempio n. 9
0
        if args.export:
            with open(args.export, 'w', newline='\n',
                      encoding='utf-8') as csvfile:
                writer = csv.writer(csvfile)
                writer.writerow(['id', 'firstname', 'lastname'])
                for person in results:
                    writer.writerow(
                        [person.id, person.firstname, person.lastname])

        else:
            for person in results:
                print_person(person)

    if args.action == "insert":
        person = Person(firstname=args.firstname, lastname=args.lastname)
        results = insert_people(person)
        print(results)

if args.context == "movies":
    print("Mode Movies")

    if args.action == "find":
        movieId = args.id
        movie = find("movies", movieId)
        if movie == None:
            print("Cet id n'a pas été trouvé")
        else:
            print_movie(movie)

    if args.action == "list":
def main():
    parser = argparse.ArgumentParser(
        description='Process Movies Predictor data')
    parser.add_argument(
        'context',
        choices=['people', 'movies', 'import'],
        help='La table concernée, people ou movies'
        )

    known_args = parser.parse_known_args()[0]

    if known_args.context == "import":
        parser.add_argument('--api', help='source api')
        lookfor = parser.add_subparsers(dest='lookfor', help='fullaction')

        parser_imdbid = lookfor.add_parser('imdbid')
        parser_imdbid.add_argument('imdbid')

        parser_since = lookfor.add_parser('since')
        parser_since.add_argument('date')

    else:
        fullaction = parser.add_subparsers(dest='action', help='fullaction')

        parser_find = fullaction.add_parser('find')
        parser_find.add_argument('id', type=int)

        parser_list = fullaction.add_parser('list')
        parser_list.add_argument('--export', type=str)

        import_parser = fullaction.add_parser(
            'import', help='Add data from csv file')
        import_parser.add_argument('--file', help='File with data')

        parser_scrapp = fullaction.add_parser('scrap')
        parser_scrapp.add_argument('--url', type=str)

        insert_parser = fullaction.add_parser(
            'insert', help='Add data in tables')

        if known_args.context == "people":
            insert_parser.add_argument(
                '--firstname',
                help='Person first name',
                required=True)
            insert_parser.add_argument(
                '--lastname',
                help='Person last name',
                required=True)

        if known_args.context == "movies":
            insert_parser.add_argument(
                '--imdb_id', help='Movie imdb id', required=True)
            insert_parser.add_argument(
                '--original-title', help='Movie original title', required=True)
            insert_parser.add_argument(
                '--title', default=None, help='Movie title')
            insert_parser.add_argument(
                '--duration', default=None, help='Movie duration')
            insert_parser.add_argument(
                '--origin-country', default=None, help='Movie origin country')
            insert_parser.add_argument(
                '--release-date', default=None, help='Movie release date')
            insert_parser.add_argument(
                '--rating', default=None, help='Movie rating')

    args = parser.parse_args()
    print(args)

    """
    Args example:
    $ python app.py movies find 1
    $ python app.py people list
    $ python app.py people list --export "listing.csv"

    $ python app.py people insert --firstname "John" --lastname "Doe"
    $ python app.py movies insert
    --title "Star Wars, épisode VIII : Les Derniers Jedi"--duration 152
        --original-title "Star Wars: Episode VIII – The Last Jedi"
        --origin-country US
        --release-date

    $ python app.py movies import --file new_movies.csv
    $ python app.py movies scrap --url https://www.imdb.com/title/tt2527338/

    $ python app.py import --api omdb --imdbid tt7016254
    $ python app.py import --api themoviedb --imdbid tt7016254
    $ python app.py import --api themoviedb --since 2018-01-01
    """

    # Utiliser arguments pour afficher des inputs
    if args.context == "people":
        print("Mode People")

        if args.action == "find":
            peopleId = args.id
            person = find("people", peopleId)
            if person is None:
                print("Cet id n'a pas été trouvé")
            else:
                print_person(person)

        if args.action == "list":
            results = findall("people")

            if args.export:
                with open(args.export, 'w', newline='\n', encoding='utf-8') \
                        as csvfile:
                    writer = csv.writer(csvfile)
                    writer.writerow(['id', 'firstname', 'lastname'])
                    for person in results:
                        writer.writerow(
                            [person.id, person.firstname, person.lastname]
                            )

            else:
                for person in results:
                    print_person(person)

        if args.action == "insert":
            person = Person(firstname=args.firstname, lastname=args.lastname)
            results = insert_people(person)
            print(results)

    if args.context == "movies":
        print("Mode Movies")

        if args.action == "find":
            movieId = args.id
            movie = find("movies", movieId)
            if movie is None:
                print("Cet id n'a pas été trouvé")
            else:
                print_movie(movie)

        if args.action == "list":
            results = findall("movies")
            for movie in results:
                print_movie(movie)

            if args.export:
                with open(args.export, 'w', newline='\n', encoding='utf-8')\
                        as csvfile:
                    writer = csv.writer(csvfile)
                    writer.writerow([
                        'id', 'imdb_id', 'original_title',
                        'title', 'rating', 'production_budget',
                        'marketing_budget', 'duration',
                        'release_date', 'is3d', 'synopsis',
                        'review'
                    ])
                    for movie in results:
                        writer.writerow([
                            movie.id, movie.imdb_id, movie.original_title,
                            movie.title, movie.rating, movie.production_budget,
                            movie.marketing_budget, movie.duration,
                            movie.release_date, movie.is3d, movie.synopsis,
                            movie.review
                        ])

        if args.action == "insert":
            new_movie = Movie(
                title=args.title,
                duration=args.duration,
                original_title=args.original_title,
                release_date=args.release_date,
                rating=args.rating
            )

            results = insert_movie(new_movie)
            print(results)

        if args.action == "import":
            cnx = connect_to_database()
            cursor = create_cursor(cnx)
            with open(args.file, 'r', encoding='utf-8', newline='') as csvfile:
                reader = csv.DictReader(csvfile)
                i = 0
                for row in reader:
                    i += 1
                    row = {k: v if v else None for k, v in row.items()}
                    new_movie = Movie(
                        imdb_id=row['imdb_id'],
                        title=row['title'],
                        duration=row['duration'],
                        original_title=row['original_title'],
                        release_date=row['release_date'],
                        rating=row['rating'],
                        production_budget=row['production_budget'],
                        marketing_budget=row['marketing_budget'],
                        is3d=row['is3d'],
                        synopsis=row['synopsis'],
                        review=row['review']
                    )

                    results = insert_movie(new_movie, cnx=cnx, cursor=cursor,
                                           commit=False)

                    print(results)

            cnx.commit()
            disconnect_to_database(cnx, cursor)

        if args.action == "scrap":
            scrap_movie(args.url)

    if args.context == "import":
        print('Mode import')
        if args.api == 'themoviedb':
            if args.lookfor == 'imdbid':
                print('Mode themoviedb imdbid')
                movie = themoviedb.collect_from__themoviedb(args.imdbid)
                results = insert_movie(movie)
                print(results)
                print()

            if args.lookfor == 'since':
                print('Mode themoviedb since')
                import_movies_since(args.date)
Esempio n. 11
0
from econtools.budget import Budget, Good
from econtools.hicks import Hicks, Slutsky
from entities.person import Person

my_person = Person(1)

my_person.get_policy_history()

my_person.get_policy('company_1', 1)

my_person.get_budget()

all_other = Good(1)
insurance = Good(1000)
new_budget = Budget(insurance,
                    all_other,
                    income=my_person.income,
                    name='new_budget')

test = Hicks(my_person.budget, new_budget, my_person.utility)

test.show_plot()
Esempio n. 12
0
# test if theoretical properties of endowment are satisfied
from econtools.budget import Budget, Endowment, Good
from econtools.utility import CobbDouglas
from entities.person import Person

# original endowment should lie on budget line

my_person = Person(1)

good_1 = Good(price=1, name='good_1')

good_2 = Good(price=1, name='good_2')

endowment = Endowment(good_x=good_1,
                      good_y=good_2,
                      good_x_quantity=5,
                      good_y_quantity=5)

# test equivalence of initialization methods

endowment_value = 5 * good_1.price + 5 * good_2.price
my_person.income = endowment_value

budget_bundle = Budget(good_x=good_1, good_y=good_2, income=endowment_value)
budget_endowment = Budget.from_endowment(endowment=endowment)

print(budget_bundle.good_x == budget_endowment.good_x)
print(budget_bundle.good_y == budget_endowment.good_y)
print(budget_bundle.income == budget_endowment.income)
print(budget_bundle.x_lim == budget_endowment.x_lim)
print(budget_bundle.y_lim == budget_endowment.y_lim)
Esempio n. 13
0
 def MapAddPersonRequestToPerson(request):
     return Person(request['id'], request['name'])
Esempio n. 14
0
pricing_date = dt.date(1, 12, 31)

rayon = Broker()

company_1 = Insurer(4000000, 'company_1')
company_1_formula = 'severity ~ age_class + profession + health_status + education_level'

rayon.place_business(pricing_date, company_1)

ahura.smite(pricing_date + dt.timedelta(days=1))

company_1.price_book(company_1_formula)

rayon.place_business(pricing_date, company_1)

my_person = Person(person_id=1)
my_person.get_policy_history()
my_person.get_policy('company_1', 1001)
my_person.get_budget()
my_person.get_consumption()
my_person.get_consumption_figure()

fig = my_person.consumption_figure

fig['layout'].update({
    'title_x': 0.5,
    'width': 1200,
    'height': 627,
    'margin': {
        'l': 10
    }
Esempio n. 15
0
 def register(self, name, entry_time):
     self.persons[name] = Person(name, entry_time, 0)
Esempio n. 16
0
 def mark_person_disappeared(self, name, exit_time):
     if name in self.persons.keys():
         self.persons_activities.append(
             Person(name, self.persons[name].entry_time, exit_time))
Esempio n. 17
0
# import tests.base_sim
from econtools.budget import Budget, Endowment, Good
from econtools.utility import CobbDouglas
from econtools.slutsky import Slutsky
from entities.person import Person

my_person = Person(1)

my_person.get_policy_history()
my_person.get_policy('company_1', 1)

my_person.get_budget()
my_person.get_consumption()

# rate change
all_other = Good(1)
insurance = Good(1000)
new_budget = Budget(insurance,
                    all_other,
                    income=my_person.income,
                    name='new_budget')

testcobb = my_person.utility
testcobb.optimal_bundle(new_budget.good_x.price, new_budget.good_y.price,
                        my_person.income)

slutsky_res = Slutsky(old_budget=my_person.budget,
                      new_budget=new_budget,
                      utility_function=my_person.utility)
slutsky_res.get_slutsky_plot()
slutsky_res.show_plot()