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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from platform import python_version
|
| 3 |
+
import os
|
| 4 |
+
import pandas as pd
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
import openpyxl
|
| 7 |
+
from openpyxl.styles import PatternFill, Border, Side
|
| 8 |
+
from openpyxl.utils.dataframe import dataframe_to_rows
|
| 9 |
+
from openpyxl import Workbook
|
| 10 |
+
# [theme]
|
| 11 |
+
# primaryColor = "#E694FF"
|
| 12 |
+
# backgroundColor = "#00172B"
|
| 13 |
+
# secondaryBackgroundColor = "#0083B8"
|
| 14 |
+
# textColor = "#C6CDD4"
|
| 15 |
+
# font = "sans-serif"
|
| 16 |
+
# add_selectbox = st.sidebar.selectbox(
|
| 17 |
+
# "How would you like to be contacted?",
|
| 18 |
+
# ("Email", "Home phone", "Mobile phone")
|
| 19 |
+
# )
|
| 20 |
+
|
| 21 |
+
# Using "with" notation
|
| 22 |
+
# with st.sidebar:
|
| 23 |
+
# add_radio = st.radio(
|
| 24 |
+
# "Choose a shipping method",
|
| 25 |
+
# ("Standard (5-15 days)", "Express (2-5 days)")
|
| 26 |
+
# )
|
| 27 |
+
def tut4(of):
|
| 28 |
+
u = of['U'] # assigning a list to columns of input file
|
| 29 |
+
v = of['V']
|
| 30 |
+
w = of['W']
|
| 31 |
+
t = of['T']
|
| 32 |
+
|
| 33 |
+
# calculating the avg value sum() returns summation and len() return length
|
| 34 |
+
avgu = [sum(u) / len(u)]
|
| 35 |
+
avgv = [sum(v) / len(v)]
|
| 36 |
+
avgw = [sum(w) / len(w)]
|
| 37 |
+
|
| 38 |
+
au = sum(u) / len(u)
|
| 39 |
+
av = sum(v) / len(v)
|
| 40 |
+
aw = sum(w) / len(w)
|
| 41 |
+
|
| 42 |
+
u_ = []
|
| 43 |
+
v_ = []
|
| 44 |
+
w_ = []
|
| 45 |
+
|
| 46 |
+
for i in u:
|
| 47 |
+
u_.append(i - au) # pushing the element at back of list
|
| 48 |
+
for i in v:
|
| 49 |
+
v_.append(i - av)
|
| 50 |
+
for i in w:
|
| 51 |
+
w_.append(i - aw)
|
| 52 |
+
|
| 53 |
+
# filling the remaining spaces in the column with blank space using extend function
|
| 54 |
+
avgu.extend([''] * (len(u) - 1))
|
| 55 |
+
avgv.extend([''] * (len(u) - 1))
|
| 56 |
+
avgw.extend([''] * (len(u) - 1))
|
| 57 |
+
|
| 58 |
+
octs = [1, -1, 2, -2, 3, -3, 4, -4]
|
| 59 |
+
|
| 60 |
+
lenc = {} # dictionary to store longest subsequence length for each octant
|
| 61 |
+
for i in octs:
|
| 62 |
+
lenc[i] = 0
|
| 63 |
+
|
| 64 |
+
octants = [] # list to store octants for each case
|
| 65 |
+
|
| 66 |
+
col2 = [] # column to store longest subsequence length for each octant
|
| 67 |
+
col4 = [] # column to store octants and time row
|
| 68 |
+
col5 = [] # column to store start time
|
| 69 |
+
col6 = [] # column to store end time
|
| 70 |
+
|
| 71 |
+
# loop to determine the octant and to store the octants
|
| 72 |
+
# and update the length of subsequence with maxmimum length each time
|
| 73 |
+
c = 1
|
| 74 |
+
p = 1
|
| 75 |
+
for i in range(len(u_)):
|
| 76 |
+
oc = 1
|
| 77 |
+
if (u_[i] > 0) and (v_[i] > 0) and (w_[i] > 0):
|
| 78 |
+
oc = 1
|
| 79 |
+
elif (u_[i]) < 0 and (v_[i]) > 0 and (w_[i]) > 0:
|
| 80 |
+
oc = 2
|
| 81 |
+
elif (u_[i]) < 0 and (v_[i]) < 0 and (w_[i]) > 0:
|
| 82 |
+
oc = 3
|
| 83 |
+
elif (u_[i]) > 0 and (v_[i]) < 0 and (w_[i]) > 0:
|
| 84 |
+
oc = 4
|
| 85 |
+
elif (u_[i]) > 0 and (v_[i]) > 0 and (w_[i]) < 0:
|
| 86 |
+
oc = -1
|
| 87 |
+
elif (u_[i]) < 0 and (v_[i]) > 0 and (w_[i]) < 0:
|
| 88 |
+
oc = -2
|
| 89 |
+
elif (u_[i]) < 0 and (v_[i]) < 0 and (w_[i]) < 0:
|
| 90 |
+
oc = -3
|
| 91 |
+
elif (u_[i]) > 0 and (v_[i]) < 0 and (w_[i]) < 0:
|
| 92 |
+
oc = -4
|
| 93 |
+
|
| 94 |
+
octants.append(oc)
|
| 95 |
+
if i > 0:
|
| 96 |
+
if oc == p:
|
| 97 |
+
c += 1
|
| 98 |
+
else:
|
| 99 |
+
c = 1
|
| 100 |
+
p = oc
|
| 101 |
+
lenc[oc] = max(lenc[oc], c)
|
| 102 |
+
|
| 103 |
+
octants.extend([''] * (len(u_) - len(octants)))
|
| 104 |
+
|
| 105 |
+
of[' '] = ''
|
| 106 |
+
|
| 107 |
+
col1 = [] # column to store the octant values
|
| 108 |
+
for i in octs:
|
| 109 |
+
col1.append(i)
|
| 110 |
+
|
| 111 |
+
col1.extend([''] * (len(u_) - len(col1)))
|
| 112 |
+
of['Octant ##'] = col1
|
| 113 |
+
|
| 114 |
+
# column to store the longest subsequence length for each octant value
|
| 115 |
+
for i in lenc.values():
|
| 116 |
+
col2.append(i)
|
| 117 |
+
|
| 118 |
+
col2.extend([''] * (len(u_) - len(col2)))
|
| 119 |
+
of['Longest Subsequence Length'] = col2
|
| 120 |
+
|
| 121 |
+
col3 = [] # column to store count of longest subsequence for each octant value
|
| 122 |
+
|
| 123 |
+
maxc = {} # dictionary to store count of longest subsequence for each octant value
|
| 124 |
+
maxl = {} # dictionary to store start and end time for each octant's longest subsequence
|
| 125 |
+
for i in octs:
|
| 126 |
+
maxc[i] = 0
|
| 127 |
+
maxl[i] = []
|
| 128 |
+
|
| 129 |
+
p = 0
|
| 130 |
+
c = 1
|
| 131 |
+
time = t[0]
|
| 132 |
+
f = 0
|
| 133 |
+
j = 0
|
| 134 |
+
# loop performing required operations to store count of longest subsequence for each octant value
|
| 135 |
+
# and start and end time for each longest subsequence of individual octant
|
| 136 |
+
for i in octants:
|
| 137 |
+
if f == 0:
|
| 138 |
+
time = t[j]
|
| 139 |
+
f = 1
|
| 140 |
+
oc = i
|
| 141 |
+
if oc == p:
|
| 142 |
+
c += 1
|
| 143 |
+
else:
|
| 144 |
+
c = 1
|
| 145 |
+
time = t[j]
|
| 146 |
+
|
| 147 |
+
if c == lenc[oc]:
|
| 148 |
+
maxc[oc] += 1
|
| 149 |
+
maxl[oc].append([time, t[j]])
|
| 150 |
+
f = 0
|
| 151 |
+
|
| 152 |
+
p = oc
|
| 153 |
+
j = j + 1
|
| 154 |
+
|
| 155 |
+
for i in maxc.values():
|
| 156 |
+
col3.append(i)
|
| 157 |
+
|
| 158 |
+
col3.extend([''] * (len(u_) - len(col3)))
|
| 159 |
+
of['Count '] = col3
|
| 160 |
+
|
| 161 |
+
of[' '] = ''
|
| 162 |
+
|
| 163 |
+
# forming the required output columns accordingly from this tut's output
|
| 164 |
+
for i in octs:
|
| 165 |
+
col4.append(i)
|
| 166 |
+
col5.append(lenc[i])
|
| 167 |
+
col6.append(maxc[i])
|
| 168 |
+
|
| 169 |
+
col4.append('Time')
|
| 170 |
+
col5.append('From')
|
| 171 |
+
col6.append('To')
|
| 172 |
+
|
| 173 |
+
for j in maxl[i]:
|
| 174 |
+
col5.append(j[0])
|
| 175 |
+
col6.append(j[1])
|
| 176 |
+
|
| 177 |
+
col4.extend([''] * (len(col6) - len(col4)))
|
| 178 |
+
|
| 179 |
+
cnt = len(col6)
|
| 180 |
+
col4.extend([''] * (len(u_) - len(col4)))
|
| 181 |
+
col5.extend([''] * (len(u_) - len(col5)))
|
| 182 |
+
col6.extend([''] * (len(u_) - len(col6)))
|
| 183 |
+
|
| 184 |
+
of['Octant ###'] = col4
|
| 185 |
+
of[' Longest Subsequence Length'] = col5
|
| 186 |
+
of['Count '] = col6
|
| 187 |
+
return cnt
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def tut2(of, mod=5000):
|
| 191 |
+
u = of['U'] # assigning list to columns of input file
|
| 192 |
+
v = of['V']
|
| 193 |
+
w = of['W']
|
| 194 |
+
|
| 195 |
+
# calculating the avg value sum() returns summation and len() return length
|
| 196 |
+
avgu = [sum(u) / len(u)]
|
| 197 |
+
avgv = [sum(v) / len(v)]
|
| 198 |
+
avgw = [sum(w) / len(w)]
|
| 199 |
+
|
| 200 |
+
au = sum(u) / len(u)
|
| 201 |
+
av = sum(v) / len(v)
|
| 202 |
+
aw = sum(w) / len(w)
|
| 203 |
+
|
| 204 |
+
u_ = []
|
| 205 |
+
v_ = []
|
| 206 |
+
w_ = []
|
| 207 |
+
|
| 208 |
+
for i in u:
|
| 209 |
+
u_.append(i - au) # pushing the element at back of list
|
| 210 |
+
for i in v:
|
| 211 |
+
v_.append(i - av)
|
| 212 |
+
for i in w:
|
| 213 |
+
w_.append(i - aw)
|
| 214 |
+
|
| 215 |
+
# filling the remaining spaces in the column with blank space
|
| 216 |
+
avgu.extend([''] * (len(u) - 1))
|
| 217 |
+
avgv.extend([''] * (len(u) - 1))
|
| 218 |
+
avgw.extend([''] * (len(u) - 1))
|
| 219 |
+
|
| 220 |
+
col = ['', 'User Input']
|
| 221 |
+
col.extend([''] * (len(u_) - 2))
|
| 222 |
+
|
| 223 |
+
ranges = (len(u_) + mod - 1) // mod
|
| 224 |
+
|
| 225 |
+
oc_id = ['Overall Count', 'Mod ' + str(mod)]
|
| 226 |
+
# loop for creating the mod range's column
|
| 227 |
+
for i in range(ranges):
|
| 228 |
+
if i == ranges - 1:
|
| 229 |
+
oc_id.append(str(i * mod) + '-' +
|
| 230 |
+
str(min((i + 1) * mod - 1, len(u) - 1)))
|
| 231 |
+
else:
|
| 232 |
+
oc_id.append(str(i * mod) + '-' + str((i + 1) * mod - 1))
|
| 233 |
+
|
| 234 |
+
octs = [1, -1, 2, -2, 3, -3, 4, -4]
|
| 235 |
+
values = {}
|
| 236 |
+
xx = {}
|
| 237 |
+
|
| 238 |
+
ran = 2 + int(len(u_) / mod) + bool(len(u_) // mod) + 14 * \
|
| 239 |
+
(1 + int(len(u_) / mod) + bool(len(u_) // mod))
|
| 240 |
+
|
| 241 |
+
num = 2 + int(len(u_) / mod) + bool(len(u_) // mod)
|
| 242 |
+
|
| 243 |
+
# initializing the dictionary with value equal to 0 and blank spaces as per requirements
|
| 244 |
+
for i in octs:
|
| 245 |
+
values[i] = [0] * (ran)
|
| 246 |
+
values[i][1] = ''
|
| 247 |
+
|
| 248 |
+
for k in range(num - 1):
|
| 249 |
+
for j in range(5):
|
| 250 |
+
values[i][j + 14 * k + num] = ''
|
| 251 |
+
|
| 252 |
+
values[i][num + 5] = i
|
| 253 |
+
xx[i] = 0
|
| 254 |
+
|
| 255 |
+
octants = []
|
| 256 |
+
|
| 257 |
+
# dictionary to store position of octant in columns
|
| 258 |
+
inds = {}
|
| 259 |
+
inds[1] = num + 6
|
| 260 |
+
col[inds[1]] = "From"
|
| 261 |
+
|
| 262 |
+
for i in range(len(octs)):
|
| 263 |
+
if i > 0:
|
| 264 |
+
inds[octs[i]] = inds[octs[i - 1]] + 1
|
| 265 |
+
|
| 266 |
+
# loop to determine the octant and to store the counts of octants
|
| 267 |
+
# and to store the total transition count
|
| 268 |
+
p = 1
|
| 269 |
+
for i in range(len(u_)):
|
| 270 |
+
oc = 1
|
| 271 |
+
if (u_[i] > 0) and (v_[i] > 0) and (w_[i] > 0):
|
| 272 |
+
oc = 1
|
| 273 |
+
elif (u_[i]) < 0 and (v_[i]) > 0 and (w_[i]) > 0:
|
| 274 |
+
oc = 2
|
| 275 |
+
elif (u_[i]) < 0 and (v_[i]) < 0 and (w_[i]) > 0:
|
| 276 |
+
oc = 3
|
| 277 |
+
elif (u_[i]) > 0 and (v_[i]) < 0 and (w_[i]) > 0:
|
| 278 |
+
oc = 4
|
| 279 |
+
elif (u_[i]) > 0 and (v_[i]) > 0 and (w_[i]) < 0:
|
| 280 |
+
oc = -1
|
| 281 |
+
elif (u_[i]) < 0 and (v_[i]) > 0 and (w_[i]) < 0:
|
| 282 |
+
oc = -2
|
| 283 |
+
elif (u_[i]) < 0 and (v_[i]) < 0 and (w_[i]) < 0:
|
| 284 |
+
oc = -3
|
| 285 |
+
elif (u_[i]) > 0 and (v_[i]) < 0 and (w_[i]) < 0:
|
| 286 |
+
oc = -4
|
| 287 |
+
|
| 288 |
+
octants.append(oc)
|
| 289 |
+
values[oc][0] += 1
|
| 290 |
+
values[oc][2 + i // mod] += 1
|
| 291 |
+
|
| 292 |
+
if i > 0:
|
| 293 |
+
values[oc][inds[p]] += 1
|
| 294 |
+
|
| 295 |
+
p = oc
|
| 296 |
+
|
| 297 |
+
# formation and adjustment of octant id column
|
| 298 |
+
for i in range(3):
|
| 299 |
+
oc_id.append('')
|
| 300 |
+
|
| 301 |
+
oc_id.append('Overall Transition Count')
|
| 302 |
+
oc_id.append('')
|
| 303 |
+
oc_id.append('Count')
|
| 304 |
+
values[1][num + 4] = "To"
|
| 305 |
+
|
| 306 |
+
for i in range(len(octs)):
|
| 307 |
+
oc_id.append(octs[i])
|
| 308 |
+
|
| 309 |
+
p = octants[0]
|
| 310 |
+
# loop for individual mod range's transition count and table formation
|
| 311 |
+
for i in range(num - 2):
|
| 312 |
+
|
| 313 |
+
for j in range(3):
|
| 314 |
+
oc_id.append('')
|
| 315 |
+
|
| 316 |
+
oc_id.append('Mod Transition Count')
|
| 317 |
+
|
| 318 |
+
if i == num - 3:
|
| 319 |
+
oc_id.append(str(i * mod) + '-' +
|
| 320 |
+
str(min((i + 1) * mod - 1, len(u) - 1)))
|
| 321 |
+
else:
|
| 322 |
+
oc_id.append(str(i * mod) + '-' + str((i + 1) * mod - 1))
|
| 323 |
+
|
| 324 |
+
values[1][inds[1] + 14 - 2] = "To"
|
| 325 |
+
col[inds[1] + 14] = "From"
|
| 326 |
+
oc_id.append("Octant #")
|
| 327 |
+
|
| 328 |
+
for j in octs:
|
| 329 |
+
oc_id.append(j)
|
| 330 |
+
|
| 331 |
+
for j in octs:
|
| 332 |
+
values[j][inds[1] + 14 - 1] = j
|
| 333 |
+
|
| 334 |
+
for j in range(mod * (i) + 1, min(mod * (i + 1), len(u_) - 1) + 1):
|
| 335 |
+
oc = octants[j]
|
| 336 |
+
|
| 337 |
+
if j > 0:
|
| 338 |
+
values[oc][inds[p] + 14] += 1
|
| 339 |
+
p = oc
|
| 340 |
+
|
| 341 |
+
for j in octs:
|
| 342 |
+
inds[j] += 14
|
| 343 |
+
|
| 344 |
+
oc_id.extend([''] * (len(u_) - len(oc_id)))
|
| 345 |
+
|
| 346 |
+
# forming the columns required from this tut's output
|
| 347 |
+
for i in octs:
|
| 348 |
+
values[i].extend([''] * (len(u_) - len(values[i])))
|
| 349 |
+
|
| 350 |
+
req1 = []
|
| 351 |
+
req2 = []
|
| 352 |
+
req3 = {}
|
| 353 |
+
for i in octs:
|
| 354 |
+
req3[i] = []
|
| 355 |
+
|
| 356 |
+
for i in range(len(oc_id)):
|
| 357 |
+
if i >= num + 4:
|
| 358 |
+
req1.append(col[i])
|
| 359 |
+
req2.append(oc_id[i])
|
| 360 |
+
for j in octs:
|
| 361 |
+
req3[j].append(values[j][i])
|
| 362 |
+
|
| 363 |
+
blank = [''] * (len(u_))
|
| 364 |
+
of['ok1'] = blank
|
| 365 |
+
|
| 366 |
+
req1.extend([''] * (len(u_) - len(req1)))
|
| 367 |
+
req2.extend([''] * (len(u_) - len(req2)))
|
| 368 |
+
of['ok2' + col[num + 3]] = req1
|
| 369 |
+
of[oc_id[num + 3]] = req2
|
| 370 |
+
|
| 371 |
+
i = 3
|
| 372 |
+
for j in octs:
|
| 373 |
+
req3[j].extend([''] * (len(u_) - len(req3[j])))
|
| 374 |
+
of['ok' + str(i) + values[j][num + 3]] = req3[j]
|
| 375 |
+
i = i + 1
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
cols = {}
|
| 379 |
+
cols[1] = 23
|
| 380 |
+
cols[-1] = 24
|
| 381 |
+
cols[2] = 25
|
| 382 |
+
cols[-2] = 26
|
| 383 |
+
cols[3] = 27
|
| 384 |
+
cols[-3] = 28
|
| 385 |
+
cols[4] = 29
|
| 386 |
+
cols[-4] = 30
|
| 387 |
+
|
| 388 |
+
|
| 389 |
+
def tut5(of, f, poss, mod=5000):
|
| 390 |
+
# try:
|
| 391 |
+
octant_name_id_mapping = {"1": "Internal outward interaction", "-1": "External outward interaction",
|
| 392 |
+
"2": "External Ejection", "-2": "Internal Ejection",
|
| 393 |
+
"3": "External inward interaction", "-3": "Internal inward interaction",
|
| 394 |
+
"4": "Internal sweep", "-4": "External sweep"}
|
| 395 |
+
|
| 396 |
+
u = of['U'] # assigning a list to columns of input file
|
| 397 |
+
v = of['V']
|
| 398 |
+
w = of['W']
|
| 399 |
+
|
| 400 |
+
# calculating the avg value sum() returns summation and len() returns length
|
| 401 |
+
avgu = [round(sum(u) / len(u), 3)]
|
| 402 |
+
avgv = [round(sum(v) / len(v), 3)]
|
| 403 |
+
avgw = [round(sum(w) / len(w), 3)]
|
| 404 |
+
|
| 405 |
+
au = round(sum(u) / len(u), 3)
|
| 406 |
+
av = round(sum(v) / len(v), 3)
|
| 407 |
+
aw = round(sum(w) / len(w), 3)
|
| 408 |
+
|
| 409 |
+
u_ = []
|
| 410 |
+
v_ = []
|
| 411 |
+
w_ = []
|
| 412 |
+
|
| 413 |
+
for i in u:
|
| 414 |
+
u_.append(round(i - au, 3)) # pushing the element at the end of list using append
|
| 415 |
+
for i in v:
|
| 416 |
+
v_.append(round(i - av, 3))
|
| 417 |
+
for i in w:
|
| 418 |
+
w_.append(round(i - aw, 3))
|
| 419 |
+
|
| 420 |
+
# filling the remaining spaces in the column with blank space using extend
|
| 421 |
+
avgu.extend([''] * (len(u) - 1))
|
| 422 |
+
avgv.extend([''] * (len(u) - 1))
|
| 423 |
+
avgw.extend([''] * (len(u) - 1))
|
| 424 |
+
|
| 425 |
+
try:
|
| 426 |
+
of["U Avg"] = avgu # creating a column in output file
|
| 427 |
+
of["V Avg"] = avgv
|
| 428 |
+
of["W Avg"] = avgw
|
| 429 |
+
|
| 430 |
+
of["U'=U-U avg"] = u_
|
| 431 |
+
of["V'=V-V avg"] = v_
|
| 432 |
+
of["W'=W-W avg"] = w_
|
| 433 |
+
except:
|
| 434 |
+
print('Error encountered : Mismatch in length of columns')
|
| 435 |
+
|
| 436 |
+
emp = [''] * (len(u_))
|
| 437 |
+
col = ['', 'Mod ' + str(mod)]
|
| 438 |
+
col.extend([''] * (len(u_) - 2))
|
| 439 |
+
|
| 440 |
+
ranges = (len(u_) + mod - 1) // mod
|
| 441 |
+
|
| 442 |
+
oc_id = ['Overall Count']
|
| 443 |
+
|
| 444 |
+
# loop for creating the mod range's column
|
| 445 |
+
for i in range(ranges):
|
| 446 |
+
if i == ranges - 1:
|
| 447 |
+
oc_id.append(str(i * mod) + '-' +
|
| 448 |
+
str(min((i + 1) * mod - 1, len(u) - 1)))
|
| 449 |
+
else:
|
| 450 |
+
oc_id.append(str(i * mod) + '-' + str((i + 1) * mod - 1))
|
| 451 |
+
|
| 452 |
+
octs = [1, -1, 2, -2, 3, -3, 4, -4]
|
| 453 |
+
values = {} # columns before ranking starts
|
| 454 |
+
ranks = {} # columns containing ranks
|
| 455 |
+
rank = []
|
| 456 |
+
rank.extend([''] * (len(u_)))
|
| 457 |
+
name = []
|
| 458 |
+
name.extend([''] * (len(u_)))
|
| 459 |
+
|
| 460 |
+
ran = 2 + int(len(u_) / mod) + bool(len(u_) // mod) + 14 * \
|
| 461 |
+
(1 + int(len(u_) / mod) + bool(len(u_) // mod))
|
| 462 |
+
|
| 463 |
+
num = 1 + int(len(u_) / mod) + bool(len(u_) // mod)
|
| 464 |
+
|
| 465 |
+
# initializing the dictionary with value equal to 0 and blank spaces as per requirements
|
| 466 |
+
for i in octs:
|
| 467 |
+
values[i] = [''] * (len(u_))
|
| 468 |
+
values[i] = [0] * (num)
|
| 469 |
+
ranks[i] = [''] * (len(u_))
|
| 470 |
+
ranks[i] = [0] * (num)
|
| 471 |
+
|
| 472 |
+
octants = []
|
| 473 |
+
|
| 474 |
+
# loop to determine the octant and to store the counts of octants
|
| 475 |
+
# and to store the total transition count
|
| 476 |
+
|
| 477 |
+
for i in range(len(u_)):
|
| 478 |
+
oc = 1
|
| 479 |
+
if (u_[i] > 0) and (v_[i] > 0) and (w_[i] > 0):
|
| 480 |
+
oc = 1
|
| 481 |
+
elif (u_[i]) < 0 and (v_[i]) > 0 and (w_[i]) > 0:
|
| 482 |
+
oc = 2
|
| 483 |
+
elif (u_[i]) < 0 and (v_[i]) < 0 and (w_[i]) > 0:
|
| 484 |
+
oc = 3
|
| 485 |
+
elif (u_[i]) > 0 and (v_[i]) < 0 and (w_[i]) > 0:
|
| 486 |
+
oc = 4
|
| 487 |
+
elif (u_[i]) > 0 and (v_[i]) > 0 and (w_[i]) < 0:
|
| 488 |
+
oc = -1
|
| 489 |
+
elif (u_[i]) < 0 and (v_[i]) > 0 and (w_[i]) < 0:
|
| 490 |
+
oc = -2
|
| 491 |
+
elif (u_[i]) < 0 and (v_[i]) < 0 and (w_[i]) < 0:
|
| 492 |
+
oc = -3
|
| 493 |
+
elif (u_[i]) > 0 and (v_[i]) < 0 and (w_[i]) < 0:
|
| 494 |
+
oc = -4
|
| 495 |
+
|
| 496 |
+
octants.append(oc)
|
| 497 |
+
values[oc][0] += 1
|
| 498 |
+
values[oc][1 + i // mod] += 1
|
| 499 |
+
|
| 500 |
+
# formation and adjustment of octant id column
|
| 501 |
+
for i in range(3):
|
| 502 |
+
oc_id.append('')
|
| 503 |
+
|
| 504 |
+
try:
|
| 505 |
+
of['Octant'] = octants
|
| 506 |
+
of[' '] = emp
|
| 507 |
+
of[''] = col # forming a column in output file
|
| 508 |
+
except:
|
| 509 |
+
print('Error encountered : Mismatch in length of columns')
|
| 510 |
+
|
| 511 |
+
oc_id.extend([''] * (len(u_) - len(oc_id)))
|
| 512 |
+
of['Octant ID'] = oc_id
|
| 513 |
+
|
| 514 |
+
cnt = {}
|
| 515 |
+
for i in octs:
|
| 516 |
+
cnt[i] = 0
|
| 517 |
+
|
| 518 |
+
#loop to calculate rank of each octant for each mod range and assignment of the values
|
| 519 |
+
for i in range(num):
|
| 520 |
+
seq = []
|
| 521 |
+
for j in octs:
|
| 522 |
+
seq.append([values[j][i], j])
|
| 523 |
+
seq.sort()
|
| 524 |
+
|
| 525 |
+
for j in range(len(seq)):
|
| 526 |
+
ranks[seq[j][1]][i] = 8 - j
|
| 527 |
+
|
| 528 |
+
rank[i] = seq[len(seq) - 1][1]
|
| 529 |
+
poss.append([rank[i], i])
|
| 530 |
+
name[i] = octant_name_id_mapping[str(rank[i])]
|
| 531 |
+
|
| 532 |
+
if i != 0:
|
| 533 |
+
cnt[rank[i]] = cnt[rank[i]] + 1
|
| 534 |
+
|
| 535 |
+
for i in range(1):
|
| 536 |
+
ranks[4].append('')
|
| 537 |
+
ranks[-4].append('')
|
| 538 |
+
|
| 539 |
+
ranks[4].append('Octant ID')
|
| 540 |
+
ranks[-4].append('Octant Name')
|
| 541 |
+
rank[num + 1] = 'Count of Rank 1 Mod values'
|
| 542 |
+
|
| 543 |
+
# representation of name of each octant and count of rank 1 value
|
| 544 |
+
j = num + 2
|
| 545 |
+
for i in octs:
|
| 546 |
+
ranks[4].append(str(i))
|
| 547 |
+
ranks[-4].append(octant_name_id_mapping[str(i)])
|
| 548 |
+
rank[j] = cnt[i]
|
| 549 |
+
j = j + 1
|
| 550 |
+
|
| 551 |
+
#count of each octant in each mod range
|
| 552 |
+
for i in octs:
|
| 553 |
+
values[i].extend([''] * (len(u_) - len(values[i])))
|
| 554 |
+
of[str(i)] = values[i]
|
| 555 |
+
|
| 556 |
+
#rank columns of each octant
|
| 557 |
+
for i in octs:
|
| 558 |
+
ranks[i].extend([''] * (len(u_) - len(ranks[i])))
|
| 559 |
+
of['Rank Octant ' + str(i)] = ranks[i]
|
| 560 |
+
|
| 561 |
+
#forming the output columns
|
| 562 |
+
of['Rank1 Octant ID'] = rank
|
| 563 |
+
of['Rank1 Octant Name'] = name
|
| 564 |
+
|
| 565 |
+
|
| 566 |
+
|
| 567 |
+
opdir = 'output'
|
| 568 |
+
def tut7(f):
|
| 569 |
+
# forming the output directory if not present
|
| 570 |
+
if not os.path.exists(opdir):
|
| 571 |
+
os.makedirs(opdir)
|
| 572 |
+
|
| 573 |
+
# for f in files:
|
| 574 |
+
# if ('input/' + f)[-4:] == 'xlsx':
|
| 575 |
+
# reading the input file
|
| 576 |
+
df = pd.read_excel(f)
|
| 577 |
+
of = df
|
| 578 |
+
|
| 579 |
+
u = of['U']
|
| 580 |
+
num = 2 + int(len(u) / mod) + bool(len(u) // mod)
|
| 581 |
+
|
| 582 |
+
# calling the required functions
|
| 583 |
+
poss = []
|
| 584 |
+
tut5(of, f, poss, mod)
|
| 585 |
+
tut2(of, mod)
|
| 586 |
+
cnt = int(tut4(of))
|
| 587 |
+
|
| 588 |
+
heads = []
|
| 589 |
+
c = 33
|
| 590 |
+
while c <= 43:
|
| 591 |
+
if c != 35:
|
| 592 |
+
heads.append(c)
|
| 593 |
+
c = c+1
|
| 594 |
+
|
| 595 |
+
# forming a dataframe in openpyxl from pandas dataframes
|
| 596 |
+
wb = Workbook()
|
| 597 |
+
sheet = wb.active
|
| 598 |
+
for r in dataframe_to_rows(df, index=False, header=True):
|
| 599 |
+
sheet.append(r)
|
| 600 |
+
|
| 601 |
+
yellow = "00FFFF00"
|
| 602 |
+
|
| 603 |
+
# coloring and bordering the required cells using openpxyl's
|
| 604 |
+
# patternfill and border function
|
| 605 |
+
for i in range(len(poss)):
|
| 606 |
+
c = cols[poss[i][0]]
|
| 607 |
+
r = int(poss[i][1]+2)
|
| 608 |
+
sheet.cell(row=r, column=c).fill = PatternFill(
|
| 609 |
+
patternType="solid", fgColor=yellow)
|
| 610 |
+
|
| 611 |
+
for i in range(len(heads)):
|
| 612 |
+
sheet.cell(row=1, column=heads[i]).value = ' '
|
| 613 |
+
|
| 614 |
+
c = 14
|
| 615 |
+
borcol = []
|
| 616 |
+
while c <= 32:
|
| 617 |
+
borcol.append(c)
|
| 618 |
+
c = c+1
|
| 619 |
+
|
| 620 |
+
black = '000000'
|
| 621 |
+
thin_border = Border(left=Side(style='thin', color=black),
|
| 622 |
+
right=Side(style='thin', color=black),
|
| 623 |
+
top=Side(style='thin', color=black),
|
| 624 |
+
bottom=Side(style='thin', color=black))
|
| 625 |
+
for i in range(len(borcol)):
|
| 626 |
+
for j in range(num):
|
| 627 |
+
sheet.cell(row=j+1, column=borcol[i]).border = thin_border
|
| 628 |
+
|
| 629 |
+
for i in range(9):
|
| 630 |
+
sheet.cell(row=num + 2 + i, column=29).border = thin_border
|
| 631 |
+
sheet.cell(row=num + i + 2, column=30).border = thin_border
|
| 632 |
+
sheet.cell(row=num + i + 2, column=31).border = thin_border
|
| 633 |
+
|
| 634 |
+
borcol = []
|
| 635 |
+
c = 35
|
| 636 |
+
while c <= 43:
|
| 637 |
+
borcol.append(c)
|
| 638 |
+
c = c+1
|
| 639 |
+
|
| 640 |
+
ran = int(len(u)/mod)+bool(len(u) % mod)+1
|
| 641 |
+
row = 0
|
| 642 |
+
for k in range(ran):
|
| 643 |
+
row = row+2
|
| 644 |
+
for i in range(len(borcol)):
|
| 645 |
+
for j in range(9):
|
| 646 |
+
sheet.cell(
|
| 647 |
+
row=row+1+j, column=borcol[i]).border = thin_border
|
| 648 |
+
row = row+12
|
| 649 |
+
|
| 650 |
+
c = 44
|
| 651 |
+
while c <= 46:
|
| 652 |
+
c = c+1
|
| 653 |
+
for i in range(9):
|
| 654 |
+
sheet.cell(row=i + 1, column=c).border = thin_border
|
| 655 |
+
|
| 656 |
+
for i in range(cnt+1):
|
| 657 |
+
sheet.cell(row=1 + i, column=49).border = thin_border
|
| 658 |
+
sheet.cell(row=i+1, column=50).border = thin_border
|
| 659 |
+
sheet.cell(row=i+1, column=51).border = thin_border
|
| 660 |
+
|
| 661 |
+
# forming the required output file by saving openpyxl dataframe
|
| 662 |
+
wb.save(os.path.join(
|
| 663 |
+
opdir, f.name[0:-4] + '_octant_analysis_mod_' + str(mod) + '.xlsx'))
|
| 664 |
+
|
| 665 |
+
st.title('Get output file of CS384-2022 tut-7 for free')
|
| 666 |
+
f=[]
|
| 667 |
+
|
| 668 |
+
f = st.sidebar.file_uploader('Upload your input file in xlsx format', accept_multiple_files=True
|
| 669 |
+
)
|
| 670 |
+
# f = st.file_uploader('Upload your input file in xlsx format', accept_multiple_files=True)
|
| 671 |
+
from zipfile import ZipFile
|
| 672 |
+
|
| 673 |
+
mod=0
|
| 674 |
+
if f is not None:
|
| 675 |
+
mod=int(st.number_input('Please enter mod value'))
|
| 676 |
+
if mod!=0:
|
| 677 |
+
|
| 678 |
+
if st.button('Compute'):
|
| 679 |
+
cnt=100/len(f)
|
| 680 |
+
num=0
|
| 681 |
+
bar=st.progress(num)
|
| 682 |
+
for files in f:
|
| 683 |
+
num+=cnt
|
| 684 |
+
bar.progress(int(num))
|
| 685 |
+
# print(files.name)
|
| 686 |
+
tut7(files)
|
| 687 |
+
|
| 688 |
+
else:
|
| 689 |
+
st.warning('Mod cannot be zero', icon='🥱')
|
| 690 |
+
|
| 691 |
+
st.title('')
|
| 692 |
+
st.write('Output files ready for download👇')
|
| 693 |
+
opdir="output"
|
| 694 |
+
for files in os.listdir(opdir):
|
| 695 |
+
# print(files)
|
| 696 |
+
st.download_button("Download "+(files), os.path.join(opdir,files), file_name=files)
|
| 697 |
+
|
| 698 |
+
st.title('')
|
| 699 |
+
st.write("Thank us later✌")
|
| 700 |
+
|
| 701 |
+
# with ZipFile('my_python_files.zip','w') as zip:
|
| 702 |
+
# # writing each file one by one
|
| 703 |
+
# opdir="output"
|
| 704 |
+
# for file in opdir:
|
| 705 |
+
# zip.write(file)
|
| 706 |
+
|
| 707 |
+
# print('All files zipped successfully!')
|
requirements.txt.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pandas
|