Esempio n. 1
0
class TravelDay(db.Model):
    __tablename__ = 'travel_days'
    # TODO: needs work
    id: int = db.Column(db.Integer, primary_key=True, autoincrement=True)
    created_date = db.Column(db.DateTime, default=datetime.now, index=True)

    travel_id: int = db.Column(db.Integer, db.ForeignKey('travels.id'))

    date = db.Column(db.Date, nullable=False)
    starting_point_id = db.Column(db.Integer, db.ForeignKey('locations.id'))
    starting_point = db.relationship('Location',
                                     foreign_keys=[starting_point_id])
    ending_point_id = db.Column(db.Integer, db.ForeignKey('locations.id'))
    ending_point = db.relationship('Location', foreign_keys=[ending_point_id])
    route = db.Column(db.String, index=True)
    mode = db.Column(db.String, index=True)

    def __init__(self, date: str, starting_point: str, ending_point: str,
                 route: str, mode: str):
        self.date = datetime.strptime(date, '%Y-%m-%d')
        self.starting_point_id = location_services.get_id_from_name(
            starting_point)
        self.ending_point_id = location_services.get_id_from_name(ending_point)
        self.route = route
        self.mode = mode

    def __lt__(self, other):
        return self.date < other.date

    def __repr__(self):
        return f'{str(self.date)} {self.starting_point} {self.ending_point} {self.route} {self.mode}'
Esempio n. 2
0
class Note(db.Model):
    """
    A note for a Car
    
    :param created_date: when the note was created
    :type created_date: datetime
    :param text: the body of the note
    :type text: str
    :param car_id: the id of the car that the note's to be added to
    :type car_id: int
    """
    __tablename__ = 'notes'

    id: int = db.Column(db.Integer, primary_key=True)
    created_date = db.Column(db.DateTime,
                             default=datetime.datetime.now,
                             index=True)
    text: str = db.Column(db.String, unique=True, nullable=False)
    car_id: int = db.Column(db.Integer, db.ForeignKey('cars.id'))

    def __init__(self, text: str):
        """Initiates a Note object with a text body"""
        self.text = text

    def __lt__(self, other):
        return str(self) < str(other)

    def __repr__(self):
        return f'{self.text}'
Esempio n. 3
0
class Car(db.Model):
    __tablename__ = 'cars'

    id: int = db.Column(db.Integer, primary_key=True)
    created_date = db.Column(db.DateTime,
                             default=datetime.datetime.now,
                             index=True)
    plate: str = db.Column(db.String, unique=True, nullable=False)
    make: str = db.Column(db.String)
    model: str = db.Column(db.String)
    color_id: int = db.Column(db.String, db.ForeignKey('colors.id'))
    color = db.relationship('Color', foreign_keys=[color_id])
    location: str = db.Column(db.String)
    active: bool = db.Column(db.Boolean)
    department_id: int = db.Column(db.String, db.ForeignKey('departments.id'))
    department = db.relationship('Department', foreign_keys=[department_id])
    notes = db.relationship('Note', backref='car')

    def __init__(self,
                 plate: str,
                 make: str = None,
                 model: str = None,
                 color: str = None,
                 location: str = None,
                 active: bool = None,
                 department: Department = None):
        self.plate = plate
        self.make = make
        self.model = model
        color = color_services.add_if_not_present(color)
        self.color_id = color_services.get_id_from_name(color)
        self.location = location
        self.active = active
        self.department_id = department_services.get_id_from_name(
            department) if department else None

    def __lt__(self, other):
        return str(self) < str(other)

    def __repr__(self):
        return f'{self.plate} {self.make} {self.model} {self.color.name} {self.location}'

    @property
    def name(self):
        return str(self)
Esempio n. 4
0
class User(db.Model):
    __tablename__ = 'users'

    # TODO: lots (db. and __init__)
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    created_date = db.Column(db.DateTime,
                             default=datetime.datetime.now,
                             index=True)

    name = db.Column(db.String, nullable=False, unique=True)
    email = db.Column(db.String, unique=True)
    department_id: int = db.Column(db.String, db.ForeignKey('departments.id'))
    department: Department = db.relationship('Department',
                                             foreign_keys=[department_id])

    travels = db.relationship('TravelUserUnit', backref='traveler')

    home_number = db.Column(db.String)
    work_number = db.Column(db.String)
    cell_number = db.Column(db.String)

    active: bool = db.Column(db.Boolean, nullable=False)

    def __init__(self,
                 name: str,
                 email: str,
                 work_number: str = None,
                 home_number: str = None,
                 cell_number: str = None,
                 department: str = None,
                 active: bool = None):
        self.name = name
        self.email = email
        self.work_number = work_number
        self.home_number = home_number
        self.cell_number = cell_number
        self.active = active
        department_id = department_services.get_id_from_name(department)
        self.department_id = department_id

    def __lt__(self, other):
        return self.name < other.name

    def __eq__(self, other):
        return self.name == other.name and \
               self.email == other.email and \
               self.work_number == self.work_number and \
               self.home_number == self.home_number and \
               self.cell_number == self.cell_number and \
               self.department == self.department
Esempio n. 5
0
class TravelFile(db.Model):
    __tablename__ = 'travel_files'

    id: str = db.Column(db.Integer, primary_key=True)
    created_date = db.Column(db.DateTime, default=datetime.datetime.now)
    name: str = db.Column(db.String, unique=True, nullable=False, index=True)
    travel_id: int = db.Column(db.Integer, db.ForeignKey('travels.id'))

    def __init__(self, name: str):
        self.name = name

    def __lt__(self, other):
        return self.name < other.name

    def __repr__(self):
        return self.name
Esempio n. 6
0
class Travel(db.Model):
    __tablename__ = 'travels'

    id = db.Column(db.Integer, primary_key=True)
    created_date = db.Column(db.DateTime,
                             default=datetime.datetime.utcnow,
                             index=True)

    start_date: datetime = db.Column(db.Date, index=True)
    entry_point_id = db.Column(db.Integer, db.ForeignKey('locations.id'))
    entry_point: Location = db.relationship('Location',
                                            foreign_keys=[entry_point_id])
    end_date: datetime = db.Column(db.Date, index=True)
    exit_point_id = db.Column(db.Integer, db.ForeignKey('locations.id'))
    exit_point: Location = db.relationship('Location',
                                           foreign_keys=[exit_point_id])

    tracked = db.Column(db.Boolean, index=False)
    plb = db.Column(db.String, index=False)

    trip_leader_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    trip_leader = db.relationship('User', foreign_keys=[trip_leader_id])

    travelers = db.relationship('TravelUserUnit', backref='travel')
    travel_days: TravelDay = db.relationship('TravelDay', backref='travel')

    car_id: int = db.Column(db.Integer, db.ForeignKey('cars.id'))
    car: Car = db.relationship('Car', foreign_keys=[car_id])
    car_location: str = db.Column(db.String)

    bivy_gear = db.Column(db.Boolean)
    compass = db.Column(db.Boolean)
    first_aid_kit = db.Column(db.Boolean)
    flagging = db.Column(db.Boolean)
    flare = db.Column(db.Boolean)
    flashlight = db.Column(db.Boolean)
    gps = db.Column(db.Boolean)
    head_lamp = db.Column(db.Boolean)
    helmet = db.Column(db.Boolean)
    ice_axe = db.Column(db.Boolean)
    map = db.Column(db.Boolean)
    matches = db.Column(db.Boolean)
    probe_pole = db.Column(db.Boolean)
    radio = db.Column(db.Boolean)
    rope = db.Column(db.Boolean)
    shovel = db.Column(db.Boolean)
    signal_mirror = db.Column(db.Boolean)
    space_blanket = db.Column(db.Boolean)
    spare_battery = db.Column(db.Boolean)
    tent = db.Column(db.Boolean)
    whistle = db.Column(db.Boolean)

    days_of_food = db.Column(db.Float)
    weapon = db.Column(db.String)
    radio_monitor_time = db.Column(db.String)
    off_trail_travel = db.Column(db.Boolean)
    cell_number = db.Column(db.String)
    satellite_number = db.Column(db.String)

    contacts: User = db.relationship('User',
                                     secondary=contact_association_table)

    files: User = db.relationship('TravelFile', backref='travel')

    gar_avg = db.Column(db.Float)
    mitigated_gar = db.Column(db.Float)
    gar_mitigations = db.Column(db.String)

    notes = db.Column(db.String)

    def __init__(
        self,
        start_date: datetime,
        entry_point_id: int,
        end_date: datetime,
        exit_point_id: int,
        tracked: bool,
        plb: str,
        trip_leader_id: int,
        car_id: int,
        car_location: str,
        bivy_gear: bool,
        compass: bool,
        first_aid_kit: bool,
        flagging: bool,
        flare: bool,
        flashlight: bool,
        gps: bool,
        head_lamp: bool,
        helmet: bool,
        ice_axe: bool,
        map: bool,
        matches: bool,
        probe_pole: bool,
        radio: bool,
        rope: bool,
        shovel: bool,
        signal_mirror: bool,
        space_blanket: bool,
        spare_battery: bool,
        tent: bool,
        whistle: bool,
        days_of_food: float,
        weapon: str,
        radio_monitor_time: str,
        off_trail_travel: bool,
        cell_number: str,
        satellite_number: str,
        gar_avg: float,
        mitigated_gar: int,
        gar_mitigations: str,
        notes: str,
    ):
        self.start_date = start_date
        self.entry_point_id = entry_point_id
        self.end_date = end_date
        self.exit_point_id = exit_point_id

        self.tracked = tracked
        self.plb = plb

        self.trip_leader_id = trip_leader_id

        self.car_id = car_id
        self.car_location = car_location

        self.bivy_gear = bivy_gear
        self.compass = compass
        self.first_aid_kit = first_aid_kit
        self.flagging = flagging
        self.flare = flare
        self.flashlight = flashlight
        self.gps = gps
        self.head_lamp = head_lamp
        self.helmet = helmet
        self.ice_axe = ice_axe
        self.map = map
        self.matches = matches
        self.probe_pole = probe_pole
        self.radio = radio
        self.rope = rope
        self.shovel = shovel
        self.signal_mirror = signal_mirror
        self.space_blanket = space_blanket
        self.spare_battery = spare_battery
        self.tent = tent
        self.whistle = whistle

        self.days_of_food = days_of_food
        self.weapon = weapon
        self.radio_monitor_time = radio_monitor_time
        self.off_trail_travel = off_trail_travel
        self.cell_number = cell_number
        self.satellite_number = satellite_number

        self.gar_avg = float(gar_avg)
        self.mitigated_gar = float(mitigated_gar)
        self.gar_mitigations = gar_mitigations

        self.notes = notes

    def __repr__(self):
        return f'{self.start_date} - {self.entry_point}, {self.entry_point} - {self.exit_point}'
Esempio n. 7
0
import datetime

from travel_plan import db
from travel_plan.car.cars import Car
from travel_plan.location.locations import Location
from travel_plan.travel.travel_days import TravelDay
from travel_plan.user.users import User

contact_association_table = db.Table(
    'travel_contact_association', db.metadata,
    db.Column('travels_id',
              db.Integer,
              db.ForeignKey('travels.id'),
              primary_key=True),
    db.Column('contacts_id',
              db.Integer,
              db.ForeignKey('users.id'),
              primary_key=True))


class Travel(db.Model):
    __tablename__ = 'travels'

    id = db.Column(db.Integer, primary_key=True)
    created_date = db.Column(db.DateTime,
                             default=datetime.datetime.utcnow,
                             index=True)

    start_date: datetime = db.Column(db.Date, index=True)
    entry_point_id = db.Column(db.Integer, db.ForeignKey('locations.id'))
    entry_point: Location = db.relationship('Location',
Esempio n. 8
0
class TravelUserUnit(db.Model):
    __tablename__ = 'travel_user_units'

    id = db.Column(db.Integer, primary_key=True)
    created_date = db.Column(db.DateTime, default=datetime.datetime.utcnow, index=True)

    travel_id: int = db.Column(db.Integer, db.ForeignKey('travels.id'))
    user_id: int = db.Column(db.Integer, db.ForeignKey('users.id'))
    user: User = db.relationship('User', foreign_keys=[user_id])

    call_sign: str = db.Column(db.String)

    pack_color_id: int = db.Column(db.Integer, db.ForeignKey('colors.id'))
    pack_color = db.relationship('Color', foreign_keys=[pack_color_id])
    tent_color_id: int = db.Column(db.Integer, db.ForeignKey('colors.id'))
    tent_color = db.relationship('Color', foreign_keys=[tent_color_id])
    fly_color_id: int = db.Column(db.Integer, db.ForeignKey('colors.id'))
    fly_color = db.relationship('Color', foreign_keys=[fly_color_id])

    supervision: int = db.Column(db.Integer)
    planning: int = db.Column(db.Integer)
    contingency: int = db.Column(db.Integer)
    comms: int = db.Column(db.Integer)
    team_selection: int = db.Column(db.Integer)
    fitness: int = db.Column(db.Integer)
    env: int = db.Column(db.Integer)
    complexity: int = db.Column(db.Integer)
    total: int = db.Column(db.Integer)

    def __init__(self, traveler_name: str, call_sign: str,
                 pack_color: str, tent_color: str, fly_color: str,
                 supervision: int, planning: int, contingency: int, comms: int,
                 team_selection: int, fitness: int, env: int, complexity: int,
                 total: int):

        self.traveler = user_services.get_user_from_name(traveler_name)
        if not self.traveler:
            self.traveler = user_services.create_user(traveler_name, active=False)

        self.call_sign = call_sign

        if pack_color:
            pack_color = color_services.add_if_not_present(pack_color)
            self.pack_color_id = color_services.get_id_from_name(pack_color)
        if tent_color:
            tent_color = color_services.add_if_not_present(tent_color)
            self.tent_color_id = color_services.get_id_from_name(tent_color)
        if fly_color:
            fly_color = color_services.add_if_not_present(fly_color)
            self.fly_color_id = color_services.get_id_from_name(fly_color)

        self.supervision = supervision
        self.planning = planning
        self.contingency = contingency
        self.comms = comms
        self.team_selection = team_selection
        self.fitness = fitness
        self.env = env
        self.complexity = complexity
        self.total = total

    @property
    def total_gar_score(self):
        return (self.supervision + self.planning + self.contingency + self.comms
                + self.team_selection + self.fitness + self.env + self.complexity)
Esempio n. 9
0
class KindEnum(enum.Enum):
    Peak = 1
    Valley = 2
    River = 3
    Lake = 4
    Ridge = 5
    Trail_Head = 6
    Meadow = 7
    Other = 8
    Campground = 9
    Basin = 10
    Area = 11


location_association_table = sa.Table('location_alias_association', db.Model.metadata,
                                      db.Column('location_1_id', db.Integer, db.ForeignKey('locations.id'),
                                                primary_key=True),
                                      db.Column('location_2_id', db.Integer, db.ForeignKey('locations.id'),
                                                primary_key=True)
                                      )


class Location(db.Model):
    '''
    An object representing a named location.

    Since some geographic locations have multiple names, or are 
    sufficiently close to be all but geographically
    indistinguishable, multiple Locations may refer to the same
    geogrphic location. Aliasses are used to track and account
    for this.