Exemplo n.º 1
0
class Measurement(db.Model):
    __tablename__ = 'measurements'

    id = db.Column(db.Integer, primary_key=True)
    timestamp = db.Column(db.DateTime(timezone=True))

    soil_ph = db.Column(db.Float(precision=4))
    soil_nutrient = db.Column(db.Float(precision=4))
    soil_temp = db.Column(db.Float(precision=4))
    soil_humi = db.Column(db.Float(precision=4))

    air_temp = db.Column(db.Float(precision=4))
    air_humi = db.Column(db.Float(precision=4))
    air_pres = db.Column(db.Float(precision=4))
    solar_radiation = db.Column(db.Float(precision=4))

    batt_status = db.Column(db.Integer)
    lat = db.Column(db.Float(precision=8))
    lon = db.Column(db.Float(precision=8))

    # REALTIONSHIPS
    # AGRIMODULE[1]-MEASUREMENT[M]
    agrimodule_id = db.Column(db.Integer, db.ForeignKey('agrimodules.id'))
    # AGRIPUMP[1]-MEASUREMENT[M]
    agripump_id = db.Column(db.Integer, db.ForeignKey('agrisensors.id'))

    def __repr__(self):
        return '<measurement {}>'.format(self.id)
Exemplo n.º 2
0
class Farm(db.Model):
    """Farms Models for Users to create. One User can created as many farms as he wants"""
    __tablename__ = 'farm'
    id = db.Column(db.Integer, primary_key=True)
    farm_name = db.Column(db.String(25), unique=True, nullable=False)
    farm_location = db.Column(db.String(20))
    farm_coordinates = db.Column(db.String(3000))
    farm_area = db.Column(db.Float(precision=2))
    farm_cultivation_process = db.Column(db.String(20))

    # RELATIONSHIP
    # USER[1]-FARM[M]
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    # FARM[1]-FIELD[M]
    fields = db.relationship('Field', backref='farm', lazy='dynamic')
    soil_tests = db.relationship('SoilTest', backref='farm', lazy='dynamic')
    water_tests = db.relationship('WaterTest', backref='farm', lazy='dynamic')

    _default = db.Column(db.Boolean)
    _time_created = db.Column(db.DateTime(timezone=True),
                              server_default=func.now())
    _time_updated = db.Column(db.DateTime(timezone=True),
                              server_default=func.now(),
                              onupdate=func.now())

    def __repr__(self):
        return '<farm {}>'.format(self.farm_name)
Exemplo n.º 3
0
class Agrisensor(db.Model):
    """each agrimodule has a different table where all data that is measured by agrimodule is saved in this model"""
    __tablename__ = 'agrisensors'

    id = db.Column(db.Integer, primary_key=True)

    identifier = db.Column(db.String(50), unique=True)
    lat = db.Column(db.Float(precision=8))
    lon = db.Column(db.Float(precision=8))
    batt_status = db.Column(db.Integer)

    # RELATIONSHIP
    # agrimodule[1]-AGRIMODULE[M]
    agrimodule_id = db.Column(db.Integer, db.ForeignKey('agrimodules.id'))
    # AGRIMODULE[1]-MEASUREMENT[M]
    measurements = db.relationship('Measurement',
                                   backref='agrisensor',
                                   lazy='dynamic')

    # SETTINGS
    _time_created = db.Column(db.DateTime(timezone=True),
                              server_default=func.now())
    _time_updated = db.Column(db.DateTime(timezone=True),
                              server_default=func.now(),
                              onupdate=func.now())

    def __repr__(self):
        return '<agrisensor {}>'.format(self.identifier)
Exemplo n.º 4
0
class Agrimodule(db.Model):
    """Each agrimodule smart system is unique and has am agrimodule an agripump and maybe agresiensor and other agripumps depending on the complaexity of the farm
    and can be added to any user any farm with a unique identuifier which can connect the data being sent to server to an specific User.Model/Field.Model
    Each agrimodule"""
    __tablename__ = 'agrimodules'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20))
    identifier = db.Column(db.String(100), unique=True, nullable=False)
    lat = db.Column(db.Float(precision=8))
    lon = db.Column(db.Float(precision=8))
    batt_status = db.Column(db.Integer)
    public_id = db.Column(db.String(200))
    mac = db.Column(db.String(400))

    # RELATIONSHIP
    # USER[1]-agrimodule[M]
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    # FIELD[1]-agrimodule[1]
    field_id = db.Column(db.Integer, db.ForeignKey('field.id'))
    # AGRIMODULE[1]-MEASUREMENT[M]
    measurements = db.relationship('Measurement',
                                   backref='agrimodule',
                                   lazy='dynamic')
    # AGRIMODULE[1]-AGRISENSOR[M]
    agrisensors = db.relationship('Agrisensor',
                                  backref='agrimodule',
                                  lazy='dynamic')
    # AGRIMODULE[1]-AGRIPUMP[M]
    agripumps = db.relationship('Agripump',
                                backref='agrimodule',
                                lazy='dynamic')

    _time_created = db.Column(db.DateTime(timezone=True),
                              server_default=func.now())
    _time_updated = db.Column(db.DateTime(timezone=True),
                              server_default=func.now(),
                              onupdate=func.now())

    def __repr__(self):
        return '<agrimodule {}>'.format(self.identifier)
Exemplo n.º 5
0
class WelcomeLog(db.Model):
    __tablename__ = 'welcome'
    id = db.Column(db.Integer, primary_key=True)
    add_agrisys = db.Column(db.Boolean)
    install_agrisys = db.Column(db.Boolean)
    add_pump = db.Column(db.Boolean)
    add_farm = db.Column(db.Boolean)
    add_field = db.Column(db.Boolean)
    add_soil_test = db.Column(db.Boolean)
    add_water_test = db.Column(db.Boolean)
    # WELCOME[1]-USER[1]
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def __repr__(self):
        return '<welcomelog {}>'.format(self.id)
Exemplo n.º 6
0
class WaterTest(db.Model):

    __tablename__ = 'watertest'
    id = db.Column(db.Integer, primary_key=True)
    water_ph = db.Column(db.Float(precision=2))
    water_ec = db.Column(db.Float(precision=2))
    water_bicarbonates = db.Column(db.Float(precision=2))
    water_carbonates = db.Column(db.Float(precision=2))
    water_potasium = db.Column(db.Float(precision=2))
    water_sulphate = db.Column(db.Float(precision=2))

    # FARM[1]-TEST[M]
    farm_id = db.Column(db.Integer, db.ForeignKey('farm.id'))

    _time_created = db.Column(db.DateTime(timezone=True),
                              server_default=func.now())
    _time_updated = db.Column(db.DateTime(timezone=True),
                              server_default=func.now(),
                              onupdate=func.now())

    def __repr__(self):
        return '<Water Test {}>'.format(self.id)
Exemplo n.º 7
0
class SoilTest(db.Model):

    __tablename__ = 'soiltest'
    id = db.Column(db.Integer, primary_key=True)
    soil_ph = db.Column(db.Float(precision=2))
    soil_ec = db.Column(db.Float(precision=2))
    soil_organic_carbon = db.Column(db.Float(precision=2))
    soil_nitrogen = db.Column(db.Float(precision=2))
    soil_p205 = db.Column(db.Float(precision=2))
    soil_k20 = db.Column(db.Float(precision=2))

    # FARM[1]-TEST[M]
    farm_id = db.Column(db.Integer, db.ForeignKey('farm.id'))

    _time_created = db.Column(db.DateTime(timezone=True),
                              server_default=func.now())
    _time_updated = db.Column(db.DateTime(timezone=True),
                              server_default=func.now(),
                              onupdate=func.now())

    def __repr__(self):
        return '<Soil Test {}>'.format(self.id)
Exemplo n.º 8
0
class Field(db.Model):
    """Fields that can exist inside the Farm.Model. One Farm can have as many Fields within for different crops to be cultivated, being limited by the size of the Farm"""
    __tablename__ = 'field'
    id = db.Column(db.Integer, primary_key=True)
    field_name = db.Column(db.String(25), nullable=False)
    field_cultivation_area = db.Column(db.Float(precision=2))
    field_cultivation_start_date = db.Column(db.DateTime(timezone=True))
    field_cultivation_finish_date = db.Column(db.DateTime(timezone=True))
    field_current_yield = db.Column(db.Float(precision=2))
    field_projected_yield = db.Column(db.Float(precision=2))
    field_cultivation_state = db.Column(db.String(20))
    field_cultivation_type = db.Column(db.String(5))

    field_num_plants = db.Column(db.Integer)
    field_spacing_topology = db.Column(db.String(20))
    field_water_required_day = db.Column(db.Integer)
    # field_ = db.Column(db.Float)

    # RELATIONSHIP TO BE ADDED
    agrimodule = db.relationship('Agrimodule', uselist=False, backref='field')
    # FIELD[1]-AGRIMODULE[1]

    # RELATIONSHIP
    # FIELD[M]-CROP[M]
    crops = db.relationship('Crop',
                            secondary='crops_field',
                            backref='field',
                            lazy='dynamic')
    # FARM[1]-FIELD[M]
    farm_id = db.Column(db.Integer, db.ForeignKey('farm.id'))

    _time_created = db.Column(db.DateTime(timezone=True),
                              server_default=func.now())
    _time_updated = db.Column(db.DateTime(timezone=True),
                              server_default=func.now(),
                              onupdate=func.now())

    def __repr__(self):
        return '<field {}>'.format(self.field_name)
Exemplo n.º 9
0
class Pump(db.Model):
    """pump database used for each field or each agripump whichi is installed in the farm. one farm can ahve as many pump the want as long as the have an agripump for it"""
    __tablename__ = 'pump'
    id = db.Column(db.Integer, primary_key=True)
    pump_name = db.Column(db.String(30))
    pump_brand = db.Column(db.String(25))
    pump_flow_rate = db.Column(db.Float(precision=2), nullable=False)
    pump_head = db.Column(db.Float(presicion=2), nullable=False)
    pump_watts = db.Column(db.Float(precision=2), nullable=False)

    # RELATIONSHIP
    # USER[1]-PUMP[M]
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    # PUMP[1]-AGRIPUMP
    agripumps = db.relationship('Agripump', backref='pump', lazy='dynamic')

    _time_created = db.Column(db.DateTime(timezone=True),
                              server_default=func.now())
    _time_updated = db.Column(db.DateTime(timezone=True),
                              server_default=func.now(),
                              onupdate=func.now())

    def __repr__(self):
        return '<pump {}>'.format(self.pump_brand)
Exemplo n.º 10
0
class Agripump(db.Model):
    """pump schedule for each farm and agripump, it requires to know which Pump.Model is used in order to make the calculations"""
    __tablename__ = 'agripumps'

    id = db.Column(db.Integer, primary_key=True)

    identifier = db.Column(db.String(50), unique=True)
    lat = db.Column(db.Float(precision=8))
    lon = db.Column(db.Float(precision=8))
    status = db.Column(db.Boolean)

    # REQUIREMENTS
    _daily_water = db.Column(db.Float(precision=3))
    _date = db.Column(db.DateTime(timezone=True))
    # SCHEDULE IN MINUTES
    # _00_HOUR = db.Column(db.Float(precision=1))
    # _01_HOUR = db.Column(db.Float(precision=1))
    # _02_HOUR = db.Column(db.Float(precision=1))
    # _03_HOUR = db.Column(db.Float(precision=1))
    # _04_HOUR = db.Column(db.Float(precision=1))
    # _05_HOUR = db.Column(db.Float(precision=1))
    # _06_HOUR = db.Column(db.Float(precision=1))
    # _07_HOUR = db.Column(db.Float(precision=1))

    # _08_HOUR = db.Column(db.Float(precision=1))
    # _09_HOUR = db.Column(db.Float(precision=1))
    # _10_HOUR = db.Column(db.Float(precision=1))
    # _11_HOUR = db.Column(db.Float(precision=1))
    # _12_HOUR = db.Column(db.Float(precision=1))
    # _13_HOUR = db.Column(db.Float(precision=1))
    # _14_HOUR = db.Column(db.Float(precision=1))
    # _15_HOUR = db.Column(db.Float(precision=1))
    # _16_HOUR = db.Column(db.Float(precision=1))
    # _17_HOUR = db.Column(db.Float(precision=1))

    # _18_HOUR = db.Column(db.Float(precision=1))
    # _19_HOUR = db.Column(db.Float(precision=1))
    # _20_HOUR = db.Column(db.Float(precision=1))
    # _21_HOUR = db.Column(db.Float(precision=1))
    # _22_HOUR = db.Column(db.Float(precision=1))
    # _23_HOUR = db.Column(db.Float(precision=1))

    # TIME USAGE
    start_hour_per_day = db.Column(db.Integer)
    qty_hour_per_day = db.Column(db.Integer)

    time_per_hour = db.Column(db.Float)
    time_per_day = db.Column(db.Float)
    time_per_cycle = db.Column(db.Float)
    # WATER USAGE
    water_per_hour = db.Column(db.Integer)
    water_per_day = db.Column(db.Integer)
    water_per_cycle = db.Column(db.Integer)
    # ENERGY USAGE
    energy_per_hour = db.Column(db.Integer)
    energy_per_day = db.Column(db.Integer)
    energy_per_cycle = db.Column(db.Integer)

    # REALTIONSHIPS
    # AGRIMODULE[1]-AGRIPUMP[M]
    agrimodule_id = db.Column(db.Integer, db.ForeignKey('agrimodules.id'))
    # PUMP[1]-AGRIPUMP[M]
    pump_id = db.Column(db.Integer, db.ForeignKey('pump.id'))

    # SETTINGS
    _time_created = db.Column(db.DateTime(timezone=True),
                              server_default=func.now())
    _time_updated = db.Column(db.DateTime(timezone=True),
                              server_default=func.now(),
                              onupdate=func.now())

    def __repr__(self):
        return '<agripump {}>'.format(self.identifier)
Exemplo n.º 11
0
    water_tests = db.relationship('WaterTest', backref='farm', lazy='dynamic')

    _default = db.Column(db.Boolean)
    _time_created = db.Column(db.DateTime(timezone=True),
                              server_default=func.now())
    _time_updated = db.Column(db.DateTime(timezone=True),
                              server_default=func.now(),
                              onupdate=func.now())

    def __repr__(self):
        return '<farm {}>'.format(self.farm_name)


crops_field = db.Table(
    'crops_field', db.Column('field_id', db.Integer,
                             db.ForeignKey('field.id')),
    db.Column('crop_id', db.Integer, db.ForeignKey('crop.id')))


class SoilTest(db.Model):

    __tablename__ = 'soiltest'
    id = db.Column(db.Integer, primary_key=True)
    soil_ph = db.Column(db.Float(precision=2))
    soil_ec = db.Column(db.Float(precision=2))
    soil_organic_carbon = db.Column(db.Float(precision=2))
    soil_nitrogen = db.Column(db.Float(precision=2))
    soil_p205 = db.Column(db.Float(precision=2))
    soil_k20 = db.Column(db.Float(precision=2))

    # FARM[1]-TEST[M]