class Subbrand(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30), nullable=False) def __init__(self, name): self.name = name def __repr__(self): return f'<id {self.id}>' def serialize(self): return {'id': self.id, 'name': self.name}
class Affected(db.Model): id = db.Column(db.Integer, primary_key=True) gender = db.Column(db.Boolean(), nullable=True) age_range = db.Column(db.Enum(Age_range), nullable=True) accident = db.relationship('Accident', uselist=False) def __init__(self, gender, age_range): self.gender = gender self.age_range = age_range def __repr__(self): return f'<id {self.id}>' def serialize(self): return {'id': self.id, 'name': self.name, 'age_range': self.age_range}
class Detail(db.Model): id = db.Column(db.Integer, primary_key=True) belt = db.Column(db.SmallInteger, nullable=True) alcohol = db.Column(db.Boolean, nullable=True) amount = db.Column(db.Integer, nullable=True) injured = db.Column(db.String(10), nullable=True) consec = db.Column(db.Integer, nullable=True) conse_g = db.Column(db.Integer, nullable=True) conse_m = db.Column(db.Integer, nullable=True) conse_sem = db.Column(db.Integer, nullable=False) _merge = db.Column(db.String(15), nullable=True) accident = db.relationship('Accident', uselist=False) def __init__(self, belt, alcohol, amount, injured, consec, conse_g, conse_m, conse_sem, _merge): self.belt = belt self.alcohol = alcohol self.amount = amount self.injured = injured self.consec = consec self.conse_g = conse_g self.conse_m = conse_m self.conse_sem = conse_sem self._merge = _merge def __repr__(self): return f'<id {self.id}>' def serialize(self): return { 'id': self.id, 'belt': self.belt, 'amount': self.amount, 'injured': self.injured, 'consec': self.consec, 'conse_g': self.conse_g, 'conse_m': self.conse_m, 'conse_sem': self.conse_sem, '_merge': self._merge }
class Car(db.Model): id = db.Column(db.Integer, primary_key=True) model = db.Column(db.String(10), nullable=True) brand_id = db.Column(db.Integer, db.ForeignKey('brand.id'), nullable=True) brand = db.relationship('Brand', foreign_keys=[brand_id]) subbrand_id = db.Column(db.Integer, db.ForeignKey('subbrand.id'), nullable=True) subbrand = db.relationship('Subbrand', foreign_keys=[subbrand_id]) car_type_id = db.Column(db.Integer, db.ForeignKey('car_type.id'), nullable=True) car_type = db.relationship('Car_type', foreign_keys=[car_type_id]) accident = db.relationship('Accident', uselist=False) def __init__(self, model, brand_id, subbrand_id, car_type_id): self.model = model self.brand_id = brand_id self.subbrand_id = subbrand_id self.car_type_id = car_type_id def __repr__(self): return f'<id {self.id}>' def serialize(self): return { 'id': self.id, 'model': self.model, 'brand_id': self.brand_id, 'subbrand_id': self.subbrand_id, 'car_type_id': self.car_type_id }
class Place(db.Model): id = db.Column(db.Integer, primary_key=True) municipality_id = db.Column(db.Integer, db.ForeignKey('municipality.id'), nullable=False) municipality = db.relationship("Municipality", foreign_keys=[municipality_id]) intersection_a_id = db.Column(db.Integer, db.ForeignKey('street.id'), nullable=True) intersection_a = db.relationship("Street", foreign_keys=[intersection_a_id]) intersection_b_id = db.Column(db.Integer, db.ForeignKey('street.id'), nullable=True) intersection_b = db.relationship("Street", foreign_keys=[intersection_b_id]) street_id = db.Column(db.Integer, db.ForeignKey('street.id'), nullable=False) street = db.relationship("Street", foreign_keys=[street_id]) neighborhood_id = db.Column(db.Integer, db.ForeignKey('neighborhood.id'), nullable=True) neighborhood = db.relationship("Neighborhood", foreign_keys=[neighborhood_id]) def __init__(self, municipality_id, intersection_a_id, intersection_b_id, street_id, neighborhood_id): self.municipality_id = municipality_id self.intersection_a_id = intersection_a_id self.intersection_b_id = intersection_b_id self.street_id = street_id self.neighborhood_id = neighborhood_id def __repr__(self): return f'<id {self.id}>' def serialize(self): return { 'id': self.id, 'municipality_id': self.municipality_id, 'intersection_a': self.intersection_a, 'intersection_b': self.intersection_b, 'street_id': self.street_id, 'neigborhood_id': self.neigborhood_id }
class Accident(db.Model): id = db.Column(db.Integer, primary_key=True) date = db.Column(db.Date, nullable=True) hour = db.Column(db.Enum(Hour), nullable=True) x = db.Column(db.Float(), nullable=True) y = db.Column(db.Float(), nullable=True) # one to many accident_type_id = db.Column(db.Integer, db.ForeignKey('accident_type.id'), nullable=True) cause_id = db.Column(db.Integer, db.ForeignKey('cause.id'), nullable=True) route_id = db.Column(db.Integer, db.ForeignKey('route.id'), nullable=True) place_id = db.Column(db.Integer, db.ForeignKey('place.id'), nullable=False) # one to one car_id = db.Column(db.Integer, db.ForeignKey('car.id'), nullable=False) car = relationship("Car", back_populates="accident") detail_id = db.Column(db.Integer, db.ForeignKey('detail.id'), nullable=False) detail = relationship("Detail", back_populates="accident") affected_id = db.Column(db.Integer, db.ForeignKey('affected.id'), nullable=False) affected = relationship("Affected", back_populates="accident") def __init__(self, date, hour, x, y, place_id, accident_type_id, cause_id, car_id, route_id, detail_id, affected_id): self.date = date self.hour = hour self.x = x self.y = y self.place_id = place_id self.accident_type_id = accident_type_id self.cause_id = cause_id self.car_id = car_id self.route_id = route_id self.detail_id = detail_id self.affected_id = affected_id def __repr__(self): return f'<id {self.id}>' def serialize(self): return { 'id': self.id, 'date': self.date, 'hour': self.hour, 'x': self.x, 'y': self.y, 'place_id': self.place_id, 'accident_type_id': self.accident_type_id, 'cause_id': self.cause_id, 'car_id': self.car_id, 'route_id': self.route_id, 'detail_id': self.detail_id, 'affected_id': self.affected_id }