-
Notifications
You must be signed in to change notification settings - Fork 0
/
billingSlabProcessor.py
208 lines (159 loc) · 8.03 KB
/
billingSlabProcessor.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import itertools
row = {}
source_headers = ["PropertyType", "UsageCategoryMajor", "UsageCategoryMinor", "UsageCategorySubMinor",
"UsageCategoryDetail", "PropertySubType", "OwnershipCategory", "SubOwnershipCategory",
"isPropertyMultiFloored", "FromPlotSize", "ToPlotSize", "OccupancyType", "FromFloor", "ToFloor",
"Area 1", "Area 2", "Area 3", "arvPercent"]
desitination_headers = ["propertyType", "usageCategoryMajor", "usageCategoryMinor", "usageCategorySubMinor",
"usageCategoryDetail", "propertySubType", "ownerShipCategory", "subOwnerShipCategory",
"isPropertyMultiFloored", "fromPlotSize", "toPlotSize", "occupancyType", "fromFloor", "toFloor",
"areaType", "unitRate", "unBuiltUnitRate", "arvPercent"]
review_headers = ["PropertyType", "UsageCategoryMajor", "UsageCategoryMinor", "UsageCategorySubMinor",
"UsageCategoryDetail", "PropertySubType", "OwnershipCategory", "SubOwnershipCategory",
"isPropertyMultiFloored", "FromPlotSize", "ToPlotSize", "OccupancyType", "FromFloor", "ToFloor",
"areaType", "unitRate", "unBuiltUnitRate", "arvPercent"]
from common import *
TAB_NAME = 'Category 0'
dfs, wks = open_google_spreadsheet(
"https://docs.google.com/spreadsheets/d/1Grd20oHLoC4B5DfuMY8Yud31w7uKY09gM22E2LbH3cs/edit?ts=5b8e2d98#gid=771025646",
TAB_NAME)
dfs[TAB_NAME].to_csv('slabs.csv', index=False, index_label=False)
import io
import csv
import copy
f = io.open("slabs.csv", encoding="utf-8")
c = csv.DictReader(f)
rows = []
for row in c:
area1 = copy.deepcopy(row)
area2 = copy.deepcopy(row)
area3 = copy.deepcopy(row)
area1["areaType"] = "AREA1"
area2["areaType"] = "AREA2"
area3["areaType"] = "AREA3"
area1["unitRate"] = float(area1["Area 1"])
area2["unitRate"] = float(area2["Area 2"])
area3["unitRate"] = float(area3["Area 3"])
area1["unBuiltUnitRate"] = float(area1["Area 1"]) * 0.5
area2["unBuiltUnitRate"] = float(area2["Area 2"]) * 0.5
area3["unBuiltUnitRate"] = float(area3["Area 3"]) * 0.5
for area in [area1, area2, area3]:
area.pop("Area 1")
area.pop("Area 2")
area.pop("Area 3")
rows.extend([area1, area2, area3])
# rows.extend([area1])
level1_rows = []
for row in rows:
multi_data_keys = []
combinations = []
for key, value in row.items():
if type(value) is str and "\n" in value:
multi_data_keys.append(key)
combinations.append(value.split("\n"))
# elif value == "ALLE":
# multi_data_keys.append(key)
# combinations.append(["TEST1", "TEST2"])
if not combinations or len(combinations) == 0:
new_row = copy.deepcopy(row)
level1_rows.append(new_row)
else:
for combo in itertools.product(*combinations):
new_row = copy.deepcopy(row)
for i, key in enumerate(multi_data_keys):
new_row[key] = combo[i]
level1_rows.append(new_row)
# For {PropertySubType= INDEPENDENTPROPERTY} generate slabs for empty land with rate = half of {FromFloor = -10 & ToFloor = -1}
#
# For {PropertySubType= INDEPENDENTPROPERTY} & { isPropertyMultiFloored = TRUE} generate slabs for {FromFloor = -10 & ToFloor = -1} with rate = half of {FromFloor = -10 & ToFloor = -1}
#
# For {PropertySubType= INDEPENDENTPROPERTY} & { isPropertyMultiFloored = TRUE} generate slabs for {FromFloor = 1 & ToFloor = 31} with rate = half of {FromFloor = -10 & ToFloor = -1}
#
# For {PropertySubType= SHAREDPROPERTY} & { isPropertyMultiFloored = TRUE} change slabs {FromFloor = 0 & ToFloor = 0} to {FromFloor = -10 & ToFloor = 31}
#
# For {PropertySubType= SHAREDPROPERTY} & remove { isPropertyMultiFloored = FALSE}
#
# For { OccupancyType = SELFOCCUPIED} generate { OccupancyType = UNOCCUPIED} with rate = half of { OccupancyType = SELFOCCUPIED}
#
# For { UsageCategoryDetail = Malls or MarriagePalace or Multiplex } all rates are same as { PropertySubType = INDEPENDENTPROPERTY} and { FromFloor = 0&ToFloor=0}
f = io.open("level1.csv", encoding="utf-8", mode="w")
c = csv.DictWriter(f, review_headers)
c.writeheader()
c.writerows(level1_rows)
f.close()
level2_rows = []
def fix_row(row):
for key, value in row.items():
if type(value) is str:
fixed_value = value.strip().replace(" ", "").upper()
if value != fixed_value:
row[key] = fixed_value
for row in level1_rows:
fix_row(row)
if row["OccupancyType"] == "RENTED" and row["UsageCategoryMajor"] != "RESIDENTIAL":
if row["isPropertyMultiFloored"] == "TRUE" and row["FromFloor"] == "0" and row["ToFloor"] == "0":
row["FromFloor"] = -10
row["ToFloor"] = 31
level2_rows.append(row)
continue
if row["PropertySubType"] == "SHAREDPROPERTY":
if row["isPropertyMultiFloored"] == "FALSE":
continue
if row["isPropertyMultiFloored"] == "TRUE" and row["FromFloor"] == "0" and row["ToFloor"] == "0":
row["FromFloor"] = -10
row["ToFloor"] = 31
row["unBuiltUnitRate"] = row["unitRate"]
if row["UsageCategoryDetail"] == "MARRIAGEPALACE":
row["unBuiltUnitRate"] = row["unitRate"]
if row["PropertySubType"] != "SHAREDPROPERTY" and ((row["PropertySubType"] == "INDEPENDENTPROPERTY" and row["isPropertyMultiFloored"] == "TRUE")\
or (row["OccupancyType"] == "RENTED" and row["UsageCategoryMajor"] == "RESIDENTIAL" and row["FromFloor"] == "0" and row["ToFloor"] == "0")):
lower_floors = copy.deepcopy(row)
upper_floors = copy.deepcopy(row)
if row["UsageCategoryDetail"] == "MARRIAGEPALACE":
row["unBuiltUnitRate"] = row["unitRate"]
lower_floors["FromFloor"] = -10
lower_floors["ToFloor"] = -1
lower_floors["unitRate"] = row["unitRate"] * 0.5
lower_floors["unBuiltUnitRate"] = row["unitRate"] * 0.5 * 0.5
upper_floors["FromFloor"] = 1
upper_floors["ToFloor"] = 31
upper_floors["unitRate"] = row["unitRate"] * 0.5
upper_floors["unBuiltUnitRate"] = row["unitRate"] * 0.5 * 0.5
if row["PropertySubType"] == "INDEPENDENTPROPERTY" and \
row["UsageCategorySubMinor"] in ("ENTERTAINMENT", "EVENTSPACE", "RETAIL"):
if row["UsageCategoryDetail"] in ("ALL", "MALLS", "MULTIPLEX", "ESTABLISHMENTSINMULTIPLEX", "ESTABLISHMENTSINMALLS"):
lower_floors["unBuiltUnitRate"] = row["unBuiltUnitRate"]
lower_floors["unitRate"] = row["unitRate"]
upper_floors["unBuiltUnitRate"] = row["unBuiltUnitRate"]
upper_floors["unitRate"] = row["unitRate"]
level2_rows.extend([lower_floors, upper_floors])
level2_rows.append(row)
f = io.open("level2.csv", encoding="utf-8", mode="w")
c = csv.DictWriter(f, review_headers)
c.writeheader()
c.writerows(level2_rows)
f.close()
level3_rows = []
for row in level2_rows:
if row["OccupancyType"] == "SELFOCCUPIED":
unoccupied_row = copy.deepcopy(row)
unoccupied_row["OccupancyType"] = "UNOCCUPIED"
unoccupied_row["unitRate"] = row["unitRate"] * 0.5
unoccupied_row["unBuiltUnitRate"] = row["unBuiltUnitRate"] * 0.5
level3_rows.append(unoccupied_row)
level3_rows.append(row)
# print(level3_rows)
f.close()
f = io.open("level3.csv", encoding="utf-8", mode="w")
c = csv.DictWriter(f, review_headers)
c.writeheader()
c.writerows(level3_rows)
f.close()
print("Created billing_slab_generated.csv")
# insert_query = """
# INSERT INTO public.eg_pt_billingslab_v2 (id, tenantid, propertytype, propertysubtype, usagecategorymajor, usagecategoryminor, usagecategorysubminor, usagecategorydetail, ownershipcategory, subownershipcategory, fromfloor, tofloor, areatype, occupancytype, fromplotsize, toplotsize, unitrate, createdby, createdtime, lastmodifiedby, lastmodifiedtime, ispropertymultifloored, unbuiltunitrate, arvpercent) VALUES;
# """
#
# tenant_id = "pb.nawanshahr"
#
# row_template = "('{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}', {}, {}, '{}', )"