-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscratchXml.py
More file actions
175 lines (137 loc) · 6.72 KB
/
scratchXml.py
File metadata and controls
175 lines (137 loc) · 6.72 KB
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
#custom XML module YATTAG wouldn't take data correctly so I said Fuck it and XML will be written from scratch
#Distress comment for every distress listed
DistressComment = "Imported"
#row[INSPECTED_SIZE]-- set actual square footage - excel sheet has different size
#inspectedSize=row[P_LENGTH]*row[P_WIDTH]
inspectedSize = row[SAMPLESIZE]
#PCI condition, doesn't import
condition=1
#
#check the severity of the distress and give Low Medium or High value
#will probably need changing/uneccessary with new data.
#not needed as of 2.17.20 - severity pulled from excel
#def severityConvert(rowDataHere):
# severityReal = "NONE"
# if rowDataHere == 1:
# severityReal = "L"
# elif rowDataHere == 2:
# severityReal = "M"
# elif rowDataHere == 3:
# severityReal = "H"
# print("severityConvert Testing", severityReal)
# return severityReal
#spaces for XML indention since YATTAG isn't working
iS=" "
#unneeded @ this time, current sheet has L M H
######CALL severityConvert TO CONVERT # to L M H
#alligator_Severity=severityConvert(row[ALLIGATOR_S])
#potHole_Severity=severityConvert(row[POTHOLE_S])
#print(sWeathering, sampleNumber, distressQuantity)
# set spacing for indentation
#set pid without editing excel sheet to format NETWORK::STREET::PID#
#addressID can only be 10 characters
address=str(row[INSPECTED_PID1]).replace(" ","")
address=address.replace(".","")
address=address.replace("/","")
address=address.upper()
#cut address to 10 char
addressCut=address[0:10]
fullpid="WINFIELD::" + addressCut + "::" + str(row[INSPECTED_PID2])
#set date to proper format
spread_date = row[INSPECTED_DATE]
parsed_date = datetime.strftime(spread_date, "%m/%d/%Y")
#temporary date needed due to date change and not present in excel
#or set dateSet=parsed_date to pull a proper parsed date from spreadsheet
dateSet=parsed_date
#print(xml_header, "\n", xml_schema, "\n", file=f) and opening xml tags
#manually write XML data to filename.xml
#Changed comment to say Imp: for imported to identify
#removed size, unneeded at this time
#
print(iS, "<geospatialInspectionData inspectionDate=\"",dateSet,"\"", " units=\"English\" level=\"SAMPLE\" >", sep="", file=f)
print(iS*2, "<inspectedElement inspectedElementID=\"", row[SAMPLENUMBER], "\"", " size=\"", inspectedSize, "\" ", "PID=\"", fullpid, "\" inspectedType=\"R\" comment=\"",DistressComment, "\" noDistresses=\"false\">", sep="", file=f)
#if row[ALLIGATOR_S] > 0 or row[POTHOLE_S] > 0:
print (iS*3, "<inspectionData>", sep="", file=f)
#E = extent, S = severity, unsure how to assign which to which at this point 11.09.20
#Set distress codes to dict, check to see if ANY codes are > 0, then write
#iterating through isn't working...
#unneeded at this time, but I don't have to ty[e ro[blahblah] everytime, so...
distressCodes = {
'sweatherC': row[SWEATHERING_CODE],
'sweatherS': row[SWEATHERING_S],
'sweatherQ': row[SWEATHERING_Q],
'alligatorC': row[ALLIGATOR_CODE],
'alligatorS': row[ALLIGATOR_S],
'alligatorQ': row[ALLIGATOR_Q],
'blockcrackC': row[BLOCKCRACK_CODE],
'blockcrackS': row[BLOCKCRACK_S],
'blockcrackQ': row[BLOCKCRACK_Q],
'trasnverseC': row[TRANSVERSE__CODE],
'trasnverseS': row[TRANSVERSE_S],
'trasnverseQ': row[TRANSVERSE_Q],
'depressionC': row[DEPRESSION_CODE],
'depressionS': row[DEPRESSION_S],
'depressionQ': row[DEPRESSION_Q],
'potholeC': row[POTHOLE_CODE],
'potholeS': row[POTHOLE_S],
'potholeQ': row[POTHOLE_Q],
'edgecrackC': row[EDGECRACKING_CODE],
'edgecrackS': row[EDGECRACKING_S],
'edgecrackQ': row[EDGECRACKING_Q],
'jointspallC': row[JOINTSPALLING_CODE],
'jointspallS': row[JOINTSPALLING_S],
'jointspallQ': row[JOINTSPALLING_Q],
'durabilityC': row[DURABILITYCRACKING_CODE],
'durabilityS': row[DURABILITYCRACKING_S],
'durabilityQ': row[DURABILITYCRACKING_Q],
'faultC': row[FAULTING_CODE],
'faultS': row[FAULTING_S],
'faultQ': row[FAULTING_Q],
'patchingC': row[PATCHING_CODE],
'patchingS': row[PATCHING_S],
'patchingQ': row[PATCHING_Q],
'bumpsagC': row[BUMPSAG_CODE],
'bumpsagS': row[BUMPSAG_S],
'bumpsagQ': row[BUMPSAG_Q]
}
#used for checking data as we run through
distressCheck = []
distressCheck += distressCodes.values()
#print (distressCheck)
#Function for printing distress to file
def distressPrint(code, severity, quantity):
try:
if float(code) > 0:
print (iS*6, "<levelDistress distressCode=\"", code, "\"", " severity=\"", severity, "\" quantity=\"", abs(quantity), "\"", " comment=\"", DistressComment, "\" />", sep="", file=f)
fullData()
except ValueError:
emptyData()
#forced to run function individually with each var unfortunately: iterating through the dict/list was not working, int/str issues with ">"
print (iS*5, "<PCIDistresses>", sep="", file=f)
distressPrint(distressCodes["sweatherC"],distressCodes["sweatherS"],distressCodes["sweatherQ"])
distressPrint(distressCodes["alligatorC"],distressCodes["alligatorS"],distressCodes["alligatorQ"])
distressPrint(distressCodes["blockcrackC"],distressCodes["blockcrackS"],distressCodes["blockcrackQ"])
distressPrint(distressCodes["trasnverseC"],distressCodes["trasnverseS"],distressCodes["trasnverseQ"])
distressPrint(distressCodes["depressionC"],distressCodes["depressionS"],distressCodes["depressionQ"])
distressPrint(distressCodes["potholeC"],distressCodes["potholeS"],distressCodes["potholeQ"])
distressPrint(distressCodes["edgecrackC"],distressCodes["edgecrackS"],distressCodes["edgecrackQ"])
distressPrint(distressCodes["jointspallC"],distressCodes["jointspallS"],distressCodes["jointspallQ"])
distressPrint(distressCodes["durabilityC"],distressCodes["durabilityS"],distressCodes["durabilityQ"])
distressPrint(distressCodes["faultC"],distressCodes["faultS"],distressCodes["faultQ"])
distressPrint(distressCodes["patchingC"],distressCodes["patchingS"],distressCodes["patchingQ"])
distressPrint(distressCodes["bumpsagC"],distressCodes["bumpsagS"],distressCodes["bumpsagQ"])
print (iS*5, "</PCIDistresses>", sep="", file=f)
#close initial opened xml tags
#if row[ALLIGATOR_S] > 0 or row[POTHOLE_S] > 0:
print (iS*3, "</inspectionData>", sep="", file=f)
print(iS*2, "</inspectedElement>", sep="", file=f)
print(iS, "</geospatialInspectionData>", sep="", file=f)
#generic "inspection info," seems to be needed for each inspection despite appearance of duplicate information.
print (iS, "<geospatialInspectionData level=\"SECTION\" units=\"English\" inspectionDate=\"", dateSet, "\" >", sep="", file=f)
print (iS*2, "<inspectedConditions PID=\"", fullpid, "\" >", sep="", file=f)
print (iS*3, "<conditions>", sep="", file=f)
print (iS*4, "<levelCondition comment=\"\" source=\"\" cndMeasureUID=\"StructPCI\" cndMeasure=\"SCI\" conditionText=\"\" condition=\"", condition, "\"/>", sep="", file=f)
print (iS*3, "</conditions>", sep="", file=f)
print (iS*2, "</inspectedConditions>", sep="", file=f)
print (iS, "</geospatialInspectionData>", sep="", file=f)
#end