-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
159 lines (140 loc) · 6.51 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# coding: utf-8
from flask import Flask
from sqlalchemy import BigInteger, Column, DateTime, Float, Integer, String
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
from app import __name__ as app_name
# init app
app = Flask(app_name)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:3113@localhost/ELEC'
app.config['SECRET_KEY'] = 'thisissecret'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# init db
db = SQLAlchemy(app)
# init ma
ma = Marshmallow(app)
# MeterInfo Class/Model
class MeterInfo(db.Model):
__tablename__ = 'MeterInfo'
TimeTag = db.Column(db.BigInteger, primary_key=True, nullable=False)
ID = db.Column(db.String(64), primary_key=True, nullable=False)
GUID = db.Column(db.String(128))
MeterID = db.Column(db.String(64))
MeterType = db.Column(db.String(32))
MeterSerialNumber = db.Column(db.String(64))
Date = db.Column(db.DateTime)
ShmasiDate = db.Column(db.String(32))
SourceID = db.Column(db.String(64))
SourceName = db.Column(db.String(64))
PowerActive = db.Column(db.Float(53))
PowerReactive = db.Column(db.Float(53))
VoltagePhaseA = db.Column(db.Float(53))
VoltagePhaseB = db.Column(db.Float(53))
VoltagePhaseC = db.Column(db.Float(53))
VoltagePhaseN = db.Column(db.Float(53))
CurrentPhaseA = db.Column(db.Float(53))
CurrentPhaseB = db.Column(db.Float(53))
CurrentPhaseC = db.Column(db.Float(53))
CurrentPhaseN = db.Column(db.Float(53))
PhaseAAngle = db.Column(db.Float(53))
PhaseBAngle = db.Column(db.Float(53))
PhaseCAngle = db.Column(db.Float(53))
PhaseNAngle = db.Column(db.Float(53))
Frequency = db.Column(db.Float(53))
ActiveEnergy = db.Column(db.Float(53))
ReactiveEnergy = db.Column(db.Float(53))
VoltageL1 = db.Column(db.Float(53))
VoltageL2 = db.Column(db.Float(53))
VoltageL3 = db.Column(db.Float(53))
CurrentL1 = db.Column(db.Float(53))
CurrentL2 = db.Column(db.Float(53))
CurrentL3 = db.Column(db.Float(53))
demand = db.Column(db.Float(53))
PowerFactor = db.Column(db.Float(53))
ActiveEnergyExport = db.Column(db.Float(53))
ReActiveEnergyExport = db.Column(db.Float(53))
ProfileStatusEnergy = db.Column(db.Integer)
ProfileStatusPower = db.Column(db.Integer)
# MeterInfo Schema
class MeterInfoSchema(ma.Schema):
class Meta:
fields = ("TimeTag", "ID", "PowerActive", "PowerReactive", "Frequency", "ActiveEnergy",
"ReactiveEnergy", "VoltageL1", "VoltageL2", "VoltageL3", "CurrentL1", "CurrentL2",
"CurrentL3", "demand", "PowerFactor", "ActiveEnergyExport", "ReActiveEnergyExport",
"ProfileStatusEnergy", "ProfileStatusPower")
# init Schema
meterinfo_schema = MeterInfoSchema(strict=True)
metersinfo_schema = MeterInfoSchema(many=True, strict=True)
# Customer Class/Model
class Customer(db.Model):
__tablename__ = 'Customer'
xSubscriptionId_Pk = db.Column(db.BigInteger,primary_key=True, nullable=False)
xSubscriberLastUpdateDate = db.Column(db.Integer)
xSubscriberId_pk = db.Column(db.Integer)
xSubscriptionLogId_fk = db.Column(db.BigInteger)
xSubscriberFirstName = db.Column(db.String(50))
xSubscriberLastName = db.Column(db.String(50))
xSubscriberMobile = db.Column(db.String(11))
xSubscriptionPostCode = db.Column(db.String(10))
xSubscriberTelNo = db.Column(db.String(20))
xSubscriptionAddress = db.Column(db.String(250))
xSubscriberIsActive = db.Column(db.Boolean)
xSubscriptionUsageAvg = db.Column(db.Float(53))
xGISCode = db.Column(db.String(30))
xSubscriberAddress = db.Column(db.String(250))
xComunicateAddress = db.Column(db.String(250))
xDepartmentName = db.Column(db.String(50))
xFatherName = db.Column(db.String(50))
xSubscriptionDebit = db.Column(db.BigInteger)
xCasteName = db.Column(db.String(50))
xServiceLineName = db.Column(db.String(60))
xContractPower = db.Column(db.Integer)
xFaze = db.Column(db.String(1))
xAmper = db.Column(db.SmallInteger)
xCounterBuldingNo = db.Column(db.String(20))
xCounterMultiple = db.Column(db.Float(53))
xDigitNum = db.Column(db.SmallInteger)
xDimandmeterDomain = db.Column(db.Integer)
xCounterTypeName = db.Column(db.String(30))
xRegionName = db.Column(db.String(50))
xBranchStateName = db.Column(db.String(25))
xLongitude = db.Column(db.Float(53))
xLatitude = db.Column(db.Float(53))
xSubscriptionLevelName = db.Column(db.String(50))
xPayDelayCount = db.Column(db.SmallInteger)
xBakhshName = db.Column(db.String(30))
xOmorName = db.Column(db.String(60))
xActiveCounterId_fk = db.Column(db.Integer)
xUsageTypeName = db.Column(db.String(250))
xUsageGroupName = db.Column(db.String(100))
xUsageSubGroupName = db.Column(db.String(50))
xISIC_Code = db.Column(db.String(10))
xISIC_Name = db.Column(db.String(100))
xPrevOutPowerCount = db.Column(db.Integer)
xPrev3TariffDayNums = db.Column(db.Integer)
xPrevSureBillCount = db.Column(db.Integer)
xTariffName = db.Column(db.String(50))
# Customer Schema
class CustomerSchema(ma.Schema):
class Meta:
fields = ("xSubscriptionId_Pk", "xSubscriberLastUpdateDate",
"xSubscriberId_pk", "xSubscriptionLogId_fk", "xSubscriberFirstName",
"xSubscriberLastName", "xSubscriberMobile", "xSubscriptionPostCode",
"xSubscriberTelNo", "xSubscriptionAddress", "xSubscriberIsActive",
"xSubscriptionUsageAvg", "xGISCode", "xSubscriberAddress", "xComunicateAddress",
"xDepartmentName", "xFatherName", "xSubscriptionDebit", "xCasteName", "xServiceLineName",
"xContractPower", "xFaze", "xAmper", "xCounterBuldingNo", "xCounterMultiple", "xDigitNum",
"xDimandmeterDomain", "xCounterTypeName", "xRegionName", "xBranchStateName", "xLongitude",
"xLatitude", "xSubscriptionLevelName", "xPayDelayCount", "xBakhshName", "xOmorName",
"xActiveCounterId_fk", "xUsageTypeName", "xUsageGroupName", "xUsageSubGroupName",
"xISIC_Code", "xISIC_Name", "xPrevOutPowerCount", "xPrev3TariffDayNums", "xPrevSureBillCount",
"xTariffName")
# init Schema
customer_schema = CustomerSchema(strict=True)
customers_schema = CustomerSchema(many=True, strict=True)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
public_id = db.Column(db.String(50), unique=True)
name = db.Column(db.String(50))
password = db.Column(db.String(80))
admin = db.Column(db.Boolean)