# coding: utf-8
from datetime import datetime
from sqlalchemy import Column, Date, DateTime, Float, Index, Integer, String, Text
from sqlalchemy.schema import FetchedValue
from flask_sqlalchemy import SQLAlchemy


# db = SQLAlchemy()

#與當前項目相關的模型文件，即所有的實體類在此編寫
from coffee_manage import db
from werkzeug.utils import send_file

#用戶表
class User(db.Model):
    __tablename__ = 'user'
    userID = db.Column(db.Integer, primary_key=True)
    firstname = db.Column(db.String(30), nullable=False)
    lastname = db.Column(db.String(30), nullable=False)
    mail = db.Column(db.String(50), nullable=False)
    phone = db.Column(db.String(20), nullable=False)
    username = db.Column(db.String(30), nullable=False, unique=True)
    password = db.Column(db.String(40), nullable=False)
    status = db.Column(db.Integer, nullable=False, info='0:admin;1:new;9:disable')

# ////////////////////////////////////////////////////////////////////////////////
# 乾燥槽
# 乾燥桶入料_感測器_超音波感測器
class dry_input_sensor(db.Model):
    __tablename__ = 'dry_input_sensor'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    UltraSonic = db.Column(db.Text, nullable=False)

# 乾燥桶_感測器_SHT11
class dry_tank_SHT11(db.Model):
    __tablename__ = 'dry_tank_SHT11'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    SHT11_Temp = db.Column(db.Text, nullable=False)
    SHT11_Humidity = db.Column(db.Text, nullable=False)

# 乾燥桶_感測器_土壤三合一感測器
class dry_tank_Soil(db.Model):
    __tablename__ = 'dry_tank_Soil'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    soil_Temp = db.Column(db.Text, nullable=False)
    soil_Humidity = db.Column(db.Text, nullable=False)
    soil_EC = db.Column(db.Text, nullable=False)

# 乾燥桶_感測器_超音波感測器
class dry_tank_PA(db.Model):
    __tablename__ = 'dry_tank_PA'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    PA = db.Column(db.Text, nullable=False)

# 乾燥桶_感測器_超音波感測器
class dry_tank_UltraSonic(db.Model):
    __tablename__ = 'dry_tank_UltraSonic'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    UltraSonic = db.Column(db.Text, nullable=False)

# 乾燥桶出料_感測器_超音波感測器
class dry_output_sensor(db.Model):
    __tablename__ = 'dry_output_sensor'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    UltraSonic = db.Column(db.Text, nullable=False)

# 乾燥桶入料_排程設定
class set_dry_input(db.Model):
    __tablename__ = 'set_dry_input'
    # sn
    sn = db.Column(db.Integer, primary_key=True)
    # 存入時間
    datetime = db.Column(db.DateTime, nullable=False)
    # 入料儲豆槽_咖啡豆高度
    input_height = db.Column(db.Text, nullable=False)
    # 乾燥桶_吸料時間
    input_entertime = db.Column(db.Text, nullable=False)
    # 乾燥桶_放料時間
    input_exittime = db.Column(db.Text, nullable=False)
    # 乾燥桶_咖啡豆高度
    tank_height = db.Column(db.Text, nullable=False)

# 乾燥桶入料_致動器_真空吸料機
class dry_input_brake(db.Model):
    __tablename__ = 'dry_input_brake'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    vacuum = db.Column(db.Integer, nullable=False)

#乾燥桶_致動器_ALL
class dry_tank_brake(db.Model):
    __tablename__ = 'dry_tank_brake'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    vacuum = db.Column(db.Integer, nullable=False)
    threewayvalve_input = db.Column(db.Integer, nullable=False)
    threewayvalve_bean = db.Column(db.Integer, nullable=False)
    diskvalve = db.Column(db.Integer, nullable=False)
    solenoid_disinfect = db.Column(db.Integer, nullable=False)
    solenoid_water = db.Column(db.Integer, nullable=False)
    solenoid_outer_water = db.Column(db.Integer, nullable=False)
    motor = db.Column(db.Integer, nullable=False)
    blower = db.Column(db.Integer, nullable=False)
    heater1 = db.Column(db.Integer, nullable=False)
    heater2 = db.Column(db.Integer, nullable=False)
    temp1_enable = db.Column(db.Integer, nullable=False)
    temp1 = db.Column(db.Float, nullable=False)

# 乾燥桶出料_致動器_真空吸料機
class dry_output_brake(db.Model):
    __tablename__ = 'dry_output_brake'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    vacuum = db.Column(db.Integer, nullable=False)
    
# ////////////////////////////////////////////////////////////////////////////////
# 發酵槽
# 發酵槽_發酵貨櫃入料儲豆槽_超音波感測器
class ferment_input_UltraSonic(db.Model):
    __tablename__ = 'ferment_input_UltraSonic'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    UltraSonic = db.Column(db.Text, nullable=False)

# 發酵槽_發酵貨櫃入料儲豆槽_致動器
class ferment_input_actuator(db.Model):
    __tablename__ = 'ferment_input_actuator'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    vacuum = db.Column(db.Integer, nullable=False)

# 發酵槽_感測器_SHT11
class ferment_tank_SHT11(db.Model):
    __tablename__ = 'ferment_tank_SHT11'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    SHT11_Temp = db.Column(db.Text, nullable=False)
    SHT11_Humidity = db.Column(db.Text, nullable=False)

# 發酵槽_感測器_二氧化碳
class ferment_tank_CO2(db.Model):
    __tablename__ = 'ferment_tank_CO2'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    CO2 = db.Column(db.Text, nullable=False)

# 發酵槽_感測器_PH
class ferment_tank_PH(db.Model):
    __tablename__ = 'ferment_tank_PH'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    PH = db.Column(db.Text, nullable=False)

# 發酵槽_感測器_ORP
class ferment_tank_ORP(db.Model):
    __tablename__ = 'ferment_tank_ORP'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    ORP = db.Column(db.Text, nullable=False)

# 發酵槽_感測器_DO
class ferment_tank_DO(db.Model):
    __tablename__ = 'ferment_tank_DO'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    DO = db.Column(db.Text, nullable=False)

# 發酵槽_感測器_EC
class ferment_tank_EC(db.Model):
    __tablename__ = 'ferment_tank_EC'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    EC = db.Column(db.Text, nullable=False)

# 發酵槽_感測器_PA
class ferment_tank_PA(db.Model):
    __tablename__ = 'ferment_tank_PA'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    PA = db.Column(db.Text, nullable=False)

# 發酵槽保溫夾層_感測器_保溫夾層水位計
class ferment_tank_WaterLevel(db.Model):
    __tablename__ = 'ferment_tank_WaterLevel'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    WaterLevel = db.Column(db.Text, nullable=False)

# 發酵槽_感測器_超音波感測器
class ferment_tank_UltraSonic(db.Model):
    __tablename__ = 'ferment_tank_UltraSonic'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    UltraSonic = db.Column(db.Text, nullable=False)

# 發酵槽_感測器_咖啡生豆高度
class ferment_tank_LiDAR(db.Model):
    __tablename__ = 'ferment_tank_LiDAR'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    LiDAR = db.Column(db.Text, nullable=False)

# 發酵槽_感測器_水位高度
class ferment_tank_PressureWaterLevel(db.Model):
    __tablename__ = 'ferment_tank_PressureWaterLevel'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    PressureWaterLevel = db.Column(db.Text, nullable=False)

# 發酵槽_感測器_馬達編碼器
class ferment_tank_motorEncoder(db.Model):
    __tablename__ = 'ferment_tank_motorEncoder'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    motorEncoder = db.Column(db.Text, nullable=False)

# 發酵槽_致動器
class ferment_tank_actuator(db.Model):
    __tablename__ = 'ferment_tank_actuator'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    vacuum = db.Column(db.Integer, nullable=False)
    threewayvalve_input = db.Column(db.Integer, nullable=False)
    diskvalve = db.Column(db.Integer, nullable=False)
    solenoid_tank_pump = db.Column(db.Integer, nullable=False)
    solenoid_tank_disinfect = db.Column(db.Integer, nullable=False)
    solenoid_outer_water = db.Column(db.Integer, nullable=False)
    solenoid_tank_water_in = db.Column(db.Integer, nullable=False)
    solenoid_tank_water_out = db.Column(db.Integer, nullable=False)
    pump_sensor = db.Column(db.Integer, nullable=False)
    threewayvalve_outer_float = db.Column(db.Integer, nullable=False)
    motor = db.Column(db.Integer, nullable=False)
    heater1 = db.Column(db.Integer, nullable=False)
    heater2 = db.Column(db.Integer, nullable=False)
    temp_enable = db.Column(db.Integer, nullable=False)
    temp = db.Column(db.Integer, nullable=False)

# 發酵槽_發酵貨櫃出料儲豆槽_感測器
class ferment_output_UltraSonic(db.Model):
    __tablename__ = 'ferment_output_UltraSonic'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    UltraSonic = db.Column(db.Text, nullable=False)

# 發酵槽_發酵貨櫃出料儲豆槽_致動器
class ferment_output_actuator(db.Model):
    __tablename__ = 'ferment_output_actuator'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    vacuum = db.Column(db.Integer, nullable=False)

# 發酵槽_發酵貨櫃自動化狀態判斷
class ferment_container_status(db.Model):
    __tablename__ = 'ferment_container_status'
    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    Ferment_Input_1 = db.Column(db.Text, nullable=False)
    Ferment_Input_2 = db.Column(db.Text, nullable=False)
    Ferment_Tank_1 = db.Column(db.Text, nullable=False)
    Ferment_Tank_2 = db.Column(db.Text, nullable=False)
    Ferment_Tank_3 = db.Column(db.Text, nullable=False)
    Ferment_Tank_4 = db.Column(db.Text, nullable=False)
    Ferment_Tank_5 = db.Column(db.Text, nullable=False)
    Ferment_Tank_6 = db.Column(db.Text, nullable=False)
    Ferment_Tank_7 = db.Column(db.Text, nullable=False)
    Ferment_Tank_8 = db.Column(db.Text, nullable=False)
    Ferment_Tank_9 = db.Column(db.Text, nullable=False)
    Ferment_Tank_10 = db.Column(db.Text, nullable=False)
    Ferment_Tank_11 = db.Column(db.Text, nullable=False)
    Ferment_Tank_12 = db.Column(db.Text, nullable=False)
    Ferment_Output_1 = db.Column(db.Text, nullable=False)
    Ferment_Output_2 = db.Column(db.Text, nullable=False)

# 乾燥槽_乾燥貨櫃自動化狀態判斷
class dry_container_status(db.Model):
    __tablename__ = 'dry_container_status'
    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    Dry_Input_1 = db.Column(db.Text, nullable=False)
    Dry_Input_2 = db.Column(db.Text, nullable=False)
    Dry_Tank_1 = db.Column(db.Text, nullable=False)
    Dry_Tank_2 = db.Column(db.Text, nullable=False)
    Dry_Tank_3 = db.Column(db.Text, nullable=False)
    Dry_Tank_4 = db.Column(db.Text, nullable=False)
    Dry_Tank_5 = db.Column(db.Text, nullable=False)
    Dry_Tank_6 = db.Column(db.Text, nullable=False)
    Dry_Tank_7 = db.Column(db.Text, nullable=False)
    Dry_Tank_8 = db.Column(db.Text, nullable=False)
    Dry_Tank_9 = db.Column(db.Text, nullable=False)
    Dry_Tank_10 = db.Column(db.Text, nullable=False)
    Dry_Tank_11 = db.Column(db.Text, nullable=False)
    Dry_Tank_12 = db.Column(db.Text, nullable=False)
    Dry_Output_1 = db.Column(db.Text, nullable=False)
    Dry_Output_2 = db.Column(db.Text, nullable=False)

# 乾燥槽_乾燥貨櫃自動化狀態判斷
class clean_container_status(db.Model):
    __tablename__ = 'clean_container_status'
    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    Clean_Input_1 = db.Column(db.Text, nullable=False)
    Clean_Input_2 = db.Column(db.Text, nullable=False)
    Clean_Tank_1 = db.Column(db.Text, nullable=False)
    Clean_Tank_2 = db.Column(db.Text, nullable=False)
    Clean_Tank_3 = db.Column(db.Text, nullable=False)
    Clean_Tank_4 = db.Column(db.Text, nullable=False)
    ColorSelect_Input_1 = db.Column(db.Text, nullable=False)
    ColorSelect_Input_2 = db.Column(db.Text, nullable=False)
    ColorSelect_Tank_1 = db.Column(db.Text, nullable=False)
    ColorSelect_Tank_2 = db.Column(db.Text, nullable=False)
    ColorSelect_Output_g1 = db.Column(db.Text, nullable=False)
    ColorSelect_Output_b1 = db.Column(db.Text, nullable=False)
    ColorSelect_Output_g2 = db.Column(db.Text, nullable=False)
    ColorSelect_Output_b2 = db.Column(db.Text, nullable=False)
    Peel_Tank_1 = db.Column(db.Text, nullable=False)
    Peel_Tank_2 = db.Column(db.Text, nullable=False)
    Peel_Output_1 = db.Column(db.Text, nullable=False)
    Peel_Output_2 = db.Column(db.Text, nullable=False)
    Peel_Output_b1 = db.Column(db.Text, nullable=False)

# ////////////////////////////////////////////////////////////////////////////////
# 清洗貨櫃
# 清洗浮選槽_清洗貨櫃入料儲豆槽_致動器
class clean_input_actuator(db.Model):
    __tablename__ = 'clean_input_actuator'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    vacuum = db.Column(db.Integer, nullable=False)

# 清洗浮選槽_致動器 (old)
class clean_tank_actuator(db.Model):
    __tablename__ = 'clean_tank_actuator'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    vacuum = db.Column(db.Integer, nullable=False)
    pump_waterInput = db.Column(db.Integer, nullable=False)
    pump_waterL2L3 = db.Column(db.Integer, nullable=False)
    pump_waterL4L5 = db.Column(db.Integer, nullable=False)
    solenoid_waterL2L3 = db.Column(db.Integer, nullable=False)
    solenoid_waterL4L5 = db.Column(db.Integer, nullable=False)
    stepping_motor = db.Column(db.Text, nullable=False)

# 清洗浮選槽_致動器 (new)
class cleann_tank_actuator(db.Model):
    __tablename__ = 'cleann_tank_actuator'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    vacuum = db.Column(db.Integer, nullable=False)
    threewayvalve_input = db.Column(db.Integer, nullable=False)
    motor = db.Column(db.Integer, nullable=False)
    solenoid_reclaimed_in = db.Column(db.Integer, nullable=False)
    solenoid_water_in = db.Column(db.Integer, nullable=False)
    pump_water_in = db.Column(db.Integer, nullable=False)
    solenoid_water_out = db.Column(db.Integer, nullable=False)
    solenoid_reclaimed_out = db.Column(db.Integer, nullable=False)
    solenoid_disinfect = db.Column(db.Integer, nullable=False)
    pump_disinfect = db.Column(db.Integer, nullable=False)
    diskvalve = db.Column(db.Integer, nullable=False)

# 清洗浮選槽_清洗貨櫃出料儲豆槽_致動器
class clean_output_actuator(db.Model):
    __tablename__ = 'clean_output_actuator'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    vacuum = db.Column(db.Integer, nullable=False)

# 清洗浮選槽_感測器
class clean_tank_UltraSonic(db.Model):
    __tablename__ = 'clean_tank_UltraSonic'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    UltraSonic = db.Column(db.Text, nullable=False)

class clean_tank_Encoder(db.Model):
    __tablename__ = 'clean_tank_Encoder'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    Encoder = db.Column(db.Text, nullable=False)

class clean_tank_Turbidity(db.Model):
    __tablename__ = 'clean_tank_Turbidity'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    tankTurbidity = db.Column(db.Text, nullable=False)

class clean_filter_Turbidity(db.Model):
    __tablename__ = 'clean_filter_Turbidity'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    filterTurbidity = db.Column(db.Text, nullable=False)

# 脫皮機_清洗貨櫃入料儲豆槽_致動器
class peel_input_actuator(db.Model):
    __tablename__ = 'peel_input_actuator'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    vacuum = db.Column(db.Integer, nullable=False)

# 脫皮機_致動器
class peel_tank_actuator(db.Model):
    __tablename__ = 'peel_tank_actuator'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    vacuum = db.Column(db.Integer, nullable=False)
    motor = db.Column(db.Integer, nullable=False)

# 脫皮機_感測器
class peel_output_UltraSonic(db.Model):
    __tablename__ = 'peel_output_UltraSonic'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    UltraSonic = db.Column(db.Text, nullable=False)

class peel_output_motorEncoder(db.Model):
    __tablename__ = 'peel_output_motorEncoder'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    motorEncoder = db.Column(db.Text, nullable=False)

# 脫皮機_清洗貨櫃出料儲豆槽_致動器
class peel_output_actuator(db.Model):
    __tablename__ = 'peel_output_actuator'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    vacuum = db.Column(db.Integer, nullable=False)

# 色選機_清洗貨櫃出料儲豆槽_致動器
class colorselect_output_actuator(db.Model):
    __tablename__ = 'colorselect_output_actuator'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    vacuum = db.Column(db.Integer, nullable=False)

class colorselect_tank_actuator(db.Model):
    __tablename__ = 'colorselect_tank_actuator'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    vacuum = db.Column(db.Integer, nullable=False)
    motor = db.Column(db.Integer, nullable=False)
    nozzle = db.Column(db.Integer, nullable=False)
    
class colorselect_tank_color(db.Model):
    __tablename__ = 'colorselect_tank_color'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    color = db.Column(db.Integer, nullable=False)

class colorselect_tank_UltraSonic(db.Model):
    __tablename__ = 'colorselect_tank_UltraSonic'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    UltraSonic = db.Column(db.Integer, nullable=False)

# 中水桶_致動器
class reclaimed_tank_actuator(db.Model):
    __tablename__ = 'reclaimed_tank_actuator'
    datetime = db.Column(db.DateTime, nullable=False, primary_key=True)
    tank_num = db.Column(db.Text, nullable=False)
    solenoid_water_in = db.Column(db.Integer, nullable=False)
    solenoid_water_out = db.Column(db.Integer, nullable=False)
    solenoid_reclaimed_out = db.Column(db.Integer, nullable=False)
    pump_reclaimed_out = db.Column(db.Integer, nullable=False)

# ////////////////////////////////////////////////////////////////////////////////



#發酵槽溫度感測器表
class TankTemSensor(db.Model):
    __tablename__ = 'tank_tem_sensor'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    tem = db.Column(db.Text, nullable=False)

#發酵槽二氧化碳感測器表
class TankCO2Sensor(db.Model):
    __tablename__ = 'tank_co2_sensor'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    co2 = db.Column(db.Text, nullable=False)

#發酵槽酸鹼值感測器表
class TankPHSensor(db.Model):
    __tablename__ = 'tank_ph_sensor'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    ph = db.Column(db.Text, nullable=False)

#發酵槽酸鹼值感測器表
class TankECSensor(db.Model):
    __tablename__ = 'tank_ec_sensor'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    ec = db.Column(db.Text, nullable=False)

#發酵槽超音波感測器表
class TankSonicSensor(db.Model):
    __tablename__ = 'tank_sonic_sensor'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    sonic = db.Column(db.Text, nullable=False)


class BeanValve(db.Model):
    __tablename__ = 'bean_valve'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)

class WashMachine(db.Model):
    __tablename__ = 'wash_machine'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)

class ConveyorBelt1(db.Model):
    __tablename__ = 'conveyor_belt1'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)

class Cargo1Disinfect(db.Model):
    __tablename__ = 'cargo1_disinfect'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)

class ColorMachine(db.Model):
    __tablename__ = 'color_machine'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)

class ConveyorBelt2(db.Model):
    __tablename__ = 'conveyor_belt2'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)

class PeelingMachine(db.Model):
    __tablename__ = 'peeling_machine'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)



class ConveyorBelt3(db.Model):
    __tablename__ = 'conveyor_belt3'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)



class Bacteria(db.Model):
    __tablename__ = 'bacteria'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)

class Cargo2Disinfect(db.Model):
    __tablename__ = 'cargo2_disinfect'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)

class Heating(db.Model):
    __tablename__ = 'heating'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)

class Stir(db.Model):
    __tablename__ = 'stir'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)

class WaterInjection(db.Model):
    __tablename__ = 'water_injection'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)



class TopValve(db.Model):
    __tablename__ = 'top_valve'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)

class BottomValve(db.Model):
    __tablename__ = 'bottom_valve'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)

class Temperature(db.Model):
    __tablename__ = 'temperature'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)

class Hoist(db.Model):
    __tablename__ = 'hoist'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)

class Dryer(db.Model):
    __tablename__ = 'dryer'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    duration = db.Column(db.Text, nullable=False)
    start = db.Column(db.Text, nullable=False)
    end = db.Column(db.Text, nullable=False)

class Relay(db.Model):
    __tablename__ = 'relay'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    status= db.Column(db.Text, nullable=False)


class PeelingMachineRPM(db.Model):
    __tablename__ = 'peeling_machine_rpm'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    rpm = db.Column(db.Text, nullable=False)

class StirRPM(db.Model):
    __tablename__ = 'stir_rpm'

    sn = db.Column(db.Integer, primary_key=True)
    datetime = db.Column(db.DateTime, nullable=False)
    tank_num = db.Column(db.Integer, nullable=False)
    rpm = db.Column(db.Text, nullable=False)



db.create_all()