-
Notifications
You must be signed in to change notification settings - Fork 0
/
webappFilter.py
86 lines (75 loc) · 2.84 KB
/
webappFilter.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
import pandas as pd
from scipy.stats import percentileofscore
import numpy as np
import re
def filterResults(requestVariable, allData, column):
filter_ = allData[column]==requestVariable
return allData[filter_]
def Filter(result, allData, stateStatus, gradeLevel, genderStatus):
#print(result)
dataCopy = filterResults(result["event"], allData, "event")
#print(dataCopy)
#print(package)
if stateStatus == 'True':
print('filtering state')
dataCopy = filterResults(result["state"], dataCopy, "state")
else:
print('not filtering location')
if gradeLevel == "True":
#print('filtering ' + package["grade"])
dataCopy = filterResults(result["gradeLevel"], dataCopy, "gradeLevel")
if genderStatus == 'True':
#print('filtering ' + package["gender"])
dataCopy = filterResults(result["gender"], dataCopy, "gender")
return dataCopy
def percentileConverter(result):
result = postCleaner(str(result))
try:
if ':' in result:
splitResult = re.split(":", result)
if len(splitResult) == 1:
return float(splitResult)
if len(splitResult) == 2:
return float(splitResult[0]) * 60 + float(splitResult[1])
if len(splitResult) == 3:
return float(splitResult[0]) * 60 + float(splitResult[1]) * 60 + float(splitResult[2])
if "'" in result:
splitDistance = re.split("'", result)
if len(splitDistance) == 1:
return float(splitDistance)
if len(splitDistance) == 2:
return float(splitDistance[0]) * 12 + float(splitDistance[1])
else:
return float(result)
except:
return(0)
def postCleaner(result):
result = result.replace("PR", "").replace("SR", "").replace("h", "0").replace("c", "").replace("m", "").replace("SCR", "")
if "(" in result and ")" not in result:
return result[:-5]
#print(result)
return result
def percentile(filteredData, singleRequest):
#print(filteredData)
noError = filteredData[filteredData.formattedResults != "Error"]
#filteredData['']
resultList = noError['splitTime'].values.tolist()
#print(resultList)
floatResults = []
#print(singleRequest)
for results in resultList:
try:
#limFloat = "{0:.2f}".format(results)
floatResult = float(results)
floatResults.append(floatResult)
except:
#print('blah', end=' ')
pass
dataSize = len(floatResults)
formattedRaw = postCleaner(singleRequest['result'])
#print(formattedRaw)
formattedResult = percentileConverter(formattedRaw)
#print(type(formattedResult))
percentile = 100 - percentileofscore(floatResults, float(formattedResult))
#rint(percentile)
return [percentile, dataSize]