Exemplo n.º 1
0
class Mountain(Base):
    __tablename__ = tb_mountains

    id = Column(Integer, Sequence(mountain_id), primary_key=True)
    name = Column("name", String(80), nullable=False)
    mrange = Column("mountainrange", String(50))
    elevation = Column("elevation", Integer, nullable=False)

    mtype_id = Column(Integer, ForeignKey("%s.id" % (tb_mtype)))
    mtype = relationship("MountainType")

    country_id = Column(Integer, ForeignKey("%s.id" % (tb_country)))
    country = relationship("Country")

    # self representation
    def __repr__(self):
        return "<Mountains (id = '%s', name='%s', country='%s', mountainrange='%s', elevation='%s', mountaintype='%s')>" % (
            self.id, self.name, self.country.name, self.mrange, self.elevation,
            self.mtype.name)

    # Query for all and return as panda
    @classmethod
    def queryAll(self):
        countries = readTableFromDB(tb_country)
        mountains = readTableFromDB(tb_mountains)
        mtype = readTableFromDB(tb_mtype)
        mountains["mname"] = mountains.mtype_id.map(mtype.name.to_dict())
        mountains["country"] = mountains.country_id.map(
            countries.code.to_dict())
        return mountains

    # new Mountain
    @classmethod
    def new(self):
        print()
        newM = Mountain()
        # Ask for Name of Route
        newM.name = input("Enter Name of Summit: ")
        # Ask for Location
        newM.countrycode = input("Enter Countrycode: ")
        # Ask for distance of Route
        newM.mrange = input("Enter Mountainrange: ")
        # Ask for distance of Route
        newM.elevation = input("Enter Elevation: ")
        # Ask for distance of Route
        newM.mtype = input("Enter Mountaintype (Pass, Mountain, Vulcan): ")
        # Print what was entered
        horizontalSeperator()
        print("New Mountain:\n%s" % (newM.name))
        saveNewInput("mountain", newM)
Exemplo n.º 2
0
class Difficulty(Base):
    __tablename__ = tb_difficulty

    id = Column(Integer, Sequence(difficulty_id), primary_key=True)
    code = Column("code", String(10), nullable=False)
    description = Column("description", Text)
    sport_id = Column(Integer, ForeignKey("%s.id" % (tb_sport)))

    sport = relationship("Sport")

    # self representation
    def __repr__(self):
        return "<Difficulty (id = '%s', code='%s', sport='%s', description='%s')>" % (
            self.id, self.code, self.sport.name, self.description)

    # Query for all and return as panda
    @classmethod
    def queryAll(self):
        return pd.read_sql_table(tb_difficulty, Engine, index_col="id")

    # new Difficulty
    @classmethod
    def new():
        print()
        newD = Difficulty()
        # Ask for SportID
        newD.sport_id = selectSport()
        # Ask for difficulty code
        newD.code = input("Enter Difficulty Code: ")
        # Ask for description
        newD.description = input("Enter Description: ")
        # Print what was entered
        horizontalSeperator()
        print("New Sport:\n%s" % (newD.name))
        # Ask if User wants to save new sport
        saveNewInput("sport", newD)

    # Query for all and return as panda
    @classmethod
    def select(sport, self):
        # Query from postgreSQL
        dificulties = pd.read_sql_table(tb_difficulty, Engine, index_col="id")
        # Panda comperision
        difficultyBool = difficulty["sport_id"] == sport
        difficulty = difficulty[difficultyBool]
        #print dificulties for Sport
        print(tabulate(difficulty, headers="keys", tablefmt="psql"))
        #Ask for intput
        selection = input("Select difficulty: ")
        selection = int(selection)
        return selection
Exemplo n.º 3
0
class TrackRun(Base):
    __tablename__ = tb_tracksrun
    id = Column(Integer, Sequence(trackrun_id), primary_key=True)
    date_duration = Column('date_duration', DateTime, nullable=False)
    route_id = Column(Integer, ForeignKey("%s.id" % (tb_routes)))
    route = relationship("RouteRun")

    # self representation
    def __repr__(self):
        return "<Running Track (id = '%s', date_duration='%s', pace='%s', speed='%s')>" % (
            self.id, self.date_duration, self.pace(), self.speed())

    # Query for all and return as panda
    @classmethod
    def queryAll(self):
        return readTableFromDB(tb_tracksrun)

    # Calculate pace
    def pace(self):
        distance = float(self.route.distance)
        # Return pace in min/km
        return round(
            (self.date_duration.hour * 60 + self.date_duration.minute +
             self.date_duration.second / 60) / distance, 3)

    # Calculate speed
    def speed(self):
        # Return Speed in km/h
        return round(60 / self.pace(), 2)

    @classmethod
    def new(self):
        newT = TrackRun()
        # Ask for Date
        newT.date_duration = enterDateDuration()
        # Ask for route
        newT.route_id = RouteRun.select()
        # Print what was entered
        horizontalSeperator()
        print("New Track for Running:\n%s" %
              (newT.name, newT.date_duration, newT.route_id))
        # Ask if User wants to save new running track
        saveNewInput("Track for Running", newT)
Exemplo n.º 4
0
class Weight(Base):
    __tablename__ = tb_weight

    id = Column(Integer, Sequence(weight_id), primary_key=True)
    date = Column("date", Date, nullable=False)
    weight = Column("weight", Float, nullable=False)  # in kg
    neck = Column("neck", Float, nullable=False)  # in cm
    waist = Column("waist", Float)  # in cm
    hip = Column("hip", Float)  # in cm

    user_id = Column(Integer, ForeignKey("%s.id" % (tb_users)))
    user = relationship("User", back_populates="weights")

    # self representation
    def __repr__(self):
        return "<Weight (username='******', date='%s', weight='%s', avgBodyfat='%.1f')>" % (
            self.user.name, self.date, self.weight, self.bodyfat())

    # Query for all and return as panda
    @classmethod
    def queryAll(self):
        # create empty Dataframe
        d = pd.DataFrame(columns=[
            "date", "weight", "waist", "neck", "hip", "bf", "male", "height",
            "user_id"
        ])
        users = pd.DataFrame()
        # Append postgreSQL Table
        d = d.append(readTableFromDB(tb_weight), sort=False)
        users = users.append(readTableFromDB(tb_users), sort=False)
        # extract user height, male
        d["male"] = d.user_id.map(users.male.to_dict())
        d["height"] = d.user_id.map(users.height.to_dict())

        # iterate through DataFrame
        for index, row in d.iterrows():
            bodyf = bodyfat(row['waist'], row['neck'], row['hip'],
                            row['height'], row['male'])
            d.at[index, "bf"] = bodyf

        return d
Exemplo n.º 5
0
class User(Base):
    __tablename__ = tb_users

    id = Column(Integer, Sequence(user_id), primary_key=True)
    name = Column("name", String(50), nullable=False)
    birthday = Column("birthday", Date, nullable=False)
    male = Column("male", Boolean, nullable=False)
    height = Column("height", Integer, nullable=False)  # in cm

    weights = relationship("Weight", back_populates="user")

    # self representation
    def __repr__(self):
        return "New User:\nName: %s\nBirthday: %s\nMale: %s\nHeight: %s" % (
            self.name, self.birthday, self.male, self.height)

    # Query for all and return as panda
    @classmethod
    def queryAll(self):
        return readTableFromDB(tb_users, Engine, parse_dates="birthday")

    # Add new user
    @classmethod
    def new(self):
        print()
        newU = User()
        # Ask for Name of User
        newU.name = input("Enter Name of User: "******"Birthday of user %s: " % (newU.name))
        newU.birthday = enterDate()
        # Ask for male or female
        while True:
            i = input("Is the user female or male? (f/m): ")
            if i == "f" or i == "F":
                newU.male = False
                break
            elif i == "m" or i == "M":
                newU.male = True
                break
            else:
                print("Invalid Input! Try again!")
        # Ask for heigt of user
        newU.height = int(
            input("Enter height of user %s (in cm): " % (newU.name)))
        # Print what was entered
        horizontalSeperator()
        print("New User:\nName: %s\nBirthday: %s\nMale: %s\nHeight: %s cm" %
              (newU.name, newU.birthday, newU.male, newU.height))
        # Ask to save or delete
        saveNewInput("User", newU)
        pass

    # selecting a User from the list in postgreSQL
    @classmethod
    def select(self):
        users = readTableFromDB(tb_users, Engine, parse_dates="birthday")
        print(tabulate(users, headers="keys", tablefmt="psql"))
        while True:
            selection = int(input("Select User: "******"Enter weight (in kg): "))
        # Ask for neck circumference
        newW.neck = convertStringToFloat(
            input("Enter neck circumference (in cm): "))
        # Ask for waist circumference
        newW.waist = convertStringToFloat(
            input("Enter waist circumference (in cm): "))
        # Ask for hip circumference
        ## Check if user is male or female

        if self.male == False:
            newW.hip = convertStringToFloat(
                input("Enter hip circumference (in cm): "))
        else:
            newW.hip = 0

        # Print what was entered
        horizontalSeperator()
        if self.male == True:
            print(
                "New Measurements:\nuserID: %s\nDate: %s\nWeight: %.1f kg\nneck: %.1f cm\nwaist: %.1f cm"
                %
                (newW.user_id, newW.date, newW.weight, newW.neck, newW.waist))
        else:
            print(
                "New Measurements:\nUserID: %s\nDate: %s\nWeight: %.1f kg\nNeck: %.1f cm\nWaist: %.1f cm\nHip: %.1f cm"
                % (newW.user_id, newW.date, newW.weight, newW.neck, newW.waist,
                   newW.hip))
        # Ask to save or delete
        while True:
            i = input("Do you want to save the new measurements (Y/N)? ")
            if i == "J" or i == "j" or i == "y" or i == "Y":
                self.weights.append(newW)
                moveToDatabase(self)
                break
            elif i == "n" or i == "N":
                break
            else:
                print("Invalid Input! Try again!")
            pass
        pass
Exemplo n.º 6
0
class AlpineTrack(Base):
    __tablename__ = tb_tracksalpine

    id = Column(Integer, Sequence(trackalpine_id), primary_key=True)
    date_duration = Column('date_duration', DateTime, nullable=False)
    conditions = Column("conditions", Text)
    summit = Column("Including Summit", Boolean, nullable=False)
    distance = Column("distance", Float, nullable=False)
    ascend = Column("ascend", Integer, nullable=False)
    descend = Column("descend", Integer, nullable=False)

    mountain_id = Column(Integer, ForeignKey("%s.id" % (tb_mountains)))
    mountain = relationship("Mountain")

    sport_id = Column(Integer, ForeignKey("%s.id" % (tb_sport)))
    sport = relationship("Sport")

    difficulty_id = Column(Integer, ForeignKey("%s.id" % (tb_difficulty)))
    difficulty = relationship("Difficulty")

    # self representation
    def __repr__(self):
        return "<Mountains (id = '%s', name='%s', country='%s', mountainrange='%s', elevation='%s', mountaintype='%s')>" % (
            self.id, self.name, self.country.name, self.mrange, self.elevation,
            self.mtype.name)

    # Query for all and return as panda
    @classmethod
    def queryAll(self):
        return readTableFromDB(tb_tracksalpine)

    # new AlpineTrack
    @classmethod
    def new(self):
        print()
        newAT = AlpineTrack()
        # Ask for Date & Duration
        newAT.date_duration = enterDateDuration()
        horizontalSeperator()
        # Select mountain
        newAT.mountain_id = selectMountain(Engine)
        horizontalSeperator()
        # Enter if Summit was climbed or not
        while True:
            i = input("Does this include the summit? (Y/N)? ")
            if (i == "J" or i == "j" or i == "y" or i == "Y"):
                # Summit was climbed
                newAT.summit = True
                break
            elif (i == "N" or i == "n"):
                # Summit was NOT climbed
                newAT.summit = False
                break
            else:
                horizontalSeperator(string="!")
                print("%s is an invalid Option. Try again!" % option)
        # Select Sport and Difficulty
        newAT.sport_id = selectSport()
        newAT.difficulty_id = selectDifficulty(sportID)
        horizontalSeperator()
        # Enter Conditions & Weather
        newAT.conditions = input("How were the conditions & weather? ")
        horizontalSeperator()
        # Enter Horizontal Distance
        newAT.distance = convertStringToFloat(
            input("Enter the horizontal distance in km: "))
        # Enter Meters of Ascend
        newAT.ascend = int(input("Enter vertical meters ascend: "))
        # Enter Meters of Descend
        newAT.descend = int(input("Enter vertical meters descend: "))
        # Print what was entered
        horizontalSeperator()
        print("New Alpine Tour:\n%s" % (newAT.name))
        # Ask if User wants to save new alpine track
        saveNewInput("Alpine Tour", newAT)

    def PerformanceSpeed(self):

        return ((self.ascend + self.descend) / 100 +
                self.distance) / (self.date_duration.hour +
                                  (self.date_duration.minute +
                                   (self.date_duration.second) / 60) / 60)