first commit

This commit is contained in:
Senad Uka
2017-11-07 09:23:57 +01:00
commit 0eee92660a
356 changed files with 747259 additions and 0 deletions

View File

View File

@@ -0,0 +1,14 @@
from sqlalchemy import Column, Integer, ForeignKey
from helix.models.sql.shared_sql_base import Base
class InverterBrand(Base):
__tablename__ = 'inverter_brands'
id = Column(Integer, primary_key=True)
site_id = Column(Integer, ForeignKey('sites.id'), primary_key=True)
def to_json(self):
return {
'inverter_brand_id': self.id,
}

View File

@@ -0,0 +1,29 @@
from sqlalchemy import Column, Integer, Enum, Boolean, ForeignKey, CheckConstraint
from helix.constants.inverter_type import InverterType
from helix.models.sql.shared_sql_base import Base
class Inverter(Base):
__tablename__ = 'inverters'
id = Column(Integer, primary_key=True)
model = Column(Enum(*map(lambda x: str(x.value), InverterType.all()), name='invertertype'), nullable=False)
strings_per_inverter = Column(Integer, nullable=False)
sunshade = Column(Boolean)
dc_switch = Column(Boolean)
splice_box = Column(Boolean)
power_station_id = Column(Integer, ForeignKey('power_stations.id'))
standalone_inverter_id = Column(Integer, ForeignKey('standalone_inverters.id', ondelete='CASCADE'))
__table_args__ = (
CheckConstraint('(power_station_id IS NULL != standalone_inverter_id IS NULL)'),
)
def to_json(self):
inverter_type = InverterType.SMA if int(self.model) in InverterType.SMA.all() else InverterType.DELTA
return {
'model': inverter_type(int(self.model)),
'strings_per_inverter': self.strings_per_inverter,
'sunshade': self.sunshade,
'dc_switch': self.dc_switch,
'splice_box': self.splice_box,
}

View File

@@ -0,0 +1,21 @@
from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.orm import relationship
from helix.models.sql.shared_sql_base import Base
class PowerMonitor(Base):
__tablename__ = 'power_monitors'
id = Column(Integer, primary_key=True)
site_id = Column(Integer, ForeignKey('sites.id'))
power_station_id = Column(Integer, ForeignKey('power_stations.id'))
power_station = relationship("PowerStation")
def to_json(self):
if self.power_station:
power_source = (self.power_station.description, self.power_station.id)
else:
power_source = ('Switch Gear/External', None)
return {
'monitor_id': self.id,
'power_source': power_source
}

View File

@@ -0,0 +1,24 @@
from sqlalchemy import Column, Integer, Unicode, ForeignKey
from sqlalchemy.orm import relationship
from helix.models.sql.inverters import Inverter
from helix.models.sql.shared_sql_base import Base
class PowerStation(Base):
__tablename__ = 'power_stations'
id = Column(Integer, primary_key=True)
site_id = Column(Integer, ForeignKey('sites.id'))
quantity = Column(Integer, nullable=False)
ac_run_length = Column(Integer, nullable=False)
description = Column(Unicode, nullable=False)
inverters = relationship(Inverter.__name__, backref="power_stations", cascade="save-update, merge, delete")
def to_json(self):
return {
'inverter_quantity': len(self.inverters),
'power_station_quantity': self.quantity,
'power_station_description': self.description,
'power_station_id': self.id,
'ac_run_length': self.ac_run_length,
'inverters': [inverter.to_json() for inverter in self.inverters]
}

View File

@@ -0,0 +1,3 @@
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()

41
helix/models/sql/sites.py Normal file
View File

@@ -0,0 +1,41 @@
from sqlalchemy import Column, Integer, Unicode, Float, Enum, ForeignKey
from sqlalchemy.orm import relationship
from helix.constants.anchor_type import AnchorType
from helix.constants.module_type import ModuleType
from helix.constants.system_type import SystemType
from helix.models.sql.inverter_brands import InverterBrand
from helix.models.sql.power_monitors import PowerMonitor
from helix.models.sql.power_stations import PowerStation
from helix.models.sql.shared_sql_base import Base
from helix.models.sql.standalone_inverters import StandaloneInverter
class Site(Base):
__tablename__ = 'sites'
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
project_name = Column(Unicode, nullable=False)
building_height = Column(Float, nullable=False)
building_width = Column(Float, nullable=False)
building_length = Column(Float, nullable=False)
parapet_height = Column(Float, nullable=False)
wind_speed = Column(Integer, nullable=False)
exposure_category = Column(Unicode, nullable=False)
exposure_transition_distance = Column(Integer)
ballast_block_weight = Column(Integer, nullable=False)
max_psf = Column(Float, nullable=False)
system_type = Column(Enum(SystemType.singleTilt.value, SystemType.dualTilt.value, name='SystemType'), nullable=False)
module_type = Column(Enum(ModuleType.Cell96.value, ModuleType.Cell128.value, ModuleType.PSeries.value, name='ModuleType'), nullable=False)
anchor_type = Column(Enum(AnchorType.OMG_PowerGrip.value, AnchorType.OMG_PowerGrip_Plus.value, AnchorType.EcoFasten.value, name='AnchorType'), nullable=False)
spectral_response = Column(Float, nullable=False)
seismic_importance_factor = Column(Float, nullable=False)
cad_file = Column(Unicode)
cad_file_name = Column(Unicode)
dxf_file = Column(Unicode)
dxf_file_name = Column(Unicode)
inverter_brands = relationship(InverterBrand.__name__, backref="site", cascade="save-update, merge, delete")
power_stations = relationship(PowerStation.__name__, backref="site", cascade="save-update, merge, delete")
standalone_inverters = relationship(StandaloneInverter.__name__, backref="site", cascade="save-update, merge, delete")
power_monitors = relationship(PowerMonitor.__name__, backref="site", cascade="save-update, merge, delete")

View File

@@ -0,0 +1,29 @@
from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.orm import relationship, backref
from helix.models.sql.inverters import Inverter
from helix.models.sql.power_stations import PowerStation
from helix.models.sql.shared_sql_base import Base
class StandaloneInverter(Base):
__tablename__ = 'standalone_inverters'
id = Column(Integer, primary_key=True)
site_id = Column(Integer, ForeignKey('sites.id'))
ac_run_length = Column(Integer, nullable=False)
inverter = relationship(Inverter.__name__,
backref=backref("standalone_inverters", uselist=False),
cascade="save-update, merge, delete")
attachment_point_id = Column(Integer, ForeignKey('power_stations.id'))
attachment_point = relationship(PowerStation.__name__)
def to_json(self):
if self.attachment_point:
attachment_point = (self.attachment_point.description, self.attachment_point.id)
else:
attachment_point = ('Switch Gear', None)
return { **{
'standalone_inverter_id': self.id,
'ac_run_length': self.ac_run_length,
'attachment_point': attachment_point
}, **(self.inverter[0].to_json()) }

View File

@@ -0,0 +1,9 @@
from sqlalchemy import Column, Integer, Unicode
from helix.models.sql.shared_sql_base import Base
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
username = Column(Unicode, nullable=False)
password_hash = Column(Unicode, nullable=False)